Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved: fetching closed cycle counts total on closed page in admin screen (#622) #623

Merged
merged 4 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/services/CountService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ const fetchCycleCountUploadedFileData = async (payload: any): Promise <any> => {
});
}

const fetchCycleCountsTotal = async (payload: any): Promise<any> => {
return api({
url: "cycleCounts/count",
method: "get",
params: payload
})
}

export const CountService = {
acceptItem,
addProductToCount,
Expand All @@ -168,6 +176,7 @@ export const CountService = {
fetchCycleCountStats,
fetchCycleCounts,
fetchCycleCountItems,
fetchCycleCountsTotal,
recountItems,
updateCount,
updateCycleCount,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/count/CountState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export default interface CountState {
cycleCountImportSystemMessages: Array<any>;
defaultRecountUpdateBehaviour: String;
cachedUnmatchProducts: any;
closedCycleCountsTotal: any;
}
32 changes: 32 additions & 0 deletions src/store/modules/count/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@
commit(types.COUNT_LIST_UPDATED, { counts, total , isScrollable })
},

async fetchClosedCycleCountsTotal({ commit, state }) {
const params = {
statusId: "INV_COUNT_COMPLETED"
} as any;
// TODO: Currently, the search functionality works only on the count name. Once the API supports searching across
// multiple fields, we should include the count ID in the search parameters.
if(state.query.queryString.length) {
params["countImportName"] = state.query.queryString
params["countImportName_op"] = "contains"
}

if(state.query.facilityIds.length) {
params["facilityId"] = state.query.facilityIds.join(",")
params["facilityId_op"] = "in"
}

let total = "";
try {
const resp = await CountService.fetchCycleCountsTotal(params);
if(!hasError(resp)) {
total = resp.data.count;
} else {
throw resp;
}
} catch(err) {
logger.error(err)
}

commit(types.COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED, total)
},

async fetchCycleCountStats({ commit, state }, inventoryCountImportIds) {
const cachedProducts = JSON.parse(JSON.stringify(state.cachedUnmatchProducts))
try {
Expand Down Expand Up @@ -133,6 +164,7 @@
statusId = "INV_COUNT_COMPLETED"
}
dispatch("fetchCycleCounts", { pageSize: process.env.VUE_APP_VIEW_SIZE, pageIndex: 0, statusId })
if(payload.key === "facilityIds") dispatch("fetchClosedCycleCountsTotal")
},

async updateQueryString({ commit }, payload) {
Expand Down Expand Up @@ -212,7 +244,7 @@
commit(types.COUNT_ITEMS_UPDATED, [])
},

async fetchCycleCountImportSystemMessages({commit} ,payload) {

Check warning on line 247 in src/store/modules/count/actions.ts

View workflow job for this annotation

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

'payload' is defined but never used

Check warning on line 247 in src/store/modules/count/actions.ts

View workflow job for this annotation

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

'payload' is defined but never used
let systemMessages;
try {
const twentyFourHoursEarlier = DateTime.now().minus({ hours: 24 });
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/count/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ const getters: GetterTree<CountState, RootState> = {
},
getCachedUnmatchProducts: (state) => (id: string) => {
return state.cachedUnmatchProducts[id]
},
getClosedCycleCountsTotal(state) {
return state.closedCycleCountsTotal
}
};

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/count/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ const countModule: Module<CountState, RootState> = {
},
cycleCountItems: {},
defaultRecountUpdateBehaviour: "add",
cachedUnmatchProducts: {}
cachedUnmatchProducts: {},
closedCycleCountsTotal: ""
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/count/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export const COUNT_STATS_UPDATED = SN_COUNT + "/STATS_UPDATED"
export const COUNT_UPDATED = SN_COUNT + '/UPDATED'
export const COUNT_ITEMS_UPDATED = SN_COUNT + '/ITEMS_UPDATED'
export const COUNT_IMPORT_SYSTEM_MESSAGES_UPDATED = SN_COUNT + 'IMPORT_SYSTEM_MESSAGES_UPDATED'
export const COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED = SN_COUNT + 'CACHED_UNMATCHED_PRODUCTS_UPDATED'
export const COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED = SN_COUNT + 'CACHED_UNMATCHED_PRODUCTS_UPDATED'
export const COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED = SN_COUNT + 'CLOSED_CYCLE_COUNTS_TOTAL_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/count/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ const mutations: MutationTree <CountState> = {
},
[types.COUNT_CACHED_UNMATCH_PRODUCTS_UPDATED] (state, payload) {
state.cachedUnmatchProducts = payload
},
[types.COUNT_CLOSED_CYCLE_COUNTS_TOTAL_UPDATED] (state, payload) {
state.closedCycleCountsTotal = payload
}

}
Expand Down
7 changes: 4 additions & 3 deletions src/views/Closed.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<ion-item lines="full">
<ion-icon slot="start" :icon="listOutline"/>
<ion-label>{{ translate("Counts closed") }}</ion-label>
<ion-label slot="end">{{ cycleCounts.length }}</ion-label>
<ion-label slot="end">{{ closedCycleCountsTotal ? closedCycleCountsTotal : "-" }}</ion-label>
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
</ion-item>
<ion-item lines="full">
<ion-icon slot="start" :icon="thermometerOutline"/>
Expand Down Expand Up @@ -115,13 +115,14 @@ const cycleCounts = computed(() => store.getters["count/getCounts"])
const cycleCountStats = computed(() => (id: string) => store.getters["count/getCycleCountStats"](id))
const isScrollable = computed(() => store.getters["count/isCycleCountListScrollable"])
const query = computed(() => store.getters["count/getQuery"])
const closedCycleCountsTotal = computed(() => store.getters["count/getClosedCycleCountsTotal"])

const isScrollingEnabled = ref(false);
const contentRef = ref({}) as any
const infiniteScrollRef = ref({}) as any

onIonViewWillEnter(async () => {
await fetchClosedCycleCounts()
await Promise.allSettled([fetchClosedCycleCounts(), store.dispatch("count/fetchClosedCycleCountsTotal")])
})

onIonViewWillLeave(async () => {
Expand All @@ -142,7 +143,7 @@ function enableScrolling() {

async function updateQueryString(key: string, value: any) {
await store.dispatch("count/updateQueryString", { key, value })
fetchClosedCycleCounts();
await Promise.allSettled([fetchClosedCycleCounts(), store.dispatch("count/fetchClosedCycleCountsTotal")])
}

async function loadMoreCycleCounts(event: any) {
Expand Down
Loading