From 67e2e7c3baa058ca4b268a355a1ee2c4e2413f27 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 26 Jan 2024 22:11:10 +0530 Subject: [PATCH] Fixed: case when updating routing multiple times without refresh, removed check for empty description, and deep cloning routingd before updating state to remove the reference after update --- src/components/ArchivedRoutingModal.vue | 2 +- src/views/BrokeringRoute.vue | 22 ++++++++++------------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/ArchivedRoutingModal.vue b/src/components/ArchivedRoutingModal.vue index 2731943..9b36b97 100644 --- a/src/components/ArchivedRoutingModal.vue +++ b/src/components/ArchivedRoutingModal.vue @@ -51,7 +51,7 @@ let routings = ref(props.archivedRoutings) as any let routingsToUpdate = ref([]) as any function closeModal() { - modalController.dismiss({ dismissed: true, routings: routingsToUpdate.value.concat(routings.value) }); + modalController.dismiss({ dismissed: true, routings: routingsToUpdate.value.length ? routingsToUpdate.value.concat(routings.value) : [] }); } async function updateOrderRouting(routing: Route, fieldToUpdate: string, value: string) { diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 17fb80a..64aaeab 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -115,7 +115,7 @@ import ArchivedRoutingModal from "@/components/ArchivedRoutingModal.vue" import { OrderRoutingService } from "@/services/RoutingService"; import logger from "@/logger"; import { DateTime } from "luxon"; -import { hasError, showToast, sortSequence } from "@/utils"; +import { hasError, getTime, showToast, sortSequence } from "@/utils"; const router = useRouter(); const store = useStore(); @@ -129,7 +129,7 @@ const props = defineProps({ const routingStatus = JSON.parse(process.env?.VUE_APP_ROUTE_STATUS_ENUMS as string) const cronExpressions = JSON.parse(process.env?.VUE_APP_CRON_EXPRESSIONS as string) let routingsForReorder = ref([]) -let description = ref('') +let description = ref("") let isDescUpdating = ref(false) let hasUnsavedChanges = ref(false) @@ -143,10 +143,12 @@ onIonViewWillEnter(async () => { await store.dispatch("orderRouting/fetchCurrentRoutingGroup", props.routingGroupId) job.value = currentRoutingGroup.value["schedule"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["schedule"] : {} - orderRoutings.value = currentRoutingGroup.value["routings"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"] : {} - description.value = currentRoutingGroup.value["description"] ? currentRoutingGroup.value["description"] : "No description available" + orderRoutings.value = currentRoutingGroup.value["routings"] ? JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"] : [] + description.value = currentRoutingGroup.value["description"] ? currentRoutingGroup.value["description"] : "" - initializeOrderRoutings(); + if(orderRoutings.value.length) { + initializeOrderRoutings(); + } }) onBeforeRouteLeave(async (to) => { @@ -183,10 +185,6 @@ function updateCronExpression(event: CustomEvent) { job.value.cronExpression = event.detail.value } -function getTime(time: any) { - return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : '-'; -} - function initializeOrderRoutings() { routingsForReorder.value = JSON.parse(JSON.stringify(getActiveAndDraftOrderRoutings())) } @@ -271,7 +269,7 @@ async function createOrderRoute() { // update the routing order for reordering and the cloned updated routings again if(orderRoutingId) { - orderRoutings.value = JSON.parse(JSON.stringify(currentRoutingGroup.value["routings"])) + orderRoutings.value = JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"] initializeOrderRoutings(); } } @@ -290,7 +288,7 @@ function getArchivedOrderRoutings() { async function updateGroupDescription() { // Do not update description, if the desc is unchanged, and we do not have routingGroupId, and description is left empty - if(description.value && props.routingGroupId && currentRoutingGroup.value.description !== description.value) { + if(props.routingGroupId && currentRoutingGroup.value.description !== description.value) { const routingGroupId = await updateRoutingGroup({ routingGroupId: props.routingGroupId, productStoreId: currentEComStore.value.productStoreId, description: description.value }) if(routingGroupId) { await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, description: description.value }) @@ -396,7 +394,7 @@ async function saveRoutingGroup() { const routingGroupId = await updateRoutingGroup(payload) if(routingGroupId) { hasUnsavedChanges.value = false - await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, routings: orderRoutings.value }) + await store.dispatch("orderRouting/setCurrentGroup", { ...currentRoutingGroup.value, routings: JSON.parse(JSON.stringify(orderRoutings.value)) }) } }