From 76b239ae24b3e6aa5f5fa5e791b7ec98f2fcdc3b Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sat, 27 Jan 2024 16:46:38 +0530 Subject: [PATCH 1/6] Improved: support to update and remove route filter options(#24) --- src/components/AddOrderRouteFilterOptions.vue | 32 +-- src/store/modules/orderRouting/actions.ts | 10 +- src/views/BrokeringQuery.vue | 243 ++++++++++-------- 3 files changed, 147 insertions(+), 138 deletions(-) diff --git a/src/components/AddOrderRouteFilterOptions.vue b/src/components/AddOrderRouteFilterOptions.vue index 849a195..988315d 100644 --- a/src/components/AddOrderRouteFilterOptions.vue +++ b/src/components/AddOrderRouteFilterOptions.vue @@ -29,6 +29,7 @@ import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, I import { useStore } from "vuex"; import { computed, defineProps, onMounted, ref } from "vue"; import { saveOutline } from "ionicons/icons"; +import { DateTime } from "luxon"; const store = useStore(); const enums = computed(() => store.getters["util/getEnums"]) @@ -64,43 +65,34 @@ function addSortOption(sort: any) { const isSortOptionAlreadyApplied = isSortOptionSelected(sort.enumCode)?.fieldName if(isSortOptionAlreadyApplied) { - delete routingFilters.value[props.conditionTypeEnumId][sort.enumCode] + delete routingFilters.value[sort.enumCode] } else { // checking unchecking an option and then checking it again, we need to use the same values - if(props.orderRoutingFilters[props.conditionTypeEnumId]?.[sort.enumCode]) { - routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = props.orderRoutingFilters[props.conditionTypeEnumId][sort.enumCode] + // TODO: check for a unique case that what if we add a new option, reorder the filters and then remove the old option and then add it again, this case result in duplicate seqNum which should not happen + if(props.orderRoutingFilters?.[sort.enumCode]) { + routingFilters.value[sort.enumCode] = props.orderRoutingFilters[sort.enumCode] } else { // when adding a new value, we don't need to pass conditionSeqId - // Added check that whether the filters for the conditionType exists or not, if not then create a new value for conditionType - routingFilters.value[props.conditionTypeEnumId] ? routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = { + routingFilters.value[sort.enumCode] = { orderRoutingId: props.orderRoutingId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: sort.enumCode, - sequenceNum: Object.keys(routingFilters.value[props.conditionTypeEnumId]).length && routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 - } : routingFilters.value = { - ...routingFilters.value, - [props.conditionTypeEnumId]: { - [sort.enumCode]: { - orderRoutingId: props.orderRoutingId, - conditionTypeEnumId: props.conditionTypeEnumId, - fieldName: sort.enumCode, - sequenceNum: 0 - } - } + sequenceNum: Object.keys(routingFilters.value).length && routingFilters.value[Object.keys(routingFilters.value)[Object.keys(routingFilters.value).length - 1]]?.sequenceNum >= 0 ? routingFilters.value[Object.keys(routingFilters.value)[Object.keys(routingFilters.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() // TODO: need to create createdDate object when clicking save button, as adding it here will have difference between creation time when having multiple filters to create } } } } function saveSortOptions() { - closeModal(routingFilters.value, 'save'); + closeModal('save'); } function isSortOptionSelected(code: string) { - return routingFilters.value[props.conditionTypeEnumId]?.[code] + return routingFilters.value?.[code] } -function closeModal(filters = {}, action = 'close') { - modalController.dismiss({ dismissed: true, filters }, action) +function closeModal(action = 'close') { + modalController.dismiss({ dismissed: true, filters: routingFilters.value }, action) } diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 3128138..e93c76b 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -115,13 +115,7 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) }, - async fetchCurrentOrderRouting({ dispatch, state }, orderRoutingId) { - const current = state.currentRoute - if(current.orderRoutingId && current.orderRoutingId === orderRoutingId) { - dispatch("setCurrentOrderRouting", current) - return; - } - + async fetchCurrentOrderRouting({ dispatch }, orderRoutingId) { let currentRoute = {} try { @@ -239,9 +233,9 @@ const actions: ActionTree = { }, async deleteRoutingFilters({ dispatch }, payload) { - // TODO: check if we can call request in parallel for delete operation let hasAllFiltersDeletedSuccessfully = true; try { + // We can't make parallel api calls, as discussed hence using forEach loop to make api calls await payload.filters.forEach(async (filter: any) => { const resp = await OrderRoutingService.deleteRoutingFilter({ orderRoutingId: payload.orderRoutingId, diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index b56bd76..304a031 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -19,34 +19,34 @@ -

{{ "Select filter to apply" }}

+

{{ "Select filter to apply" }}

- - + + {{ facility.facilityName || facilityId }} - - + + {{ shippingMethod.shippingMethodId || shippingMethodId }} - - + + {{ "High" }} {{ "Medium" }} {{ "Low" }} - + {{ "Promise date" }} - {{ getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue || getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue == 0 ? getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue : '-' }} + {{ getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue || getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue == 0 ? getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue : '-' }} - - + + {{ enumInfo.description || enumInfo.enumId }} @@ -59,9 +59,9 @@ -

{{ "Select sorting to apply" }}

+

{{ "Select sorting to apply" }}

- + {{ getLabel("ORD_SORT_PARAM_TYPE", code) || code }} @@ -212,7 +212,7 @@ import { useRouter } from "vue-router"; import { computed, defineProps, ref } from "vue"; import store from "@/store"; import AddInventoryFilterOptionsModal from "@/components/AddInventoryFilterOptionsModal.vue"; -import { showToast } from "@/utils"; +import { showToast, sortSequence } from "@/utils"; import { Rule } from "@/types"; import AddOrderRouteFilterOptions from "@/components/AddOrderRouteFilterOptions.vue" import PromiseFilterPopover from "@/components/PromiseFilterPopover.vue" @@ -231,15 +231,19 @@ const actionEnums = JSON.parse(process.env?.VUE_APP_RULE_ACTION_ENUMS as string) const conditionFilterEnums = JSON.parse(process.env?.VUE_APP_RULE_FILTER_ENUMS as string) const autoCancelDays = ref(0) const ruleActionType = ref('') -let orderRoutingFilters = ref({}) as any + +let orderRoutingFilters = ref([]) as any +let orderRoutingFilterOptions = ref({}) as any +let orderRoutingSortOptions = ref({}) as any + + let selectedRoutingRule = ref({}) as any let inventoryRuleConditions = ref({}) as any let inventoryRules = ref([]) as any -let rulesToUpdate = ref([]) as any const currentRouting = computed(() => store.getters["orderRouting/getCurrentOrderRouting"]) + const routingRules = computed(() => store.getters["orderRouting/getRoutingRules"]) -const routingFilters = computed(() => store.getters["orderRouting/getCurrentRouteFilters"]) const ruleActions = computed(() => store.getters["orderRouting/getRuleActions"]) const ruleConditions = computed(() => store.getters["orderRouting/getRuleConditions"]) const facilities = computed(() => store.getters["util/getFacilities"]) @@ -250,7 +254,8 @@ const facilityGroups = computed(() => store.getters["util/getFacilityGroups"]) onIonViewWillEnter(async () => { await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingRules", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingFilters", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")]) - orderRoutingFilters.value = JSON.parse(JSON.stringify(routingFilters.value)) + orderRoutingFilters.value = JSON.parse(JSON.stringify(currentRouting.value["orderFilters"])) + initializeOrderRoutingOptions() // 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(!routingRules.value.length) { @@ -262,6 +267,22 @@ onIonViewWillEnter(async () => { await fetchRuleInformation(inventoryRules.value[0].routingRuleId); }) +function initializeOrderRoutingOptions() { + const orderRouteFilters = sortSequence(JSON.parse(JSON.stringify(orderRoutingFilters.value))).reduce((filters: any, filter: any) => { + if(filters[filter.conditionTypeEnumId]) { + filters[filter.conditionTypeEnumId][filter.fieldName] = filter + } else { + filters[filter.conditionTypeEnumId] = { + [filter.fieldName]: filter + } + } + return filters + }, {}) + + orderRoutingFilterOptions.value = orderRouteFilters["ENTCT_FILTER"] + orderRoutingSortOptions.value = orderRouteFilters["ENTCT_SORT_BY"] +} + async function fetchRuleInformation(routingRuleId: string) { // 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 @@ -307,14 +328,14 @@ async function addInventoryFilterOptions(parentEnumId: string, conditionTypeEnum async function addOrderRouteFilterOptions(parentEnumId: string, conditionTypeEnumId: string, label = "") { const orderRouteFilterOptions = await modalController.create({ component: AddOrderRouteFilterOptions, - componentProps: { orderRoutingFilters: orderRoutingFilters.value, orderRoutingId: props.orderRoutingId, parentEnumId, conditionTypeEnumId, label } + componentProps: { orderRoutingFilters: conditionTypeEnumId === 'ENTCT_FILTER' ? orderRoutingFilterOptions.value : orderRoutingSortOptions.value, orderRoutingId: props.orderRoutingId, parentEnumId, conditionTypeEnumId, label } }) orderRouteFilterOptions.onDidDismiss().then((result: any) => { // Using role to determine when to update the filters // When closing the modal without save and when unselecting all the filter, in both the cases we get filters object as empty thus passing a role from the modal to update the filter only when save action is performed - if(result.data?.filters && result.role === 'save') { - orderRoutingFilters.value = result.data.filters + if(result.role === 'save') { + conditionTypeEnumId === 'ENTCT_FILTER' ? ( orderRoutingFilterOptions.value = result.data.filters ) : ( orderRoutingSortOptions.value = result.data.filters ) } }) @@ -418,7 +439,7 @@ function updatePartialAllocation(checked: any) { } function getFilterValue(options: any, enums: any, parameter: string) { - return options["ENTCT_FILTER"]?.[enums[parameter].code] + return options?.[enums[parameter].code] } function getLabel(parentType: string, code: string) { @@ -438,8 +459,8 @@ async function selectPromiseFilterValue(ev: CustomEvent) { }) popover.onDidDismiss().then((result: any) => { - getFilterValue(orderRoutingFilters.value, ruleEnums, "PROMISE_DATE").fieldValue = result.data?.isPastDuration ? `-${result.data?.duration}` : result.data?.duration - getFilterValue(orderRoutingFilters.value, ruleEnums, "PROMISE_DATE").operator = "less-equals" + getFilterValue(orderRoutingFilterOptions.value, ruleEnums, "PROMISE_DATE").fieldValue = result.data?.isPastDuration ? `-${result.data?.duration}` : result.data?.duration + getFilterValue(orderRoutingFilterOptions.value, ruleEnums, "PROMISE_DATE").operator = "less-equals" }) return popover.present(); @@ -478,8 +499,8 @@ function updateOperator(event: CustomEvent) { getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, "BRK_SAFETY_STOCK").operator = event.detail.value } -function updateOrderFilterValue(event: CustomEvent, conditionTypeEnumId: string, id: string) { - orderRoutingFilters.value[conditionTypeEnumId][ruleEnums[id].code].fieldValue = event.detail.value +function updateOrderFilterValue(event: CustomEvent, id: string) { + orderRoutingFilterOptions.value[ruleEnums[id].code].fieldValue = event.detail.value } function updateRuleFilterValue(event: CustomEvent, conditionTypeEnumId: string, id: string) { @@ -495,17 +516,17 @@ function updateRuleStatus(routingRuleId: string, statusId: string) { } function doRouteSortReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(Object.values(orderRoutingFilters.value["ENTCT_SORT_BY"]))) + const previousSeq = JSON.parse(JSON.stringify(Object.values(orderRoutingSortOptions.value))) // returns the updated sequence after reordering - const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(orderRoutingFilters.value["ENTCT_SORT_BY"])))); + const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(orderRoutingSortOptions.value)))); const updatedSeqenceNum = Object.keys(previousSeq).map((filter: any) => previousSeq[filter].sequenceNum) Object.keys(updatedSeq).map((key: any, index: number) => { updatedSeq[key].sequenceNum = updatedSeqenceNum[index] }) - orderRoutingFilters.value["ENTCT_SORT_BY"] = updatedSeq.reduce((filters: any, filter: any) => { + orderRoutingSortOptions.value = updatedSeq.reduce((filters: any, filter: any) => { filters[filter.fieldName] = filter return filters }, {}) @@ -539,6 +560,68 @@ function findRoutingsDiff(previousSeq: any, updatedSeq: any) { return diffSeq; } +function findSortDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].fieldName === previousSeq[key].fieldName && updatedSeq[key].sequenceNum === previousSeq[key].sequenceNum) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + if(!previousSeq[key]) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + +function findFilterDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].fieldName === previousSeq[key].fieldName && updatedSeq[key].fieldValue === previousSeq[key].fieldValue && updatedSeq[key].operator === previousSeq[key].operator) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + if(!previousSeq[key]) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + function doReorder(event: CustomEvent) { const previousSeq = JSON.parse(JSON.stringify(routingRules.value)) @@ -555,103 +638,43 @@ function doReorder(event: CustomEvent) { diffSeq = Object.keys(diffSeq).map((key) => diffSeq[key]) inventoryRules.value = updatedSeq - rulesToUpdate.value = diffSeq } // checks whether values for all the properties of two objects are same -function isObjectUpdated(initialObj: any, finalObj: any) { +function updatedFilters(initialObj: any, finalObj: any) { return !Object.keys(initialObj).every((key: string) => finalObj[key] === initialObj[key]) || Object.keys(initialObj).length !== Object.keys(finalObj).length } async function save() { - const valueRequiredForRouteFilter = "ENTCT_FILTER" - const filtersToUpdate = [] as any, filtersToRemove = [] as any, filtersToCreate = [] as any - const conditionTypes = Object.keys(enums.value["CONDITION_TYPE"]) - - conditionTypes.map((filterType: string) => { - if(orderRoutingFilters.value[filterType]) { - Object.keys(orderRoutingFilters.value[filterType]).map((key: string) => { - if(routingFilters.value[filterType]?.[key]) { - const isSeqChanged = isObjectUpdated(routingFilters.value[filterType][key], orderRoutingFilters.value[filterType]?.[key]) - if(isSeqChanged) { - // Expanding object, as when the filter which is updated needs to use the values from original object, but if there is some change in the latest object(like seqNum due to reordering) then needs to override it - filtersToUpdate.push({ - ...routingFilters.value[filterType][key], - ...orderRoutingFilters.value[filterType][key] - }) - } - } else { - // Added check for 0, as when applying promiseDate filter the value can be zero - if(filterType === valueRequiredForRouteFilter && (orderRoutingFilters.value[filterType][key]?.["fieldValue"] || orderRoutingFilters.value[filterType][key]?.["fieldValue"] == 0)) { - filtersToCreate.push(orderRoutingFilters.value[filterType][key]) - } else if(filterType !== valueRequiredForRouteFilter) { - filtersToCreate.push(orderRoutingFilters.value[filterType][key]) - } - } - }) - } - - if(routingFilters.value[filterType]) { - Object.keys(routingFilters.value[filterType]).map((key: string) => { - if(!orderRoutingFilters.value[filterType]?.[key]) { - filtersToRemove.push(routingFilters.value[filterType][key]) - } - }) + const orderRouting = { + orderRoutingId: props.orderRoutingId, + routingGroupId: currentRouting.value.routingGroupId + } as any + + const routeSortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { + filters[filter.fieldName] = filter } - }) + return filters + }, {}), orderRoutingSortOptions.value) - const conditionsToUpdate = [] as any, conditionsToRemove = [] as any, conditionsToCreate = [] as any - - conditionTypes.map((filterType: string) => { - if(inventoryRuleConditions.value[filterType]) { - Object.keys(inventoryRuleConditions.value[filterType]).map((key: string) => { - if(ruleConditions.value[filterType]?.[key]) { - const isSeqChanged = isObjectUpdated(ruleConditions.value[filterType][key], inventoryRuleConditions.value[filterType]?.[key]) - if(isSeqChanged) { - // Expanding object, as when the filter which is updated needs to use the values from original object, but if there is some change in the latest object(like seqNum due to reordering) then needs to override it - conditionsToUpdate.push({ - ...ruleConditions.value[filterType][key], - ...inventoryRuleConditions.value[filterType][key] - }) - } - } else { - // Added check for 0, as when applying safetyStock filter the value can be zero - if(filterType === valueRequiredForRouteFilter && (inventoryRuleConditions.value[filterType][key]?.["fieldValue"] || inventoryRuleConditions.value[filterType][key]?.["fieldValue"] == 0)) { - conditionsToCreate.push(inventoryRuleConditions.value[filterType][key]) - } else if(filterType !== valueRequiredForRouteFilter) { - conditionsToCreate.push(inventoryRuleConditions.value[filterType][key]) - } - } - }) + const routeFilterOptionsDiff = findFilterDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + if(filter.conditionTypeEnumId === "ENTCT_FILTER") { + filters[filter.fieldName] = filter } + return filters + }, {}), orderRoutingFilterOptions.value) - if(ruleConditions.value[filterType]) { - Object.keys(ruleConditions.value[filterType]).map((key: string) => { - if(!inventoryRuleConditions.value[filterType]?.[key]) { - conditionsToRemove.push(ruleConditions.value[filterType][key]) - } - }) - } - }) - - // TODO: add support to update rules - // TODO: add support to update filters - // TODO: add support to update conditions - - if(filtersToCreate.length) { - await store.dispatch("orderRouting/createRoutingFilters", { filters: filtersToCreate, orderRoutingId: props.orderRoutingId }) - } + const filtersToRemove = Object.values({ ...routeFilterOptionsDiff.seqToRemove, ...routeSortOptionsDiff.seqToRemove }) + const filtersToUpdate = Object.values({ ...routeFilterOptionsDiff.seqToUpdate, ...routeSortOptionsDiff.seqToUpdate }) if(filtersToRemove.length) { await store.dispatch("orderRouting/deleteRoutingFilters", { filters: filtersToRemove, orderRoutingId: props.orderRoutingId }) } - if(conditionsToCreate.length) { - await store.dispatch("orderRouting/createRuleConditions", { conditions: conditionsToCreate, routingRuleId: selectedRoutingRule.value.routingRuleId }) - } - - if(conditionsToRemove.length) { - await store.dispatch("orderRouting/deleteRuleConditions", { conditions: conditionsToRemove, routingRuleId: selectedRoutingRule.value.routingRuleId }) + if(filtersToUpdate.length) { + orderRouting["orderFilters"] = filtersToUpdate + await store.dispatch("orderRouting/updateRoutingFilters", orderRouting) } } From 151c7eb8e55200f8de0fe9324d20d4ecbd250c80 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sat, 27 Jan 2024 17:59:00 +0530 Subject: [PATCH 2/6] Improved: logic to update the filters in bulk, added check for undefined and added some comments(#24) --- src/services/RoutingService.ts | 6 ++--- src/store/modules/orderRouting/actions.ts | 29 ++++++++-------------- src/views/BrokeringQuery.vue | 30 ++++++++++++++--------- 3 files changed, 31 insertions(+), 34 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index db4998e..40e9761 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -78,9 +78,9 @@ const fetchRoutingFilters = async (payload: any): Promise => { }); } -const updateRoutingFilter = async (payload: any): Promise => { +const updateRouting = async (payload: any): Promise => { return api({ - url: `routings/${payload.orderRoutingId}/orderFilters`, + url: `routings/${payload.orderRoutingId}`, method: "POST", data: payload }); @@ -150,6 +150,6 @@ export const OrderRoutingService = { fetchRuleConditions, scheduleBrokering, updateOrderRouting, - updateRoutingFilter, + updateRouting, updateRoutingGroup } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index e93c76b..e480d5f 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -235,8 +235,8 @@ const actions: ActionTree = { async deleteRoutingFilters({ dispatch }, payload) { let hasAllFiltersDeletedSuccessfully = true; try { - // We can't make parallel api calls, as discussed hence using forEach loop to make api calls - await payload.filters.forEach(async (filter: any) => { + // As discussed, we can't make parallel api calls, hence using for loop to make api calls + for(const filter of payload.filters) { const resp = await OrderRoutingService.deleteRoutingFilter({ orderRoutingId: payload.orderRoutingId, conditionSeqId: filter.conditionSeqId @@ -244,35 +244,26 @@ const actions: ActionTree = { if(hasError(resp) || !resp.data.orderRoutingId) { hasAllFiltersDeletedSuccessfully = false } - }); + } } catch(err) { logger.error(err); } - dispatch("fetchRoutingFilters", payload.orderRoutingId) - return hasAllFiltersDeletedSuccessfully }, - async createRoutingFilters({ dispatch }, payload) { - // TODO: check if we can call request in parallel for create operation - let hasAllFiltersCreatedSuccessfully = true; + async updateRouting({ dispatch }, payload) { + let orderRoutingId = '' try { - await payload.filters.forEach(async (filter: any) => { - const resp = await OrderRoutingService.updateRoutingFilter({ - orderRoutingId: payload.orderRoutingId, - ...filter - }); - if(hasError(resp) || !resp.data.orderRoutingId) { - hasAllFiltersCreatedSuccessfully = false - } - }); + const resp = await OrderRoutingService.updateRouting(payload) + if(!hasError(resp) && resp.data?.orderRoutingId) { + orderRoutingId = resp.data.orderRoutingId + } } catch(err) { logger.error(err); } - dispatch("fetchRoutingFilters", payload.orderRoutingId) - return hasAllFiltersCreatedSuccessfully + return orderRoutingId }, async fetchRuleConditions({ commit }, routingRuleId) { diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 304a031..4c96071 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -232,7 +232,6 @@ const conditionFilterEnums = JSON.parse(process.env?.VUE_APP_RULE_FILTER_ENUMS a const autoCancelDays = ref(0) const ruleActionType = ref('') -let orderRoutingFilters = ref([]) as any let orderRoutingFilterOptions = ref({}) as any let orderRoutingSortOptions = ref({}) as any @@ -254,7 +253,6 @@ const facilityGroups = computed(() => store.getters["util/getFacilityGroups"]) onIonViewWillEnter(async () => { await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingRules", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingFilters", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")]) - orderRoutingFilters.value = JSON.parse(JSON.stringify(currentRouting.value["orderFilters"])) initializeOrderRoutingOptions() // 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 @@ -268,7 +266,7 @@ onIonViewWillEnter(async () => { }) function initializeOrderRoutingOptions() { - const orderRouteFilters = sortSequence(JSON.parse(JSON.stringify(orderRoutingFilters.value))).reduce((filters: any, filter: any) => { + const orderRouteFilters = sortSequence(JSON.parse(JSON.stringify(currentRouting.value["orderFilters"]))).reduce((filters: any, filter: any) => { if(filters[filter.conditionTypeEnumId]) { filters[filter.conditionTypeEnumId][filter.fieldName] = filter } else { @@ -279,8 +277,8 @@ function initializeOrderRoutingOptions() { return filters }, {}) - orderRoutingFilterOptions.value = orderRouteFilters["ENTCT_FILTER"] - orderRoutingSortOptions.value = orderRouteFilters["ENTCT_SORT_BY"] + orderRoutingFilterOptions.value = orderRouteFilters["ENTCT_FILTER"] ? orderRouteFilters["ENTCT_FILTER"] : {} + orderRoutingSortOptions.value = orderRouteFilters["ENTCT_SORT_BY"] ? orderRouteFilters["ENTCT_SORT_BY"] : {} } async function fetchRuleInformation(routingRuleId: string) { @@ -609,7 +607,8 @@ function findFilterDiff(previousSeq: any, updatedSeq: any) { }, seqToUpdate) seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { - if(!previousSeq[key]) { + // Added fieldValue check as we have considered that when adding a filter option, it should always have a value + if(!previousSeq[key] && updatedSeq[key].fieldValue) { diff = { ...diff, [key]: updatedSeq[key] @@ -640,11 +639,6 @@ function doReorder(event: CustomEvent) { inventoryRules.value = updatedSeq } -// checks whether values for all the properties of two objects are same -function updatedFilters(initialObj: any, finalObj: any) { - return !Object.keys(initialObj).every((key: string) => finalObj[key] === initialObj[key]) || Object.keys(initialObj).length !== Object.keys(finalObj).length -} - async function save() { const orderRouting = { orderRoutingId: props.orderRoutingId, @@ -670,12 +664,24 @@ async function save() { if(filtersToRemove.length) { await store.dispatch("orderRouting/deleteRoutingFilters", { filters: filtersToRemove, orderRoutingId: props.orderRoutingId }) + + // TODO: check when to update the filters in state, currently not updating and fetching the records again, as when creating new filter we get conditionSeqId from response, but we can't add it in the state + // if(isSuccess) { + // await store.dispatch("orderRouting/setCurrentOrderRouting", { ...currentRouting.value, orderFilters: Object.values({ ...orderRoutingFilterOptions.value, ...orderRoutingSortOptions.value }) }) + // } } if(filtersToUpdate.length) { orderRouting["orderFilters"] = filtersToUpdate - await store.dispatch("orderRouting/updateRoutingFilters", orderRouting) + const orderRoutingId = await store.dispatch("orderRouting/updateRouting", orderRouting) + + if(orderRoutingId) { + await store.dispatch("orderRouting/setCurrentOrderRouting", { ...currentRouting.value, orderFilters: Object.values({ ...orderRoutingFilterOptions.value, ...orderRoutingSortOptions.value }) }) + } } + + await store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId) + initializeOrderRoutingOptions(); } From 4ea3094b2492f8509ddeec519c4e6eacecbf961f Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sat, 27 Jan 2024 23:59:38 +0530 Subject: [PATCH 3/6] Improved: logic to find the final diff for rule actions, filters and sort options(#24) --- .env.example | 6 +- .../AddInventoryFilterOptionsModal.vue | 39 +- src/services/RoutingService.ts | 9 +- .../modules/orderRouting/OrderRoutingState.ts | 2 +- src/store/modules/orderRouting/actions.ts | 76 ++-- src/store/modules/orderRouting/getters.ts | 5 +- src/store/modules/orderRouting/index.ts | 2 +- src/views/BrokeringQuery.vue | 340 +++++++++++++----- src/views/BrokeringRoute.vue | 2 +- 9 files changed, 316 insertions(+), 165 deletions(-) diff --git a/.env.example b/.env.example index 750230b..1d264a0 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,6 @@ VUE_APP_DEFAULT_LOG_LEVEL="error" VUE_APP_RULE_ENUMS={"QUEUE":{"id":"OIP_QUEUE","code":"facilityId"},"SHIPPING_METHOD":{"id":"OIP_SHIP_METH_TYPE","code":"shipmentMethodTypeId"},"PRIORITY":{"id":"OIP_PRIORITY","code":"priority"},"PROMISE_DATE":{"id":"OIP_PROMISE_DATE","code":"promiseDaysCutoff"},"SALES_CHANNEL":{"id":"OIP_SALES_CHANNEL","code":"salesChannelEnumId"},"SHIP_BY":{"id":"OSP_SHIP_BY","code":"shipBeforeDate"},"SHIP_AFTER":{"id":"OSP_SHIP_AFTER","code":"shipAfterDate"},"ORDER_DATE":{"id":"OSP_ORDER_DATE","code":"orderDate"},"SHIPPING_METHOD_SORT":{"id":"OSP_SHIP_METH","code":"deliveryDays"}} VUE_APP_RULE_FILTER_ENUMS={"FACILITY_GROUP":{"id":"IIP_FACILITY_GROUP","code":"facilityGroupId"},"PROXIMITY":{"id":"IIP_PROXIMITY","code":"distance"},"BRK_SAFETY_STOCK":{"id":"IIP_BRK_SFTY_STOCK","code":"brokeringSafetyStock"},"MEASUREMENT_SYSTEM":{"id":"IIP_MSMNT_SYSTEM","code":"measurementSystem"}} VUE_APP_RULE_SORT_ENUMS={"PROXIMITY":{"id":"ISP_PROXIMITY","code":"distance"},"INV_BALANCE":{"id":"ISP_INV_BAL","code":"inventoryForAllocation"},"CUSTOMER_SEQ":{"id":"ISP_CUST_SEQ","code":"facilitySequence"}} -VUE_APP_RULE_ACTION_ENUMS={"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DAYS","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}} -VUE_APP_ROUTE_STATUS_ENUMS={"ROUTING_DRAFT":{"id":"ROUTING_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"ROUTING_ACTIVE":{"id":"ROUTING_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"ROUTING_ARCHIVED":{"id":"ROUTING_ARCHIVED","desc":"Archived","code":"ARCHIVED","color":"warning"}} -VUE_APP_CRON_EXPRESSIONS={"Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"} \ No newline at end of file +VUE_APP_RULE_ACTION_ENUMS={"RM_AUTO_CANCEL_DATE":{"id":"ORA_RM_CANCEL_DATE","code":"RM_AUTO_CANCEL_DATE"},"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DAYS","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}} +VUE_APP_STATUS_ENUMS={"ROUTING_DRAFT":{"id":"ROUTING_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"ROUTING_ACTIVE":{"id":"ROUTING_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"ROUTING_ARCHIVED":{"id":"ROUTING_ARCHIVED","desc":"Archived","code":"ARCHIVED","color":"warning"},"RULE_DRAFT":{"id":"RULE_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"RULE_ACTIVE":{"id":"RULE_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"RULE_ARCHIVED":{"id":"RULE_ARCHIVED","desc":"Acrhived","code":"ARCHIVED","color":"warning"}} +VUE_APP_CRON_EXPRESSIONS={"Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"} diff --git a/src/components/AddInventoryFilterOptionsModal.vue b/src/components/AddInventoryFilterOptionsModal.vue index e13ca4c..56d5f8e 100644 --- a/src/components/AddInventoryFilterOptionsModal.vue +++ b/src/components/AddInventoryFilterOptionsModal.vue @@ -29,6 +29,7 @@ import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, I import { useStore } from "vuex"; import { computed, defineProps, onMounted, ref } from "vue"; import { saveOutline } from "ionicons/icons"; +import { DateTime } from "luxon"; const store = useStore(); const enums = computed(() => store.getters["util/getEnums"]) @@ -70,54 +71,46 @@ function addConditionOption(condition: any) { const associatedEnum = enums.value[props.parentEnumId][associatedOptions[condition.enumId]] if(isConditionOptionAlreadyApplied) { - delete inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] + delete inventoryRuleConditions.value[condition.enumCode] // When removing a condition, also remove its associated option if available - associatedEnum && delete inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] + associatedEnum && delete inventoryRuleConditions.value[associatedEnum.enumCode] } else { // checking unchecking an option and then checking it again, we need to use the same values - if(props.ruleConditions[props.conditionTypeEnumId]?.[condition.enumCode]) { - inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] = props.ruleConditions[props.conditionTypeEnumId][condition.enumCode] - associatedEnum && (inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] = props.ruleConditions[props.conditionTypeEnumId][associatedEnum.enumCode]) + if(props.ruleConditions?.[condition.enumCode]) { + inventoryRuleConditions.value[condition.enumCode] = props.ruleConditions[condition.enumCode] + associatedEnum && (inventoryRuleConditions.value[associatedEnum.enumCode] = props.ruleConditions[associatedEnum.enumCode]) } else { // when adding a new value, we don't need to pass conditionSeqId // Added check that whether the filters for the conditionType exists or not, if not then create a new value for conditionType - inventoryRuleConditions.value[props.conditionTypeEnumId] ? inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] = { + inventoryRuleConditions.value[condition.enumCode] = { routingRuleId: props.routingRuleId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: condition.enumCode, - sequenceNum: Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length && inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 - } : inventoryRuleConditions.value = { - ...inventoryRuleConditions.value, - [props.conditionTypeEnumId]: { - [condition.enumCode]: { - routingRuleId: props.routingRuleId, - conditionTypeEnumId: props.conditionTypeEnumId, - fieldName: condition.enumCode, - sequenceNum: 0 - } - } + sequenceNum: Object.keys(inventoryRuleConditions.value).length && inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() } // Adding associatedEnum out of ternary, as we will always get the conditionTypeEnumId, as the filter will already handle that - associatedEnum && (inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] = { + associatedEnum && (inventoryRuleConditions.value[associatedEnum.enumCode] = { routingRuleId: props.routingRuleId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: associatedEnum.enumCode, - sequenceNum: Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length && inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + sequenceNum: Object.keys(inventoryRuleConditions.value).length && inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() }) } } } function saveConditionOptions() { - closeModal(inventoryRuleConditions.value, 'save'); + closeModal('save'); } function isConditionOptionSelected(code: string) { - return inventoryRuleConditions.value[props.conditionTypeEnumId]?.[code] + return inventoryRuleConditions.value?.[code] } -function closeModal(filters = {}, action = 'close') { - modalController.dismiss({ dismissed: true, filters }, action) +function closeModal(action = 'close') { + modalController.dismiss({ dismissed: true, filters: inventoryRuleConditions.value }, action) } diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 40e9761..488f8d8 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -118,11 +118,10 @@ const deleteRuleCondition = async (payload: any): Promise => { }); } -const fetchRuleActions = async (payload: any): Promise => { +const fetchRule = async (routingRuleId: string): Promise => { return api({ - url: `rules/${payload.routingRuleId}/actions`, - method: "GET", - query: payload + url: `rules/${routingRuleId}`, + method: "GET" }); } @@ -146,7 +145,7 @@ export const OrderRoutingService = { fetchRoutingGroupInformation, fetchRoutingGroups, fetchRoutingRules, - fetchRuleActions, + fetchRule, fetchRuleConditions, scheduleBrokering, updateOrderRouting, diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 12c66b0..5a550de 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -3,7 +3,7 @@ import { Group, RouteFilter } from "@/types"; export default interface OrderRoutingState { groups: Array; // runs routes: Array; - rules: Array; + rules: any; currentGroup: any; currentRoute: any; currentRouteFilters: { diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index e480d5f..d4dff8e 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -137,32 +137,6 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload) }, - async fetchRoutingRules({ commit }, orderRoutingId) { - let routingRules = [] as any; - // filter groups on the basis of productStoreId - const payload = { - orderRoutingId - } - - try { - const resp = await OrderRoutingService.fetchRoutingRules(payload); - - if(!hasError(resp) && resp.data.length) { - routingRules = resp.data - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } - - if(routingRules.length) { - routingRules = sortSequence(routingRules) - } - - commit(types.ORDER_ROUTING_RULES_UPDATED, routingRules) - }, - async createRoutingRule({ commit, state }, payload) { let routingRules = JSON.parse(JSON.stringify(state.rules)) let routingRuleId = '' @@ -347,31 +321,47 @@ const actions: ActionTree = { return hasAllConditionsCreatedSuccessfully }, - async fetchRuleActions({ commit }, routingRuleId) { - let ruleActions = {} as any; - const payload = { - routingRuleId + async fetchInventoryRuleInformation({ commit, state }, routingRuleId) { + const rulesInformation = JSON.parse(JSON.stringify(state.rules)) + + // Do not fetch the rule information if its already available in state. This condition will be false on refresh as state will be cleared so automatically updated information will be fetched + if(rulesInformation[routingRuleId]) { + return rulesInformation[routingRuleId]; } try { - const resp = await OrderRoutingService.fetchRuleActions(payload); + const resp = await OrderRoutingService.fetchRule(routingRuleId) + + if(!hasError(resp) && resp.data.routingRuleId) { + rulesInformation[routingRuleId] = resp.data + + if(rulesInformation[routingRuleId]["inventoryFilters"]?.length) { + rulesInformation[routingRuleId]["inventoryFilters"] = sortSequence(rulesInformation[routingRuleId]["inventoryFilters"]).reduce((filters: any, filter: any) => { + if(filters[filter.conditionTypeEnumId]) { + filters[filter.conditionTypeEnumId][filter.fieldName] = filter + } else { + filters[filter.conditionTypeEnumId] = { + [filter.fieldName]: filter + } + } + return filters + }, {}) + } - if(!hasError(resp) && resp.data.length) { - ruleActions = resp.data.reduce((actions: any, action: any) => { - // considering that only one value for an action is available - actions[action.actionTypeEnumId] = action - return actions - }, {}) - } else { - throw resp.data + if(rulesInformation[routingRuleId]["actions"]?.length) { + rulesInformation[routingRuleId]["actions"] = rulesInformation[routingRuleId]["actions"].reduce((actions: any, action: any) => { + actions[action.actionTypeEnumId] = action + return actions + }, {}) + } } } catch(err) { - logger.error(err); + logger.error(err) } - commit(types.ORDER_ROUTING_RULE_ACTIONS_UPDATED, ruleActions) - }, - + commit(types.ORDER_ROUTING_RULES_UPDATED, rulesInformation) + return JSON.parse(JSON.stringify(rulesInformation[routingRuleId])) + } } export default actions; \ No newline at end of file diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index b38bfd2..7aeb909 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -7,7 +7,10 @@ const getters: GetterTree = { return state.groups }, getRoutingRules(state) { - return JSON.parse(JSON.stringify(state.rules)) + return state.currentGroup["rules"] ? JSON.parse(JSON.stringify(state.currentGroup["rules"])) : [] + }, + getRulesInformation(state) { + return state.rules }, getCurrentRoutingGroup(state) { return JSON.parse(JSON.stringify(state.currentGroup)) diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index ae5b873..5346aeb 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -11,7 +11,7 @@ const orderRoutingModule: Module = { state: { groups: [], routes: [], - rules: [], + rules: {}, currentGroup: {}, currentRoute: {}, currentRouteFilters: {}, diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 4c96071..094db0c 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -87,8 +87,8 @@ {{ "Rule Status" }} - {{ selectedRoutingRule.statusId }} - {{ selectedRoutingRule.statusId }} + {{ statusEnums[selectedRoutingRule.statusId]?.desc }} + {{ statusEnums[selectedRoutingRule.statusId]?.desc }}
@@ -99,31 +99,31 @@ -

