From 55ff3d30d1eeccabbe85310fef93dba0f7cbe08d Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sat, 20 Jan 2024 16:09:01 +0530 Subject: [PATCH 1/2] Fixed: case that on routing page refresh the routing information is not available --- src/services/RoutingService.ts | 9 +++++- .../modules/orderRouting/OrderRoutingState.ts | 4 +-- src/store/modules/orderRouting/actions.ts | 28 ++++++++++++++++++- src/store/modules/orderRouting/getters.ts | 3 +- src/store/modules/orderRouting/index.ts | 3 +- src/store/modules/orderRouting/mutations.ts | 4 +-- src/views/BrokeringRoute.vue | 9 ++---- src/views/BrokeringRuns.vue | 9 +++--- 8 files changed, 49 insertions(+), 20 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index e0ec91a..2a6304c 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -1,6 +1,5 @@ import api from "@/api" import logger from "@/logger"; -import store from "@/store"; import { hasError, showToast } from "@/utils"; const fetchRoutingGroups = async (payload: any): Promise => { @@ -11,6 +10,13 @@ const fetchRoutingGroups = async (payload: any): Promise => { }); } +const fetchRoutingGroup = async (routingGroupId: string): Promise => { + return api({ + url: `groups/${routingGroupId}`, + method: "GET" + }); +} + const createRoutingGroup = async (payload: any): Promise => { return api({ url: "groups", @@ -109,6 +115,7 @@ export const OrderRoutingService = { createRoutingRule, fetchOrderRoutings, fetchRoutingFilters, + fetchRoutingGroup, fetchRoutingGroups, fetchRoutingRules, fetchRuleActions, diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 9c6d1b2..479e5d3 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -1,10 +1,10 @@ -import { RouteFilter } from "@/types"; +import { Group, RouteFilter } from "@/types"; export default interface OrderRoutingState { groups: Array; // runs routes: Array; rules: Array; - currentGroupId: string; + currentGroup: any; currentRouteId: string; currentRouteFilters: { [key: string]: { // conditionTypeEnumId as key diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 50f2dc5..9b0e929 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -77,7 +77,33 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) }, - async setCurrentRoutingGroupId({ commit }, payload) { + async fetchCurrentRoutingGroup({ dispatch, state }, routingGroupId) { + const current = state.currentGroup + if(current.routingGroupId) { + dispatch("setCurrentRoutingGroup", current) + return; + } + + let currentGroup = {} + + try { + const resp = await OrderRoutingService.fetchRoutingGroup(routingGroupId); + + console.log(resp.data) + + if(!hasError(resp) && resp.data) { + currentGroup = resp.data + } else { + throw resp.data + } + } catch(err) { + logger.error(err); + } + + dispatch("setCurrentRoutingGroup", currentGroup) + }, + + async setCurrentRoutingGroup({ commit }, payload) { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, payload) }, diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index d52948a..8313298 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -14,8 +14,7 @@ const getters: GetterTree = { return state.rules }, getCurrentRoutingGroup(state) { - const currentRoutingGroup = state.groups?.find((group: Group) => group.routingGroupId === state.currentGroupId) - return currentRoutingGroup ? currentRoutingGroup : {} + return JSON.parse(JSON.stringify(state.currentGroup)) }, getCurrentOrderRouting(state) { const orderRouting = state.routes?.find((route: Route) => route.orderRoutingId === state.currentRouteId) diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index b554efd..958e425 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -4,6 +4,7 @@ import mutations from "./mutations" import { Module } from "vuex" import OrderRoutingState from "./OrderRoutingState" import RootState from "@/store/RootState" +import { Route } from "@/types" const orderRoutingModule: Module = { namespaced: true, @@ -11,7 +12,7 @@ const orderRoutingModule: Module = { groups: [], routes: [], rules: [], - currentGroupId: '', // choosing only to save id and not whole object, as when updating the state we don't need to care updating the state on two different places + currentGroup: {}, currentRouteId: '', currentRouteFilters: {}, ruleConditions: {}, diff --git a/src/store/modules/orderRouting/mutations.ts b/src/store/modules/orderRouting/mutations.ts index 6ce1f3d..763491d 100644 --- a/src/store/modules/orderRouting/mutations.ts +++ b/src/store/modules/orderRouting/mutations.ts @@ -12,8 +12,8 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_RULES_UPDATED](state, payload) { state.rules = payload }, - [types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, groupId) { - state.currentGroupId = groupId + [types.ORDER_ROUTING_CURRENT_GROUP_UPDATED](state, payload) { + state.currentGroup = payload }, [types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, routeId) { state.currentRouteId = routeId diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 8727dfd..ba03dfd 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -105,7 +105,7 @@ import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonCardHeader, import { addCircleOutline, archiveOutline, reorderTwoOutline, saveOutline, timeOutline, timerOutline } from "ionicons/icons" import { useRouter } from "vue-router"; import { useStore } from "vuex"; -import { computed, defineProps, ref } from "vue"; +import { computed, defineProps, onMounted, ref } from "vue"; import { Group, Route } from "@/types"; import ArchivedRoutingModal from "@/components/ArchivedRoutingModal.vue" import emitter from "@/event-bus"; @@ -130,15 +130,10 @@ const currentRoutingGroup = computed((): Group => store.getters["orderRouting/ge const orderRoutings = computed(() => store.getters["orderRouting/getOrderRoutings"]) onIonViewWillEnter(async () => { - await store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId) + await Promise.all([store.dispatch("orderRouting/fetchOrderRoutings", props.routingGroupId), store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId)]) initializeOrderRoutings(); - // On refresh, the groups list is removed thus resulting is not fetching the current group information - if(!currentRoutingGroup.value.routingGroupId) { - await store.dispatch("orderRouting/fetchOrderRoutingGroups") - } - description.value = currentRoutingGroup.value.description ? currentRoutingGroup.value.description : "No description available" emitter.on("initializeOrderRoutings", initializeOrderRoutings) }) diff --git a/src/views/BrokeringRuns.vue b/src/views/BrokeringRuns.vue index 7da7c33..01bd683 100644 --- a/src/views/BrokeringRuns.vue +++ b/src/views/BrokeringRuns.vue @@ -16,7 +16,7 @@
- + {{ group.groupName }} @@ -46,6 +46,7 @@ From b7bd5e7dcad74741e8a7f66f71135d4f38ec48f4 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sat, 20 Jan 2024 16:10:34 +0530 Subject: [PATCH 2/2] Removed: unwanted console statement --- src/store/modules/orderRouting/actions.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 9b0e929..b457aad 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -89,8 +89,6 @@ const actions: ActionTree = { try { const resp = await OrderRoutingService.fetchRoutingGroup(routingGroupId); - console.log(resp.data) - if(!hasError(resp) && resp.data) { currentGroup = resp.data } else {