From 93e1559e6e5c40f6363c5e48f7bad5c6c9c3e541 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 14 Jan 2025 15:08:46 +0530 Subject: [PATCH 1/3] Implemented: sorting on the cycle count items based on the parentProductName (#602) --- src/store/modules/count/actions.ts | 3 +++ src/views/AssignedDetail.vue | 2 ++ src/views/DraftDetail.vue | 2 ++ src/views/PendingReviewDetail.vue | 2 ++ 4 files changed, 9 insertions(+) diff --git a/src/store/modules/count/actions.ts b/src/store/modules/count/actions.ts index b57c8b15..4dd61124 100644 --- a/src/store/modules/count/actions.ts +++ b/src/store/modules/count/actions.ts @@ -196,6 +196,9 @@ const actions: ActionTree = { } catch(err: any) { logger.error(err) } + + items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + this.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) if(cachedProducts?.length) items = items.concat(cachedProducts) commit(types.COUNT_ITEMS_UPDATED, { itemList: items }) diff --git a/src/views/AssignedDetail.vue b/src/views/AssignedDetail.vue index d8451d53..a7cbcc3d 100644 --- a/src/views/AssignedDetail.vue +++ b/src/views/AssignedDetail.vue @@ -241,6 +241,8 @@ async function fetchCountItems() { logger.error(err) } + items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + currentCycleCount.value["items"] = items store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) } diff --git a/src/views/DraftDetail.vue b/src/views/DraftDetail.vue index dd24cf03..8a507f6b 100644 --- a/src/views/DraftDetail.vue +++ b/src/views/DraftDetail.vue @@ -285,6 +285,8 @@ async function fetchCountItems() { logger.error(err) } + items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + currentCycleCount.value["items"] = items store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) } diff --git a/src/views/PendingReviewDetail.vue b/src/views/PendingReviewDetail.vue index 88d6dfd9..72c561a9 100644 --- a/src/views/PendingReviewDetail.vue +++ b/src/views/PendingReviewDetail.vue @@ -284,6 +284,8 @@ async function fetchCountItems() { logger.error(err) } + items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + currentCycleCount.value["items"] = items.map((item: any) => ({ ...item, isChecked: false })) store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) } From 109942c38f56fb9381767cba4a68ba5731d881d4 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 14 Jan 2025 15:37:11 +0530 Subject: [PATCH 2/3] Improved: made util for sorting list and not sorting the hard count (#602) --- src/store/modules/count/actions.ts | 4 ++-- src/utils/index.ts | 12 +++++++++++- src/views/AssignedDetail.vue | 4 ++-- src/views/CountDetail.vue | 2 +- src/views/DraftDetail.vue | 4 ++-- src/views/HardCountDetail.vue | 2 +- src/views/PendingReviewDetail.vue | 4 ++-- 7 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/store/modules/count/actions.ts b/src/store/modules/count/actions.ts index 4dd61124..52fca270 100644 --- a/src/store/modules/count/actions.ts +++ b/src/store/modules/count/actions.ts @@ -3,7 +3,7 @@ import RootState from "@/store/RootState" import CountState from "./CountState" import * as types from "./mutation-types" import { CountService } from "@/services/CountService" -import { hasError, showToast } from "@/utils" +import { hasError, showToast, sortListByField } from "@/utils" import { translate } from "@/i18n" import router from "@/router" import logger from "@/logger"; @@ -197,7 +197,7 @@ const actions: ActionTree = { logger.error(err) } - items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + if(payload.isSortingRequired) items = sortListByField(items, "parentProductName"); this.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) if(cachedProducts?.length) items = items.concat(cachedProducts) diff --git a/src/utils/index.ts b/src/utils/index.ts index 33e1b686..38598c52 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -168,4 +168,14 @@ const downloadCsv = (csv: any, fileName: any) => { return blob; }; -export { downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv } +function sortListByField(list: any, field = "parentProductName") { + return list.sort((a: any, b: any) => { + if (!a[field] && b[field]) return 1; // If 'item1' has no field, it goes after 'item2' + if (a[field] && !b[field]) return -1; // If 'item2' has no field, it goes after 'item1' + if (a[field] < b[field]) return -1; // Normal alphabetical sorting + if (a[field] > b[field]) return 1; // Normal alphabetical sorting + return 0; // If fields are equal + }); +} + +export { downloadCsv, jsonToCsv, showToast, hasError, handleDateTimeInput, getCycleCountStats, getDateTime, getDateWithOrdinalSuffix, getDerivedStatusForCount, getFacilityName, getPartyName, getProductIdentificationValue, timeFromNow, parseCsv, sortListByField } diff --git a/src/views/AssignedDetail.vue b/src/views/AssignedDetail.vue index a7cbcc3d..e4715687 100644 --- a/src/views/AssignedDetail.vue +++ b/src/views/AssignedDetail.vue @@ -146,7 +146,7 @@ import AssignedCountPopover from "@/components/AssignedCountPopover.vue" import store from "@/store" import logger from "@/logger" import { CountService } from "@/services/CountService" -import { hasError, showToast, getDateWithOrdinalSuffix, getDateTime, getFacilityName, getPartyName, getProductIdentificationValue } from "@/utils" +import { hasError, showToast, getDateWithOrdinalSuffix, getDateTime, getFacilityName, getPartyName, getProductIdentificationValue, sortListByField } from "@/utils" import emitter from '@/event-bus'; import AddProductModal from "@/components/AddProductModal.vue" import router from "@/router"; @@ -241,7 +241,7 @@ async function fetchCountItems() { logger.error(err) } - items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + items = sortListByField(items, "parentProductName"); currentCycleCount.value["items"] = items store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index 19bcd391..e6c8c81d 100644 --- a/src/views/CountDetail.vue +++ b/src/views/CountDetail.vue @@ -297,7 +297,7 @@ let isScanningInProgress = ref(false); onIonViewDidEnter(async() => { emitter.emit("presentLoader"); - await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id })]) + await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: false })]) selectedSegment.value = 'all'; queryString.value = ''; previousItem = itemsList.value[0] diff --git a/src/views/DraftDetail.vue b/src/views/DraftDetail.vue index 8a507f6b..64504290 100644 --- a/src/views/DraftDetail.vue +++ b/src/views/DraftDetail.vue @@ -161,7 +161,7 @@ import { calendarNumberOutline, checkmarkCircle, businessOutline, addCircleOutli import { IonBackButton, IonButton, IonChip, IonContent, IonDatetime, IonFab, IonFabButton, IonHeader, IonIcon, IonInput, IonItem, IonLabel, IonList, IonModal, IonPage, IonSpinner, IonThumbnail, IonTitle, IonToolbar, modalController, onIonViewDidEnter, onIonViewWillEnter} from "@ionic/vue"; import { CountService } from "@/services/CountService" import { defineProps, ref, nextTick, computed, watch } from "vue" -import { hasError, getDateTime, getDateWithOrdinalSuffix, handleDateTimeInput, getFacilityName, getProductIdentificationValue, showToast, parseCsv } from "@/utils"; +import { hasError, getDateTime, getDateWithOrdinalSuffix, handleDateTimeInput, getFacilityName, getProductIdentificationValue, showToast, parseCsv, sortListByField } from "@/utils"; import emitter from "@/event-bus" import logger from "@/logger" import { DateTime } from "luxon" @@ -285,7 +285,7 @@ async function fetchCountItems() { logger.error(err) } - items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + items = sortListByField(items, "parentProductName"); currentCycleCount.value["items"] = items store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index a0e8d451..726d2079 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -254,7 +254,7 @@ let isScanningInProgress = ref(false); onIonViewDidEnter(async() => { emitter.emit("presentLoader"); - await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id })]) + await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: true })]) previousItem = itemsList.value[0]; await store.dispatch("product/currentProduct", itemsList.value?.length ? itemsList.value[0] : {}) barcodeInputRef.value?.$el?.setFocus(); diff --git a/src/views/PendingReviewDetail.vue b/src/views/PendingReviewDetail.vue index 72c561a9..49859350 100644 --- a/src/views/PendingReviewDetail.vue +++ b/src/views/PendingReviewDetail.vue @@ -193,7 +193,7 @@ import { computed, defineProps, nextTick, ref } from "vue"; import store from "@/store" import { CountService } from "@/services/CountService" import emitter from '@/event-bus'; -import { showToast, getDateWithOrdinalSuffix, hasError, getFacilityName, getPartyName, timeFromNow, getProductIdentificationValue, getDateTime } from "@/utils" +import { showToast, getDateWithOrdinalSuffix, hasError, getFacilityName, getPartyName, timeFromNow, getProductIdentificationValue, getDateTime, sortListByField } from "@/utils" import logger from "@/logger"; import AddProductModal from "@/components/AddProductModal.vue"; import router from "@/router"; @@ -284,7 +284,7 @@ async function fetchCountItems() { logger.error(err) } - items = items.sort((item1: any, item2: any) => (item1.parentProductName < item2.parentProductName ? -1 : item1.parentProductName > item2.parentProductName ? 1 : 0)); + items = sortListByField(items, "parentProductName"); currentCycleCount.value["items"] = items.map((item: any) => ({ ...item, isChecked: false })) store.dispatch("product/fetchProducts", { productIds: [...new Set(items.map((item: any) => item.productId))] }) From bc705093d7ab65c6667beb08eeb516557f8dbae5 Mon Sep 17 00:00:00 2001 From: amansinghbais Date: Tue, 14 Jan 2025 16:54:50 +0530 Subject: [PATCH 3/3] Fixed: passed argument while fetching items for sorting (#602) --- src/views/CountDetail.vue | 2 +- src/views/HardCountDetail.vue | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/CountDetail.vue b/src/views/CountDetail.vue index e6c8c81d..0d2cf458 100644 --- a/src/views/CountDetail.vue +++ b/src/views/CountDetail.vue @@ -297,7 +297,7 @@ let isScanningInProgress = ref(false); onIonViewDidEnter(async() => { emitter.emit("presentLoader"); - await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: false })]) + await Promise.allSettled([await fetchCycleCount(), store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: true })]) selectedSegment.value = 'all'; queryString.value = ''; previousItem = itemsList.value[0] diff --git a/src/views/HardCountDetail.vue b/src/views/HardCountDetail.vue index 726d2079..867bf0ab 100644 --- a/src/views/HardCountDetail.vue +++ b/src/views/HardCountDetail.vue @@ -254,7 +254,7 @@ let isScanningInProgress = ref(false); onIonViewDidEnter(async() => { emitter.emit("presentLoader"); - await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: true })]) + await Promise.allSettled([fetchCycleCount(), await store.dispatch("count/fetchCycleCountItems", { inventoryCountImportId : props?.id, isSortingRequired: false })]) previousItem = itemsList.value[0]; await store.dispatch("product/currentProduct", itemsList.value?.length ? itemsList.value[0] : {}) barcodeInputRef.value?.$el?.setFocus();