Skip to content

Commit

Permalink
Merge pull request #110 from ymaheshwari1/#106
Browse files Browse the repository at this point in the history
Implemented: support to persist the selected routingRule on page refresh and after saving changes(#106)
  • Loading branch information
ymaheshwari1 authored Feb 16, 2024
2 parents 9cbf983 + 894b2b1 commit ae7efa7
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 8 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;
}
6 changes: 5 additions & 1 deletion 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 Expand Up @@ -370,7 +374,7 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
}

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) {

Check warning on line 380 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / build_and_deploy

'dispatch' is defined but never used

Check warning on line 380 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'dispatch' is defined but never used

Check warning on line 380 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'dispatch' is defined but never used
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
20 changes: 15 additions & 5 deletions src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
<div class="menu">
<ion-list>
<ion-reorder-group @ionItemReorder="doReorder($event)" :disabled="false">
<ion-item lines="full" v-for="rule in inventoryRules" :key="rule.routingRuleId && inventoryRules.length" :color="rule.routingRuleId === selectedRoutingRule.routingRuleId ? 'light' : ''" @click="fetchRuleInformation(rule.routingRuleId)" button>
<ion-item lines="full" v-for="rule in inventoryRules" :key="rule.routingRuleId && inventoryRules.length" :color="rule.routingRuleId === selectedRoutingRule?.routingRuleId ? 'light' : ''" @click="fetchRuleInformation(rule.routingRuleId)" button>
<ion-label>{{ rule.ruleName }}</ion-label>
<!-- Don't display reordering option when there is a single rule -->
<ion-reorder v-show="inventoryRules.length > 1" />
Expand All @@ -97,7 +97,7 @@
<ion-icon :icon="addCircleOutline"/>
</ion-button>
</div>
<div v-if="selectedRoutingRule.routingRuleId">
<div v-if="selectedRoutingRule?.routingRuleId">
<ion-card class="rule-info">
<ion-item lines="none">
<ion-label>
Expand Down 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 All @@ -420,7 +425,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 = "") {
Expand Down Expand Up @@ -1065,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 ae7efa7

Please sign in to comment.