Skip to content

Commit

Permalink
Merge pull request #216 from amansinghbais/#215
Browse files Browse the repository at this point in the history
Improved: fetching picklist items using pagination, added filterByDate check while fetching picklists (#215)
  • Loading branch information
ymaheshwari1 committed Jul 18, 2024
2 parents aa38444 + 8e81712 commit c9907cd
Showing 1 changed file with 47 additions and 34 deletions.
81 changes: 47 additions & 34 deletions src/store/modules/picklist/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const actions: ActionTree<PicklistState, RootState> = {
"viewIndex": payload.viewIndex,
"fieldList": ["picklistId", "picklistDate", "statusId", "partyId"],
"entityName": "PicklistAndRole",
"noConditionFind": "Y"
"noConditionFind": "Y",
"filterByDate": "Y"
} as any

if (state.filters.showMyPicklists) params.inputFields.partyId = this.state.user.current.partyId;
Expand Down Expand Up @@ -62,7 +63,8 @@ const actions: ActionTree<PicklistState, RootState> = {
"viewSize": 10,
"fieldList": ["picklistId", "picklistDate", "statusId", "partyId"],
"entityName": "PicklistAndRole",
"noConditionFind": "Y"
"noConditionFind": "Y",
"filterByDate": "Y"
} as any

if (state.filters.showMyPicklists) params.inputFields.partyId = this.state.user.current.partyId
Expand Down Expand Up @@ -95,45 +97,56 @@ const actions: ActionTree<PicklistState, RootState> = {
return current
}

let resp;
const params = {
"inputFields": {
"picklistId": payload.id,
},
"fieldList": ["productId", "productName", "picklistId", "locationSeqId", "picklistBinId", "statusId"],
"entityName": "PicklistItemsView",
"noConditionFind": "Y"
}
let resp, isScrollable = true, viewIndex = 0, total = 0;
let pickingItemList = [] as any;

try {
resp = await PicklistService.getPicklist(params);
if (!hasError(resp) && resp.data.count) {
const pickingItemList = resp.data.docs.map((picklist: any, index: any) => ({ id: index, ...picklist, isChecked: false }))

current = { picklistId: payload.id, statusId: pickingItemList[0].statusId, pickingItemList }
commit(types.PICKLIST_CURRENT_UPDATED, current)

let productIds: any = new Set(
pickingItemList.map((picklist: any) => {
return picklist.productId
})
);

productIds = [...productIds]
if (productIds.length) {
this.dispatch('product/fetchProducts', { productIds })
while(isScrollable) {
resp = await PicklistService.getPicklist({
"inputFields": {
"picklistId": payload.id,
"itemStatusId": "PICKITEM_CANCELLED",
"itemStatusId_op": "notEqual"
},
"fieldList": ["productId", "productName", "picklistId", "locationSeqId", "picklistBinId", "statusId"],
"entityName": "PicklistItemsView",
"noConditionFind": "Y",
"viewSize": 200,
viewIndex
});

if (!hasError(resp) && resp.data.count) {
pickingItemList = pickingItemList.concat(resp.data.docs)
viewIndex++;
total = resp.data.count;

if(pickingItemList.length >= total) isScrollable = false;
} else {
throw resp.data;
}

return current;
} else {
showToast(translate('Something went wrong'));
console.error("error", resp.data);
return Promise.reject(new Error(resp.data));
}
} catch (err: any) {
showToast(translate('Something went wrong'));
console.error("error", err);
return Promise.reject(new Error(err))
return [];
}

if(pickingItemList.length) {
pickingItemList = pickingItemList.map((picklist: any, index: any) => ({ id: index, ...picklist, isChecked: false }))

current = { picklistId: payload.id, statusId: pickingItemList[0].statusId, pickingItemList }
commit(types.PICKLIST_CURRENT_UPDATED, current)

let productIds: any = new Set(
pickingItemList.map((picklist: any) => {
return picklist.productId
})
);

productIds = [...productIds]
if (productIds.length) {
this.dispatch('product/fetchProducts', { productIds })
}
}
},

Expand Down

0 comments on commit c9907cd

Please sign in to comment.