{{ "Select filter to apply" }}

- - +

{{ "Select filter to apply" }}

+ + {{ facilityGroup.description || facilityGroupId }} - + {{ "Proximity" }} - + {{ "kms" }} {{ "miles" }} - {{ getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue || getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue == 0 ? getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue : '-' }} + {{ getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue || getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue == 0 ? getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue : '-' }} - + {{ "Brokering safety stock" }} - + {{ enumeration.description || enumeration.enumCode }} - {{ getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue || getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue == 0 ? getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue : '-' }} + {{ getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue || getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue == 0 ? getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue : '-' }}
@@ -134,9 +134,9 @@ -

{{ "Select sorting to apply" }}

+

{{ "Select sorting to apply" }}

- + {{ getLabel("INV_SORT_PARAM_TYPE", code) || code }} @@ -153,7 +153,7 @@ - {{ "Clear auto cancel days" }} + {{ "Clear auto cancel days" }}
@@ -176,7 +176,7 @@ - + {{ "Next rule" }} @@ -188,13 +188,13 @@ - + {{ facility.facilityName || facilityId }} {{ "Auto cancel days" }} - {{ autoCancelDays ? `${autoCancelDays} days` : '-' }} + {{ inventoryRuleActions[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue ? `${inventoryRuleActions[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue} days` : '-' }} @@ -217,6 +217,7 @@ import { Rule } from "@/types"; import AddOrderRouteFilterOptions from "@/components/AddOrderRouteFilterOptions.vue" import PromiseFilterPopover from "@/components/PromiseFilterPopover.vue" import logger from "@/logger"; +import { DateTime } from "luxon"; const router = useRouter(); const props = defineProps({ @@ -229,40 +230,37 @@ const props = defineProps({ const ruleEnums = JSON.parse(process.env?.VUE_APP_RULE_ENUMS as string) const actionEnums = JSON.parse(process.env?.VUE_APP_RULE_ACTION_ENUMS as string) const conditionFilterEnums = JSON.parse(process.env?.VUE_APP_RULE_FILTER_ENUMS as string) -const autoCancelDays = ref(0) -const ruleActionType = ref('') - -let orderRoutingFilterOptions = ref({}) as any -let orderRoutingSortOptions = ref({}) as any - - -let selectedRoutingRule = ref({}) as any -let inventoryRuleConditions = ref({}) as any -let inventoryRules = ref([]) as any +const statusEnums = JSON.parse(process.env?.VUE_APP_STATUS_ENUMS as string) const currentRouting = computed(() => store.getters["orderRouting/getCurrentOrderRouting"]) - -const routingRules = computed(() => store.getters["orderRouting/getRoutingRules"]) -const ruleActions = computed(() => store.getters["orderRouting/getRuleActions"]) -const ruleConditions = computed(() => store.getters["orderRouting/getRuleConditions"]) +const routingRules = computed(() => store.getters["orderRouting/getRulesInformation"]) const facilities = computed(() => store.getters["util/getFacilities"]) const enums = computed(() => store.getters["util/getEnums"]) const shippingMethods = computed(() => store.getters["util/getShippingMethods"]) const facilityGroups = computed(() => store.getters["util/getFacilityGroups"]) +let ruleActionType = ref('') +let selectedRoutingRule = ref({}) as any +let inventoryRules = ref([]) as any +let orderRoutingFilterOptions = ref({}) as any +let orderRoutingSortOptions = ref({}) as any +let inventoryRuleFilterOptions = ref({}) as any +let inventoryRuleSortOptions = ref({}) as any +let inventoryRuleActions = ref({}) as any +let rulesInformation = ref({}) as any + onIonViewWillEnter(async () => { - await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingRules", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingFilters", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")]) + await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")]) - initializeOrderRoutingOptions() + if(currentRouting.value["orderFilters"]?.length) { + initializeOrderRoutingOptions() + } // 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(!routingRules.value.length) { - return; + if(currentRouting.value["rules"]?.length) { + inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"])) + await fetchRuleInformation(inventoryRules.value[0].routingRuleId); } - - inventoryRules.value = JSON.parse(JSON.stringify(routingRules.value)) - - await fetchRuleInformation(inventoryRules.value[0].routingRuleId); }) function initializeOrderRoutingOptions() { @@ -281,6 +279,19 @@ function initializeOrderRoutingOptions() { orderRoutingSortOptions.value = orderRouteFilters["ENTCT_SORT_BY"] ? orderRouteFilters["ENTCT_SORT_BY"] : {} } +async function initializeInventoryRules(rule: any) { + const inventoryRuleFilters = rule["inventoryFilters"] ? rule["inventoryFilters"] : {} + + inventoryRuleActions.value = rule["actions"] || {} + inventoryRuleFilterOptions.value = inventoryRuleFilters["ENTCT_FILTER"] ? inventoryRuleFilters["ENTCT_FILTER"] : {} + inventoryRuleSortOptions.value = inventoryRuleFilters["ENTCT_SORT_BY"] ? inventoryRuleFilters["ENTCT_SORT_BY"] : {} + + const actionTypes = ["ORA_NEXT_RULE", "ORA_MV_TO_QUEUE"] + ruleActionType.value = Object.keys(inventoryRuleActions.value).find((actionId: string) => { + return actionTypes.includes(actionId) + }) || '' +} + async function fetchRuleInformation(routingRuleId: string) { // 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 @@ -288,35 +299,41 @@ async function fetchRuleInformation(routingRuleId: string) { return; } - selectedRoutingRule.value = inventoryRules.value.find((rule: Rule) => rule.routingRuleId === routingRuleId) - await Promise.all([store.dispatch("orderRouting/fetchRuleConditions", routingRuleId), store.dispatch("orderRouting/fetchRuleActions", routingRuleId)]) + // Only fetch the rules information, if already not present, as we are updating rule values + if(!rulesInformation.value[routingRuleId]) { + rulesInformation.value[routingRuleId] = await store.dispatch("orderRouting/fetchInventoryRuleInformation", routingRuleId) + } - inventoryRuleConditions.value = JSON.parse(JSON.stringify(ruleConditions.value)) - autoCancelDays.value = ruleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue + // TODO: check on this condition, remove if not required + // If there is not an already selected rule, deep clone it for usage. This condition can occur when we does not have any inventory rules for the route and we have created a new rule + if(!selectedRoutingRule.value.routingRuleId) { + rulesInformation.value = JSON.parse(JSON.stringify(routingRules.value)) + } - const actionTypes = ["ORA_NEXT_RULE", "ORA_MV_TO_QUEUE"] - ruleActionType.value = Object.keys(ruleActions.value).find((actionId: string) => { - return actionTypes.includes(actionId) - }) || '' + // Using currentRouting["rules"] deep-cloned object here, 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]))); } async function addInventoryFilterOptions(parentEnumId: string, conditionTypeEnumId: string, label = "") { if(!selectedRoutingRule.value.routingRuleId) { - // TODO: check if we can show a toast here - logger.error('Failed to identify selected inventory rule, please select a rule or refresh') + showToast("Failed to identify selected inventory rule, please select a rule or refresh") + logger.error("Failed to identify selected inventory rule, please select a rule or refresh") return; } const inventoryFilterOptionsModal = await modalController.create({ component: AddInventoryFilterOptionsModal, - componentProps: { ruleConditions: inventoryRuleConditions.value, routingRuleId: selectedRoutingRule.value.routingRuleId, parentEnumId, conditionTypeEnumId, label } + componentProps: { ruleConditions: conditionTypeEnumId === 'ENTCT_FILTER' ? inventoryRuleFilterOptions.value : inventoryRuleSortOptions.value, routingRuleId: selectedRoutingRule.value.routingRuleId, parentEnumId, conditionTypeEnumId, label } }) inventoryFilterOptionsModal.onDidDismiss().then((result: any) => { // Using role to determine when to update the filters // When closing the modal without save and when unselecting all the filter, in both the cases we get filters object as empty thus passing a role from the modal to update the filter only when save action is performed - if(result.data?.filters && result.role === 'save') { - inventoryRuleConditions.value = result.data.filters + if(result.role === 'save') { + conditionTypeEnumId === 'ENTCT_FILTER' ? ( inventoryRuleFilterOptions.value = result.data.filters ) : ( inventoryRuleSortOptions.value = result.data.filters ) + updateRule() } }) @@ -367,7 +384,7 @@ async function addInventoryRule() { statusId: "RULE_DRAFT", // by default considering the rule to be in draft sequenceNum: inventoryRules.value.length && inventoryRules.value[inventoryRules.value.length - 1].sequenceNum >= 0 ? inventoryRules.value[inventoryRules.value.length - 1].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0, that will result in again setting the new route seqNum to 0, assignmentEnumId: "ORA_SINGLE", // by default, considering partial fulfillment to be inactive - fulfillEntireShipGroup: "N", // TODO: check for default value + createdDate: DateTime.now().toMillis() } const resp = await store.dispatch("orderRouting/createRoutingRule", payload) @@ -380,24 +397,41 @@ async function addInventoryRule() { return newRuleAlert.present(); } -function updateRuleActionType(value: string) { +// When changing the selected rule, updating any changes made in filter, sort and actions of the current rule +function updateRule() { + rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"] = { "ENTCT_FILTER": inventoryRuleFilterOptions.value, "ENTCT_SORT_BY": inventoryRuleSortOptions.value } + rulesInformation.value[selectedRoutingRule.value.routingRuleId]["actions"] = inventoryRuleActions.value +} + +function updateUnfillableActionType(value: string) { const actionType = ruleActionType.value ruleActionType.value = value - ruleActions.value[ruleActionType.value] = { - ...ruleActions.value[actionType], + inventoryRuleActions.value[ruleActionType.value] = { actionTypeEnumId: value, - actionValue: '' // after changing action type, as next_rule action does not need to have a value, so in all cases making intially the value as empty and will update if required from some other function + actionValue: "", // after changing action type, as next_rule action does not need to have a value, so in all cases making intially the value as empty and will update if required from some other function + createdDate: DateTime.now().toMillis() } // deleting previous action type, but using the data of previous action, as we will not call delete action on server for actionTypes - delete ruleActions.value[actionType] + delete inventoryRuleActions.value[actionType] + updateRule() } function updateRuleActionValue(value: string) { - ruleActions.value[ruleActionType.value]["actionValue"] = value + if(inventoryRuleActions.value[ruleActionType.value]) { + inventoryRuleActions.value[ruleActionType.value]["actionValue"] = value + } else { + inventoryRuleActions.value = { + ...inventoryRuleActions.value, + [ruleActionType.value]: { + actionValue: value + } + } + } + updateRule() } -async function updateAutoCancelDays(cancelDays: any) { +async function updateAutoCancelDays() { const alert = await alertController.create({ header: "Auto Cancel Days", inputs: [{ @@ -405,7 +439,7 @@ async function updateAutoCancelDays(cancelDays: any) { placeholder: "auto cancel days", type: "number", min: 0, - value: cancelDays + value: inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue }], buttons: [{ text: "Cancel", @@ -414,18 +448,23 @@ async function updateAutoCancelDays(cancelDays: any) { { text: "Save", handler: (data) => { - if(data) { - if(data.autoCancelDays === '') { - showToast("Please provide a value") - return false; - } else if(data.autoCancelDays < 0) { - showToast("Provide a value greater than or equal to 0") - return false; + if(data?.autoCancelDays || data.autoCancelDays === 0) { + if(inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue) { + inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue = data.autoCancelDays } else { - autoCancelDays.value = data.autoCancelDays - ruleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue = data.autoCancelDays + inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id] = { + actionTypeEnumId: actionEnums['AUTO_CANCEL_DAYS'].id, + actionValue: data.autoCancelDays, + createdDate: DateTime.now().toMillis(), + } + } + } else { + // If we have received an empty/undefined value for autoCancelDays then considered that it needs to be removed + if(inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue) { + delete inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id] } } + updateRule() } }] }) @@ -433,7 +472,11 @@ async function updateAutoCancelDays(cancelDays: any) { } function updatePartialAllocation(checked: any) { - selectedRoutingRule.value.assignmentEnumId = checked ? "ORA_MULTI" : "ORA_SINGLE" + inventoryRules.value.map((inventoryRule: any) => { + if(inventoryRule.routingRuleId === selectedRoutingRule.value.routingRuleId) { + inventoryRule.assignmentEnumId = checked ? "ORA_MULTI" : "ORA_SINGLE" + } + }) } function getFilterValue(options: any, enums: any, parameter: string) { @@ -465,6 +508,7 @@ async function selectPromiseFilterValue(ev: CustomEvent) { } async function selectValue(id: string, header: string) { + const filter = getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, id) const valueAlert = await alertController.create({ header, buttons: [{ @@ -476,7 +520,7 @@ async function selectValue(id: string, header: string) { inputs: [{ name: "value", placeholder: "value", - value: getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).fieldValue + value: filter.fieldValue }] }) @@ -484,9 +528,10 @@ async function selectValue(id: string, header: string) { const value = result.data?.values?.value; // Considering that when having role in result, its negative action and not need to do anything if(!result.role && value) { - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).fieldValue = value - // When selecting a filter value making the operator to default `equals` - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).operator = "equals" + filter.fieldValue = value + // When selecting a filter value making the operator to default `equals` if not present already + filter.operator = filter.operator || "equals" + updateRule() } }) @@ -494,17 +539,37 @@ async function selectValue(id: string, header: string) { } function updateOperator(event: CustomEvent) { - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, "BRK_SAFETY_STOCK").operator = event.detail.value + getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, "BRK_SAFETY_STOCK").operator = event.detail.value + updateRule() } function updateOrderFilterValue(event: CustomEvent, id: string) { orderRoutingFilterOptions.value[ruleEnums[id].code].fieldValue = event.detail.value } -function updateRuleFilterValue(event: CustomEvent, conditionTypeEnumId: string, id: string) { - inventoryRuleConditions.value[conditionTypeEnumId][conditionFilterEnums[id].code].fieldValue = event.detail.value +function updateRuleFilterValue(event: CustomEvent, id: string) { + inventoryRuleFilterOptions.value[conditionFilterEnums[id].code].fieldValue = event.detail.value + updateRule() +} + +function updateClearAutoCancelDays(checked: any) { + if(inventoryRuleActions.value[actionEnums["RM_AUTO_CANCEL_DATE"].id]) { + inventoryRuleActions.value[actionEnums["RM_AUTO_CANCEL_DATE"].id].actionValue = checked + } else { + inventoryRuleActions.value = { + ...inventoryRuleActions.value, + [actionEnums["RM_AUTO_CANCEL_DATE"].id]: { + actionValue: checked, + actionTypeEnumId: actionEnums["RM_AUTO_CANCEL_DATE"].id, + createdDate: DateTime.now().toMillis() + } + } + } + + updateRule() } +// Updating rule status function updateRuleStatus(routingRuleId: string, statusId: string) { inventoryRules.value.map((inventoryRule: any) => { if(inventoryRule.routingRuleId === routingRuleId) { @@ -531,25 +596,27 @@ function doRouteSortReorder(event: CustomEvent) { } function doConditionSortReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(Object.values(inventoryRuleConditions.value["ENTCT_SORT_BY"]))) + const previousSeq = JSON.parse(JSON.stringify(Object.values(inventoryRuleSortOptions.value))) // returns the updated sequence after reordering - const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(inventoryRuleConditions.value["ENTCT_SORT_BY"])))); + const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(inventoryRuleSortOptions.value)))); const updatedSeqenceNum = Object.keys(previousSeq).map((filter: any) => previousSeq[filter].sequenceNum) Object.keys(updatedSeq).map((key: any, index: number) => { updatedSeq[key].sequenceNum = updatedSeqenceNum[index] }) - inventoryRuleConditions.value["ENTCT_SORT_BY"] = updatedSeq.reduce((filters: any, filter: any) => { + inventoryRuleSortOptions.value = updatedSeq.reduce((filters: any, filter: any) => { filters[filter.fieldName] = filter return filters }, {}) + + updateRule() } function findRoutingsDiff(previousSeq: any, updatedSeq: any) { const diffSeq: any = Object.keys(previousSeq).reduce((diff, key) => { - if (updatedSeq[key].routingRuleId === previousSeq[key].routingRuleId) return diff + if (updatedSeq[key].routingRuleId === previousSeq[key].routingRuleId && updatedSeq[key].statusId === previousSeq[key].statusId && updatedSeq[key].assignmentEnumId === previousSeq[key].assignmentEnumId) return diff return { ...diff, [key]: updatedSeq[key] @@ -621,8 +688,39 @@ function findFilterDiff(previousSeq: any, updatedSeq: any) { return { seqToUpdate, seqToRemove }; } +function findActionDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].actionTypeEnumId === previousSeq[key].actionTypeEnumId && updatedSeq[key].actionValue === previousSeq[key].actionValue) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + if(!previousSeq[key]) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + function doReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(routingRules.value)) + const previousSeq = JSON.parse(JSON.stringify(inventoryRules.value)) // returns the updated sequence after reordering const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(inventoryRules.value))); @@ -645,6 +743,21 @@ async function save() { routingGroupId: currentRouting.value.routingGroupId } as any + // Find diff for inventory rules + let diffSeq = findRoutingsDiff(currentRouting.value["rules"], inventoryRules.value) + + const updatedSeqenceNum = currentRouting.value["rules"].map((rule: Rule) => rule.sequenceNum) + Object.keys(diffSeq).map((key: any) => { + diffSeq[key].sequenceNum = updatedSeqenceNum[key] + }) + + diffSeq = Object.keys(diffSeq).map((key) => diffSeq[key]) + + if(diffSeq.length) { + orderRouting["rules"] = diffSeq + } + // Inventory rules diff calculated + const routeSortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { filters[filter.fieldName] = filter @@ -662,7 +775,7 @@ async function save() { const filtersToRemove = Object.values({ ...routeFilterOptionsDiff.seqToRemove, ...routeSortOptionsDiff.seqToRemove }) const filtersToUpdate = Object.values({ ...routeFilterOptionsDiff.seqToUpdate, ...routeSortOptionsDiff.seqToUpdate }) - if(filtersToRemove.length) { + if(filtersToRemove?.length) { await store.dispatch("orderRouting/deleteRoutingFilters", { filters: filtersToRemove, orderRoutingId: props.orderRoutingId }) // TODO: check when to update the filters in state, currently not updating and fetching the records again, as when creating new filter we get conditionSeqId from response, but we can't add it in the state @@ -671,7 +784,7 @@ async function save() { // } } - if(filtersToUpdate.length) { + if(filtersToUpdate?.length || orderRouting["rules"]?.length) { orderRouting["orderFilters"] = filtersToUpdate const orderRoutingId = await store.dispatch("orderRouting/updateRouting", orderRouting) @@ -680,8 +793,61 @@ async function save() { } } - await store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId) - initializeOrderRoutingOptions(); + + const initialInventoryRulesInformation = JSON.parse(JSON.stringify(routingRules.value)) + console.log('initialInventoryRulesInformation', initialInventoryRulesInformation) + console.log('rulesInformation.value', rulesInformation.value) + + // Whenever we will be having a feature to delete a rule then this logic needs updation + const rulesDiff = Object.keys(initialInventoryRulesInformation).map((ruleId: string) => { + const previousRuleSortOptions = initialInventoryRulesInformation[ruleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? initialInventoryRulesInformation[ruleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {} + const updatedRuleSortOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {} + const sortOptionsDiff = findSortDiff(previousRuleSortOptions, updatedRuleSortOptions) + + console.log('sortOptionsDiff', sortOptionsDiff) + + const previousRuleFilterOptions = initialInventoryRulesInformation[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? initialInventoryRulesInformation[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} + const updatedRuleFilterOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} + const filterOptionsDiff = findFilterDiff(previousRuleFilterOptions, updatedRuleFilterOptions) + + console.log('filterOptionsDiff', filterOptionsDiff) + + const previousRuleActionOptions = initialInventoryRulesInformation[ruleId]["actions"] ? initialInventoryRulesInformation[ruleId]["actions"] : {} + const updatedRuleActionOptions = rulesInformation.value[ruleId]["actions"] ? rulesInformation.value[ruleId]["actions"] : {} + const ruleActionsDiff = findActionDiff(previousRuleActionOptions, updatedRuleActionOptions) + + console.log(ruleActionsDiff) + + return { + routingRuleId: ruleId, + orderRoutingId: props.orderRoutingId, + filtersToRemove: Object.values({ ...filterOptionsDiff.seqToRemove, ...sortOptionsDiff.seqToRemove }), + filtersToUpdate: Object.values({ ...filterOptionsDiff.seqToUpdate, ...sortOptionsDiff.seqToUpdate }) + } + }) + + console.log('rulesDiff', rulesDiff) + + // const inventorySortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + // if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { + // filters[filter.fieldName] = filter + // } + // return filters + // }, {}), inventoryRuleSortOptions.value) + + // const inventoryFilterOptionsDiff = findFilterDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + // if(filter.conditionTypeEnumId === "ENTCT_FILTER") { + // filters[filter.fieldName] = filter + // } + // return filters + // }, {}), inventoryRuleFilterOptions.value) + + // const inventoryFiltersToRemove = Object.values({ ...inventoryFilterOptionsDiff.seqToRemove, ...inventorySortOptionsDiff.seqToRemove }) + // const inventoryFiltersToUpdate = Object.values({ ...inventoryFilterOptionsDiff.seqToUpdate, ...inventorySortOptionsDiff.seqToUpdate }) + + // TODO: call this action only if there is some change in the orderRoutings + // await store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId) + // initializeOrderRoutingOptions(); } diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 64aaeab..a7d6b9e 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -126,7 +126,7 @@ const props = defineProps({ } }) -const routingStatus = JSON.parse(process.env?.VUE_APP_ROUTE_STATUS_ENUMS as string) +const routingStatus = JSON.parse(process.env?.VUE_APP_STATUS_ENUMS as string) const cronExpressions = JSON.parse(process.env?.VUE_APP_CRON_EXPRESSIONS as string) let routingsForReorder = ref([]) let description = ref("") From 160a6bfcb2eca29a98c0ac7de880f73685d86a77 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sun, 28 Jan 2024 09:04:22 +0530 Subject: [PATCH 4/6] Implemented: actions to create and delete inventory rule actions(#24) --- src/services/RoutingService.ts | 20 +++++++- src/store/modules/orderRouting/actions.ts | 48 +++++++++++++++--- src/views/BrokeringQuery.vue | 60 +++++++++++------------ 3 files changed, 89 insertions(+), 39 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 488f8d8..6377977 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -118,6 +118,14 @@ const deleteRuleCondition = async (payload: any): Promise => { }); } +const deleteRuleAction = async (payload: any): Promise => { + return api({ + url: `rules/${payload.routingRuleId}/actions`, + method: "DELETE", + data: payload + }); +} + const fetchRule = async (routingRuleId: string): Promise => { return api({ url: `rules/${routingRuleId}`, @@ -125,6 +133,14 @@ const fetchRule = async (routingRuleId: string): Promise => { }); } +const updateRule = async (payload: any): Promise => { + return api({ + url: `rules/${payload.routingRuleId}`, + method: "POST", + data: payload + }); +} + const scheduleBrokering = async (payload: any): Promise => { return api({ url: `groups/${payload.routingGroupId}/schedule`, @@ -139,6 +155,7 @@ export const OrderRoutingService = { createRoutingRule, createRuleCondition, deleteRoutingFilter, + deleteRuleAction, deleteRuleCondition, fetchOrderRouting, fetchRoutingFilters, @@ -150,5 +167,6 @@ export const OrderRoutingService = { scheduleBrokering, updateOrderRouting, updateRouting, - updateRoutingGroup + updateRoutingGroup, + updateRule } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index d4dff8e..c591175 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -138,7 +138,8 @@ const actions: ActionTree = { }, async createRoutingRule({ commit, state }, payload) { - let routingRules = JSON.parse(JSON.stringify(state.rules)) + const currentRoute = JSON.parse(JSON.stringify(state.currentRoute)) + let routingRules = currentRoute.rules?.length ? currentRoute.rules : [] let routingRuleId = '' try { @@ -158,7 +159,7 @@ const actions: ActionTree = { routingRules = sortSequence(routingRules) } - commit(types.ORDER_ROUTINGS_UPDATED, routingRules) + commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, currentRoute) } } catch(err) { showToast("Failed to create rule") @@ -282,24 +283,42 @@ const actions: ActionTree = { // TODO: check if we can call request in parallel for delete operation let hasAllConditionsDeletedSuccessfully = true; try { - await payload.conditions.forEach(async (condition: any) => { + for(const condition of payload.conditions) { const resp = await OrderRoutingService.deleteRuleCondition({ routingRuleId: payload.routingRuleId, conditionSeqId: condition.conditionSeqId - }); + }) if(hasError(resp) || !resp.data.conditionSeqId) { hasAllConditionsDeletedSuccessfully = false } - }); + } } catch(err) { logger.error(err); } - dispatch("fetchRuleConditions", payload.routingRuleId) - return hasAllConditionsDeletedSuccessfully }, + async deleteRuleActions({ dispatch }, payload) { + // TODO: check if we can call request in parallel for delete operation + let hasAllActionsDeletedSuccessfully = true; + try { + for(const action of payload.actions) { + const resp = await OrderRoutingService.deleteRuleAction({ + routingRuleId: payload.routingRuleId, + actionSeqId: action.actionSeqId + }) + if(hasError(resp) || !resp.data.actionSeqId) { + hasAllActionsDeletedSuccessfully = false + } + } + } catch(err) { + logger.error(err) + } + + return hasAllActionsDeletedSuccessfully + }, + async createRuleConditions({ dispatch }, payload) { let hasAllConditionsCreatedSuccessfully = true; try { @@ -361,6 +380,21 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_RULES_UPDATED, rulesInformation) return JSON.parse(JSON.stringify(rulesInformation[routingRuleId])) + }, + + async updateRule({ dispatch }, payload) { + let routingRuleId = '' + try { + const resp = await OrderRoutingService.updateRule(payload) + + if(!hasError(resp) && resp.data.routingRuleId) { + routingRuleId = resp.data.routingRuleId + } + } catch(err) { + logger.error("Failed to update rule conditions and actions") + } + + return routingRuleId; } } diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 094db0c..9f559c9 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -387,9 +387,10 @@ async function addInventoryRule() { createdDate: DateTime.now().toMillis() } - const resp = await store.dispatch("orderRouting/createRoutingRule", payload) - if(resp.routingRuleId) { - fetchRuleInformation(resp.routingRuleId) + const routingRuleId = await store.dispatch("orderRouting/createRoutingRule", payload) + if(routingRuleId) { + inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"])) + fetchRuleInformation(routingRuleId) } } }) @@ -758,6 +759,7 @@ async function save() { } // Inventory rules diff calculated + // Find order filters diff const routeSortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { filters[filter.fieldName] = filter @@ -774,6 +776,7 @@ async function save() { const filtersToRemove = Object.values({ ...routeFilterOptionsDiff.seqToRemove, ...routeSortOptionsDiff.seqToRemove }) const filtersToUpdate = Object.values({ ...routeFilterOptionsDiff.seqToUpdate, ...routeSortOptionsDiff.seqToUpdate }) + // Diff found for removing and updating filters if(filtersToRemove?.length) { await store.dispatch("orderRouting/deleteRoutingFilters", { filters: filtersToRemove, orderRoutingId: props.orderRoutingId }) @@ -793,10 +796,7 @@ async function save() { } } - const initialInventoryRulesInformation = JSON.parse(JSON.stringify(routingRules.value)) - console.log('initialInventoryRulesInformation', initialInventoryRulesInformation) - console.log('rulesInformation.value', rulesInformation.value) // Whenever we will be having a feature to delete a rule then this logic needs updation const rulesDiff = Object.keys(initialInventoryRulesInformation).map((ruleId: string) => { @@ -804,46 +804,44 @@ async function save() { const updatedRuleSortOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {} const sortOptionsDiff = findSortDiff(previousRuleSortOptions, updatedRuleSortOptions) - console.log('sortOptionsDiff', sortOptionsDiff) - const previousRuleFilterOptions = initialInventoryRulesInformation[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? initialInventoryRulesInformation[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} const updatedRuleFilterOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} const filterOptionsDiff = findFilterDiff(previousRuleFilterOptions, updatedRuleFilterOptions) - console.log('filterOptionsDiff', filterOptionsDiff) - const previousRuleActionOptions = initialInventoryRulesInformation[ruleId]["actions"] ? initialInventoryRulesInformation[ruleId]["actions"] : {} const updatedRuleActionOptions = rulesInformation.value[ruleId]["actions"] ? rulesInformation.value[ruleId]["actions"] : {} const ruleActionsDiff = findActionDiff(previousRuleActionOptions, updatedRuleActionOptions) - console.log(ruleActionsDiff) - return { routingRuleId: ruleId, orderRoutingId: props.orderRoutingId, filtersToRemove: Object.values({ ...filterOptionsDiff.seqToRemove, ...sortOptionsDiff.seqToRemove }), - filtersToUpdate: Object.values({ ...filterOptionsDiff.seqToUpdate, ...sortOptionsDiff.seqToUpdate }) + filtersToUpdate: Object.values({ ...filterOptionsDiff.seqToUpdate, ...sortOptionsDiff.seqToUpdate }), + actionsToRemove: Object.values(ruleActionsDiff.seqToRemove), + actionsToUpdate: Object.values(ruleActionsDiff.seqToUpdate) } }) - console.log('rulesDiff', rulesDiff) - - // const inventorySortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { - // if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { - // filters[filter.fieldName] = filter - // } - // return filters - // }, {}), inventoryRuleSortOptions.value) - - // const inventoryFilterOptionsDiff = findFilterDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { - // if(filter.conditionTypeEnumId === "ENTCT_FILTER") { - // filters[filter.fieldName] = filter - // } - // return filters - // }, {}), inventoryRuleFilterOptions.value) - - // const inventoryFiltersToRemove = Object.values({ ...inventoryFilterOptionsDiff.seqToRemove, ...inventorySortOptionsDiff.seqToRemove }) - // const inventoryFiltersToUpdate = Object.values({ ...inventoryFilterOptionsDiff.seqToUpdate, ...inventorySortOptionsDiff.seqToUpdate }) + for(const key in rulesDiff) { + const rule = rulesDiff[key] + + if(rule.filtersToRemove?.length) { + await store.dispatch("orderRouting/deleteRuleConditions", rule.filtersToRemove) + } + + if(rule.actionsToRemove?.length) { + await store.dispatch("orderRouting/deleteRuleActions", rule.actionsToRemove) + } + + if(rule.filtersToUpdate?.length || rule.actionsToUpdate?.length) { + await store.dispatch("orderRouting/updateRule", { + routingRuleId: rule.routingRuleId, + orderRoutingId: rule.orderRoutingId, + inventoryFilters: rule.filtersToUpdate, + actions: rule.actionsToUpdate + }) + } + } // TODO: call this action only if there is some change in the orderRoutings // await store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId) From 9e706d7bf0f24d34096876f22e50354ccc1161ac Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sun, 28 Jan 2024 20:15:07 +0530 Subject: [PATCH 5/6] Improved: code comments(#24) --- src/views/BrokeringQuery.vue | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index 9f559c9..d654640 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -310,7 +310,7 @@ async function fetchRuleInformation(routingRuleId: string) { rulesInformation.value = JSON.parse(JSON.stringify(routingRules.value)) } - // Using currentRouting["rules"] deep-cloned object here, we will update the change in rules with route changes and not with rules filter changes + // 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]))); @@ -389,6 +389,7 @@ async function addInventoryRule() { const routingRuleId = await store.dispatch("orderRouting/createRoutingRule", payload) if(routingRuleId) { + // TODO: Fix warning of duplicate keys when creating a new rule inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"])) fetchRuleInformation(routingRuleId) } From b2d4098f393479e64739476babd7932a263700f8 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Sun, 28 Jan 2024 20:31:03 +0530 Subject: [PATCH 6/6] Removed: unwanted actions, getters and mutations(#24) --- src/services/RoutingService.ts | 18 --- .../modules/orderRouting/OrderRoutingState.ts | 10 -- src/store/modules/orderRouting/actions.ts | 152 ++++-------------- src/store/modules/orderRouting/getters.ts | 12 -- src/store/modules/orderRouting/index.ts | 6 +- .../modules/orderRouting/mutation-types.ts | 6 +- src/store/modules/orderRouting/mutations.ts | 12 -- 7 files changed, 29 insertions(+), 187 deletions(-) diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index 6377977..3e55e66 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -70,14 +70,6 @@ const fetchRoutingRules = async (payload: any): Promise => { }); } -const fetchRoutingFilters = async (payload: any): Promise => { - return api({ - url: `routings/${payload.orderRoutingId}/orderFilters`, - method: "GET", - query: payload - }); -} - const updateRouting = async (payload: any): Promise => { return api({ url: `routings/${payload.orderRoutingId}`, @@ -94,14 +86,6 @@ const deleteRoutingFilter = async (payload: any): Promise => { }); } -const fetchRuleConditions = async (payload: any): Promise => { - return api({ - url: `rules/${payload.routingRuleId}/inventoryFilters`, - method: "GET", - query: payload - }); -} - const createRuleCondition = async (payload: any): Promise => { return api({ url: `rules/${payload.routingRuleId}/inventoryFilters`, @@ -158,12 +142,10 @@ export const OrderRoutingService = { deleteRuleAction, deleteRuleCondition, fetchOrderRouting, - fetchRoutingFilters, fetchRoutingGroupInformation, fetchRoutingGroups, fetchRoutingRules, fetchRule, - fetchRuleConditions, scheduleBrokering, updateOrderRouting, updateRouting, diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 5a550de..4cc7024 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -1,16 +1,6 @@ -import { Group, RouteFilter } from "@/types"; - export default interface OrderRoutingState { groups: Array; // runs - routes: Array; rules: any; currentGroup: any; currentRoute: any; - currentRouteFilters: { - [key: string]: { // conditionTypeEnumId as key - [key: string]: RouteFilter // enumCode/fieldName as key - } - }; - ruleConditions: {}; - ruleActions: {} } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index c591175..816f102 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -5,7 +5,6 @@ import { OrderRoutingService } from "@/services/RoutingService" import { hasError, showToast, sortSequence } from "@/utils" import * as types from './mutation-types' import logger from "@/logger" -import { RouteFilter } from "@/types" import { DateTime } from "luxon" const actions: ActionTree = { @@ -74,6 +73,10 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) }, + async setCurrentGroup({ commit }, currentGroup) { + commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) + }, + async createOrderRouting({ dispatch, state }, payload) { const currentGroup = JSON.parse(JSON.stringify(state.currentGroup)) let orderRoutingId = '' @@ -111,10 +114,6 @@ const actions: ActionTree = { return orderRoutingId; }, - async setCurrentGroup({ commit }, currentGroup) { - commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) - }, - async fetchCurrentOrderRouting({ dispatch }, orderRoutingId) { let currentRoute = {} @@ -137,76 +136,6 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload) }, - async createRoutingRule({ commit, state }, payload) { - const currentRoute = JSON.parse(JSON.stringify(state.currentRoute)) - let routingRules = currentRoute.rules?.length ? currentRoute.rules : [] - let routingRuleId = '' - - try { - const resp = await OrderRoutingService.createRoutingRule(payload) - - if(!hasError(resp) && resp?.data.routingRuleId) { - routingRuleId = resp.data.routingRuleId - // Use the routingRuleId received in response, as we are passing empty routingRuleId in request - routingRules.push({ - ...payload, - routingRuleId - }) - showToast('New Inventory Rule Created') - - // Sort the routings and update the state only on success - if(routingRules.length) { - routingRules = sortSequence(routingRules) - } - - commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, currentRoute) - } - } catch(err) { - showToast("Failed to create rule") - logger.error('err', err) - } - - return routingRuleId; - }, - - async fetchRoutingFilters({ commit }, orderRoutingId) { - let routingFilters = {} as any; - // filter groups on the basis of productStoreId - const payload = { - orderRoutingId - } - - try { - const resp = await OrderRoutingService.fetchRoutingFilters(payload); - - if(!hasError(resp) && resp.data.length) { - routingFilters = resp.data.reduce((filters: any, filter: RouteFilter) => { - if(filters[filter.conditionTypeEnumId]) { - filters[filter.conditionTypeEnumId][filter.fieldName] = filter - } else { - filters[filter.conditionTypeEnumId] = { - [filter.fieldName]: filter - } - } - return filters - }, {}) - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } - - const sortEnum = "ENTCT_SORT_BY" - - // As we only need to add support of reordering for sortBy filter - if(routingFilters[sortEnum]?.length) { - routingFilters[sortEnum] = sortSequence(routingFilters[sortEnum]) - } - - commit(types.ORDER_ROUTING_FILTERS_UPDATED, routingFilters) - }, - async deleteRoutingFilters({ dispatch }, payload) { let hasAllFiltersDeletedSuccessfully = true; try { @@ -241,42 +170,36 @@ const actions: ActionTree = { return orderRoutingId }, - async fetchRuleConditions({ commit }, routingRuleId) { - let ruleConditions = {} as any; - // filter groups on the basis of productStoreId - const payload = { - routingRuleId - } + async createRoutingRule({ commit, state }, payload) { + const currentRoute = JSON.parse(JSON.stringify(state.currentRoute)) + let routingRules = currentRoute.rules?.length ? currentRoute.rules : [] + let routingRuleId = '' try { - const resp = await OrderRoutingService.fetchRuleConditions(payload); + const resp = await OrderRoutingService.createRoutingRule(payload) - if(!hasError(resp) && resp.data.length) { - ruleConditions = resp.data.reduce((conditions: any, condition: any) => { - if(conditions[condition.conditionTypeEnumId]) { - conditions[condition.conditionTypeEnumId][condition.fieldName] = condition - } else { - conditions[condition.conditionTypeEnumId] = { - [condition.fieldName]: condition - } - } - return conditions - }, {}) - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } + if(!hasError(resp) && resp?.data.routingRuleId) { + routingRuleId = resp.data.routingRuleId + // Use the routingRuleId received in response, as we are passing empty routingRuleId in request + routingRules.push({ + ...payload, + routingRuleId + }) + showToast('New Inventory Rule Created') - const sortEnum = "ENTCT_SORT_BY" + // Sort the routings and update the state only on success + if(routingRules.length) { + routingRules = sortSequence(routingRules) + } - // As we only need to add support of reordering for sortBy filter - if(ruleConditions[sortEnum]?.length) { - ruleConditions[sortEnum] = sortSequence(ruleConditions[sortEnum]) + commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, currentRoute) + } + } catch(err) { + showToast("Failed to create rule") + logger.error('err', err) } - commit(types.ORDER_ROUTING_RULE_CONDITIONS_UPDATED, ruleConditions) + return routingRuleId; }, async deleteRuleConditions({ dispatch }, payload) { @@ -319,27 +242,6 @@ const actions: ActionTree = { return hasAllActionsDeletedSuccessfully }, - async createRuleConditions({ dispatch }, payload) { - let hasAllConditionsCreatedSuccessfully = true; - try { - await payload.conditions.forEach(async (condition: any) => { - const resp = await OrderRoutingService.createRuleCondition({ - routingRuleId: payload.routingRuleId, - ...condition - }); - if(!hasError(resp) || !resp.data.conditionSeqId) { - hasAllConditionsCreatedSuccessfully = false - } - }); - } catch(err) { - logger.error(err); - } - - // TODO: check if we can call the action only once after all the operations are success - dispatch("fetchRuleConditions", payload.routingRuleId) - return hasAllConditionsCreatedSuccessfully - }, - async fetchInventoryRuleInformation({ commit, state }, routingRuleId) { const rulesInformation = JSON.parse(JSON.stringify(state.rules)) diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index 7aeb909..6b6e181 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -6,9 +6,6 @@ const getters: GetterTree = { getRoutingGroups(state) { return state.groups }, - getRoutingRules(state) { - return state.currentGroup["rules"] ? JSON.parse(JSON.stringify(state.currentGroup["rules"])) : [] - }, getRulesInformation(state) { return state.rules }, @@ -17,15 +14,6 @@ const getters: GetterTree = { }, getCurrentOrderRouting(state) { return JSON.parse(JSON.stringify(state.currentRoute)) - }, - getCurrentRouteFilters(state) { - return state.currentRouteFilters - }, - getRuleConditions(state) { - return JSON.parse(JSON.stringify(state.ruleConditions)) - }, - getRuleActions(state) { - return JSON.parse(JSON.stringify(state.ruleActions)) } } diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index 5346aeb..efa0196 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -10,13 +10,9 @@ const orderRoutingModule: Module = { namespaced: true, state: { groups: [], - routes: [], rules: {}, currentGroup: {}, - currentRoute: {}, - currentRouteFilters: {}, - ruleConditions: {}, - ruleActions: {} + currentRoute: {} }, getters, actions, diff --git a/src/store/modules/orderRouting/mutation-types.ts b/src/store/modules/orderRouting/mutation-types.ts index 447da3d..9674d94 100644 --- a/src/store/modules/orderRouting/mutation-types.ts +++ b/src/store/modules/orderRouting/mutation-types.ts @@ -1,9 +1,5 @@ export const SN_ORDER_ROUTING = "orderRouting" export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED" -export const ORDER_ROUTINGS_UPDATED = SN_ORDER_ROUTING + "/ROUTES_UPDATED" 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_FILTERS_UPDATED = SN_ORDER_ROUTING + "/FILTERS_UPDATED" -export const ORDER_ROUTING_RULE_CONDITIONS_UPDATED = SN_ORDER_ROUTING + "/RULE_CONDITIONS_UPDATED" -export const ORDER_ROUTING_RULE_ACTIONS_UPDATED = SN_ORDER_ROUTING + "/RULE_ACTIONS_UPDATED" \ No newline at end of file +export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED" \ No newline at end of file diff --git a/src/store/modules/orderRouting/mutations.ts b/src/store/modules/orderRouting/mutations.ts index d0d58eb..cef33f3 100644 --- a/src/store/modules/orderRouting/mutations.ts +++ b/src/store/modules/orderRouting/mutations.ts @@ -6,9 +6,6 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_GROUPS_UPDATED](state, payload) { state.groups = payload }, - [types.ORDER_ROUTINGS_UPDATED](state, payload) { - state.routes = payload - }, [types.ORDER_ROUTING_RULES_UPDATED](state, payload) { state.rules = payload }, @@ -18,14 +15,5 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, payload) { state.currentRoute = payload }, - [types.ORDER_ROUTING_FILTERS_UPDATED](state, payload) { - state.currentRouteFilters = payload - }, - [types.ORDER_ROUTING_RULE_CONDITIONS_UPDATED](state, payload) { - state.ruleConditions = payload - }, - [types.ORDER_ROUTING_RULE_ACTIONS_UPDATED](state, payload) { - state.ruleActions = payload - } } export default mutations; \ No newline at end of file