Skip to content

Commit

Permalink
Improved: inventory channel groups fetching logic to fetch when facil…
Browse files Browse the repository at this point in the history
…ity data is retrieved from cache (#244)
  • Loading branch information
amansinghbais committed Jan 18, 2024
1 parent 24390d1 commit c047579
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,20 @@ const actions: ActionTree<FacilityState, RootState> = {
commit(types.FACILITY_CURRENT_UPDATED, facility)
},

async fetchCurrentFacility({ commit, dispatch, state }, payload) {
async fetchCurrentFacility({ commit, dispatch, rootGetters, state }, payload) {
// checking that if the list contains basic information for facility then not fetching the same information again
const cachedFacilities = JSON.parse(JSON.stringify(state.facilities.list))
const current = cachedFacilities.find((facility: any) => facility.facilityId === payload.facilityId)
if(current?.facilityId && !payload.skipState) {
// As inventory channels are fetched while fetching additional facility info
// But here we already have additional facility info, so just getting and adding inventory groups to current.
const inventoryGroups = rootGetters['util/getInventoryGroups'];
inventoryGroups.forEach((group: any) => {
const isChecked = (current.facilityGroupInfo?.some((facilityGroup: any) => facilityGroup?.facilityGroupId === group.facilityGroupId))
group.isChecked = isChecked ? isChecked : false;
});
current.inventoryGroups = inventoryGroups;
commit(types.FACILITY_CURRENT_UPDATED, current);
await dispatch('fetchFacilityAdditionalInformation', payload);
return;
}

Expand Down

0 comments on commit c047579

Please sign in to comment.