From 23f92225cbf964f38d8575151b076415e2fa5c6f Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 16 Feb 2024 17:51:01 +0530 Subject: [PATCH 1/2] Improved: conditions to handle some undefined case related to selectedRoutingRule(#106) --- src/store/modules/orderRouting/actions.ts | 2 +- src/views/BrokeringQuery.vue | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index b7e4ea7..4b74307 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -370,7 +370,7 @@ const actions: ActionTree = { } commit(types.ORDER_ROUTING_RULES_UPDATED, rulesInformation) - return JSON.parse(JSON.stringify(rulesInformation[routingRuleId])) + return rulesInformation[routingRuleId] ? JSON.parse(JSON.stringify(rulesInformation[routingRuleId])) : {} }, async updateRule({ dispatch }, payload) { diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 0b80768..e104ab1 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -85,7 +85,7 @@ -
+
@@ -420,7 +420,12 @@ async function fetchRuleInformation(routingRuleId: string) { // Using currentRouting["rules"] deep-cloned object here, as we will update the change in rules with route changes and not with rules filter changes selectedRoutingRule.value = inventoryRules.value.find((rule: Rule) => rule.routingRuleId === routingRuleId) - initializeInventoryRules(JSON.parse(JSON.stringify(rulesInformation.value[routingRuleId]))); + // Even after fetching the rule is not found then initializing the selectedRouting to empty object + if(!selectedRoutingRule.value) { + selectedRoutingRule.value = {} + } + + initializeInventoryRules(rulesInformation.value[routingRuleId] ? JSON.parse(JSON.stringify(rulesInformation.value[routingRuleId])) : {}); } async function addInventoryFilterOptions(parentEnumId: string, conditionTypeEnumId: string, label = "") { From 894b2b17bb9ce7886c31f6e9763f06e29b45b59e Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 16 Feb 2024 18:36:39 +0530 Subject: [PATCH 2/2] Implemented: support to persist the routingRuleId on route details page(#106) --- src/store/index.ts | 2 +- src/store/modules/orderRouting/OrderRoutingState.ts | 1 + src/store/modules/orderRouting/actions.ts | 4 ++++ src/store/modules/orderRouting/getters.ts | 3 +++ src/store/modules/orderRouting/index.ts | 3 ++- src/store/modules/orderRouting/mutation-types.ts | 1 + src/store/modules/orderRouting/mutations.ts | 3 +++ src/views/BrokeringQuery.vue | 9 +++++++-- 8 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/store/index.ts b/src/store/index.ts index e17775f..a563108 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -15,7 +15,7 @@ import orderRoutingModule from "./modules/orderRouting" const state: any = {} const persistState = createPersistedState({ - paths: ["user", "util", "orderRouting.currentGroup"], + paths: ["user", "util", "orderRouting.currentGroup", "orderRouting.currentRuleId"], fetchBeforeUse: true }) diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 16d7934..cd77130 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -4,4 +4,5 @@ export default interface OrderRoutingState { currentGroup: any; currentRoute: any; routingHistory: any; + currentRuleId: string; } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 4b74307..9372d16 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -257,6 +257,10 @@ const actions: ActionTree = { return orderRoutingId }, + async updateRoutingRuleId({ commit }, payload) { + commit(types.ORDER_ROUTING_CURRENT_RULE_UPDATED, payload) + }, + async createRoutingRule({ commit, state }, payload) { const currentRoute = JSON.parse(JSON.stringify(state.currentRoute)) let routingRules = currentRoute.rules?.length ? JSON.parse(JSON.stringify(currentRoute.rules)) : [] diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index 5792302..e7acc47 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -17,6 +17,9 @@ const getters: GetterTree = { }, getRoutingHistory(state) { return JSON.parse(JSON.stringify(state.routingHistory)) + }, + getCurrentRuleId(state) { + return state.currentRuleId } } diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index 4b576a5..92665ec 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -12,7 +12,8 @@ const orderRoutingModule: Module = { rules: {}, currentGroup: {}, currentRoute: {}, - routingHistory: {} + routingHistory: {}, + currentRuleId: "" }, getters, actions, diff --git a/src/store/modules/orderRouting/mutation-types.ts b/src/store/modules/orderRouting/mutation-types.ts index db94981..e2c34e1 100644 --- a/src/store/modules/orderRouting/mutation-types.ts +++ b/src/store/modules/orderRouting/mutation-types.ts @@ -4,4 +4,5 @@ export const ORDER_ROUTING_RULES_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED" export const ORDER_ROUTING_CURRENT_GROUP_UPDATED = SN_ORDER_ROUTING + "/CURRENT_GROUP_UPDATED" export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED" export const ORDER_ROUTING_HISTORY_UPDATED = SN_ORDER_ROUTING + "/ROUTING_HISTORY_UPDATED" +export const ORDER_ROUTING_CURRENT_RULE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_RULE_UPDATED" export const ORDER_ROUTING_CLEARED = SN_ORDER_ROUTING + "/CLEARED" \ No newline at end of file diff --git a/src/store/modules/orderRouting/mutations.ts b/src/store/modules/orderRouting/mutations.ts index 5a0348d..0b66751 100644 --- a/src/store/modules/orderRouting/mutations.ts +++ b/src/store/modules/orderRouting/mutations.ts @@ -18,6 +18,9 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_HISTORY_UPDATED](state, payload) { state.routingHistory = payload }, + [types.ORDER_ROUTING_CURRENT_RULE_UPDATED](state, payload) { + state.currentRuleId = payload + }, [types.ORDER_ROUTING_CLEARED](state) { state.groups = [] state.rules = {} diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index e104ab1..330f4fc 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -281,6 +281,7 @@ const enums = computed(() => store.getters["util/getEnums"]) const shippingMethods = computed(() => store.getters["util/getShippingMethods"]) const facilityGroups = computed(() => store.getters["util/getFacilityGroups"]) const routingHistory = computed(() => store.getters["orderRouting/getRoutingHistory"]) +const currentRuleId = computed(() => store.getters["orderRouting/getCurrentRuleId"]) let ruleActionType = ref("") let selectedRoutingRule = ref({}) as any @@ -312,7 +313,7 @@ onIonViewWillEnter(async () => { // Added check to not fetch any rule related information as when a new route will be created no rule will be available thus no need to fetch any other information if(currentRouting.value["rules"]?.length) { inventoryRules.value = sortSequence(JSON.parse(JSON.stringify(currentRouting.value["rules"]))) - await fetchRuleInformation(inventoryRules.value[0].routingRuleId); + await fetchRuleInformation(currentRuleId.value || inventoryRules.value[0].routingRuleId); } routingStatus.value = currentRouting.value.statusId @@ -347,6 +348,8 @@ onBeforeRouteLeave(async (to) => { await alert.onDidDismiss(); return canLeave; } + // clearning the selected ruleId whenever user tries to leave the page, we need to clear this id, as if user opens some other routing then the id will not be found which will result in an empty state scenario + store.dispatch("orderRouting/updateRoutingRuleId", "") }) function getRouteIndex() { @@ -400,6 +403,8 @@ async function fetchRuleInformation(routingRuleId: string) { // Changing the value to false, as when fetching the information initially or after changing the rule we should stop the process of name updation isRuleNameUpdating.value = false + await store.dispatch("orderRouting/updateRoutingRuleId", routingRuleId) + // When clicking the same enum again do not fetch its information // TODO: check behaviour when creating a new rule, when no rule exist and when already some rule exist and a rule is open if(selectedRoutingRule.value.routingRuleId === routingRuleId) { @@ -1070,7 +1075,7 @@ async function save() { // Added check to not fetch any rule related information as when a new route will be created no rule will be available thus no need to fetch any other information if(currentRouting.value["rules"]?.length) { inventoryRules.value = sortSequence(JSON.parse(JSON.stringify(currentRouting.value["rules"]))) - await fetchRuleInformation(inventoryRules.value[0].routingRuleId); + await fetchRuleInformation(currentRuleId.value); } hasUnsavedChanges.value = false