Skip to content

Commit

Permalink
Implemented: support to persist the routingRuleId on route details page(
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Feb 16, 2024
1 parent 23f9222 commit 894b2b1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
1 change: 1 addition & 0 deletions src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export default interface OrderRoutingState {
currentGroup: any;
currentRoute: any;
routingHistory: any;
currentRuleId: string;
}
4 changes: 4 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
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)) : []
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const getters: GetterTree<OrderRoutingState, RootState> = {
},
getRoutingHistory(state) {
return JSON.parse(JSON.stringify(state.routingHistory))
},
getCurrentRuleId(state) {
return state.currentRuleId
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/orderRouting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const orderRoutingModule: Module<OrderRoutingState, RootState> = {
rules: {},
currentGroup: {},
currentRoute: {},
routingHistory: {}
routingHistory: {},
currentRuleId: ""
},
getters,
actions,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/orderRouting/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ const mutations: MutationTree<OrderRoutingState> = {
[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 = {}
Expand Down
9 changes: 7 additions & 2 deletions src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 894b2b1

Please sign in to comment.