From ae8880076e02df06dc2fd5baf6e1bc3950c8a70b Mon Sep 17 00:00:00 2001 From: shashwatbangar Date: Wed, 23 Nov 2022 18:19:59 +0530 Subject: [PATCH 1/7] Fixed: Jobs repeatation in moreJobs sections in all pages(#2vjxdha-n) --- src/components/MoreJobs.vue | 2 +- src/store/modules/job/JobState.ts | 10 ---- src/store/modules/job/actions.ts | 65 +------------------------ src/store/modules/job/getters.ts | 18 +++---- src/store/modules/job/index.ts | 10 ---- src/store/modules/job/mutation-types.ts | 1 - src/store/modules/job/mutations.ts | 6 --- src/views/Inventory.vue | 14 ++---- src/views/Orders.vue | 15 ++---- src/views/PreOrder.vue | 16 ++---- src/views/Product.vue | 14 ++---- 11 files changed, 28 insertions(+), 143 deletions(-) diff --git a/src/components/MoreJobs.vue b/src/components/MoreJobs.vue index 7ec900c0..e04c9d2d 100644 --- a/src/components/MoreJobs.vue +++ b/src/components/MoreJobs.vue @@ -5,7 +5,7 @@ - {{ job.jobName }} + {{ job.enumName || job.jobName }} {{ job.statusId === "SERVICE_PENDING" ? temporalExpr(job.tempExprId)?.description : $t('Disabled') }} diff --git a/src/store/modules/job/JobState.ts b/src/store/modules/job/JobState.ts index 84ed5782..412920d9 100644 --- a/src/store/modules/job/JobState.ts +++ b/src/store/modules/job/JobState.ts @@ -16,16 +16,6 @@ export default interface JobState { list: any, total: 0 } - more: { - pending: { - list: any, - total: 0 - } - draft: { - list: any, - total: 0 - } - } current: any; temporalExp: any; enumIds: any; diff --git a/src/store/modules/job/actions.ts b/src/store/modules/job/actions.ts index f9a1f4ce..10d0982a 100644 --- a/src/store/modules/job/actions.ts +++ b/src/store/modules/job/actions.ts @@ -357,7 +357,7 @@ const actions: ActionTree = { ...payload.inputFields }, "noConditionFind": "Y", - "viewSize": (payload.inputFields?.systemJobEnumId?.length * 3) + "viewSize": ((payload.inputFields?.systemJobEnumId?.length * 3) || 0) + 30 } as any if (payload?.orderBy) { @@ -754,69 +754,6 @@ const actions: ActionTree = { console.error(err); } }, - async fetchMoreJobs({ commit }, payload) { - const fetchJobRequests = []; - let params = { - "inputFields": { - "enumTypeId": payload.inputFields.enumTypeId, - "statusId": "SERVICE_DRAFT", - "systemJobEnumId_op": "not-empty", - "shopId_fld0_value": store.state.user.currentShopifyConfig?.shopId, - "shopId_fld0_grp": "1", - "shopId_fld0_op": "equals", - "shopId_fld1_grp": "2", - "shopId_fld1_op": "empty" - } as any, - "fieldList": [ "systemJobEnumId", "runTime", "tempExprId", "parentJobId", "serviceName", "jobId", "jobName", "currentRetryCount", "statusId", "productStoreId", "runtimeDataId", "enumName", "shopId", "description" ], - "noConditionFind": "Y", - "viewSize": 30, // as we've not implemented infiniteScroll in moreJobs, we are passing viewSize hardcodedly as 30 - "viewIndex": 0 - } - - fetchJobRequests.push(JobService.fetchJobInformation(params).catch((err) => { - return err; - })) - - // Deep cloning in order to avoid mutating the same reference causing side effects - params = JSON.parse(JSON.stringify(params)); - - // Fetching pending jobs - params.inputFields.statusId = "SERVICE_PENDING"; - params.inputFields.productStoreId = this.state.user.currentEComStore.productStoreId; - fetchJobRequests.push(JobService.fetchJobInformation(params).catch((err) => { - return err; - })) - - try { - const resp = await Promise.all(fetchJobRequests) - const moreJobs = resp.reduce((responseJobs: any, response: any) => { - response.status === 200 && !hasError(response) && response.data.docs && (responseJobs = [...responseJobs, ...response.data.docs]); - return responseJobs; - }, []) - - if(moreJobs.length) { - const morePendingJobs = moreJobs.filter((job: any) => job.statusId === "SERVICE_PENDING") - const moreDraftJobs = moreJobs.filter((job: any) => job.statusId === "SERVICE_DRAFT") - - commit(types.JOB_MORE_UPDATED, { - pendingJobs: morePendingJobs, - pendingTotal: morePendingJobs.length, - draftJobs: moreDraftJobs, - draftTotal: moreDraftJobs.length, - }); - } else { - commit(types.JOB_MORE_UPDATED, { - pendingJobs: [], - pendingTotal: 0, - draftJobs: [], - draftTotal: 0, - }); - } - } catch (err) { - console.error(err); - showToast(translate("Something went wrong")); - } - }, setPipelineFilters({ commit, state }, payload) { const pipelineFilters = JSON.parse(JSON.stringify(state.pipelineFilters)); const pipelineFilter = (pipelineFilters as any)[payload.type] diff --git a/src/store/modules/job/getters.ts b/src/store/modules/job/getters.ts index 31c0f6a8..a3b91e97 100644 --- a/src/store/modules/job/getters.ts +++ b/src/store/modules/job/getters.ts @@ -57,17 +57,15 @@ const getters: GetterTree = { isMiscellaneousJobsScrollable: (state) => { return state.miscellaneous.list?.length > 0 && state.miscellaneous.list?.length < state.miscellaneous.total }, - getMoreJobs (state){ - let jobs = state.more.draft.list.reduce((jobs: any, draftJob: any) => { - jobs[draftJob.systemJobEnumId] = draftJob; - return jobs; - }, {}) - jobs = state.more.pending.list.reduce((jobs: any, pendingJob: any) => { - jobs[pendingJob.systemJobEnumId] = pendingJob; - return jobs; - }, jobs) + getMoreJobs: (state) => (jobEnums: any, enumTypeId: string): any => { + const orderJobEnumIds = Object.values(jobEnums) as any; - return Object.values(jobs) + return Object.keys(state.cached).reduce((orders: any, enumId: any) => { + if(orderJobEnumIds.indexOf(enumId) === -1 && state.cached[enumId]?.enumTypeId === enumTypeId) { + orders.push(state.cached[enumId]) + } + return orders + }, []) }, getPipelineFilters: (state) => { return state.pipelineFilters; diff --git a/src/store/modules/job/index.ts b/src/store/modules/job/index.ts index 7ac3b724..646642f0 100644 --- a/src/store/modules/job/index.ts +++ b/src/store/modules/job/index.ts @@ -25,16 +25,6 @@ const jobModule: Module = { list: [], total: 0 }, - more: { - pending: { - list: [], - total: 0 - }, - draft: { - list: [], - total: 0 - }, - }, temporalExp: [], enumIds: {}, current: {}, diff --git a/src/store/modules/job/mutation-types.ts b/src/store/modules/job/mutation-types.ts index 55e48757..dc22175f 100644 --- a/src/store/modules/job/mutation-types.ts +++ b/src/store/modules/job/mutation-types.ts @@ -8,6 +8,5 @@ export const JOB_HISTORY_UPDATED = SN_JOB + '/HISTORY_UPDATED' export const JOB_RUNNING_UPDATED = SN_JOB + '/RUNNING_UPDATED' export const JOB_CURRENT_UPDATED = SN_JOB + '/CURRENT_UPDATED' export const JOB_MISCELLANEOUS_UPDATED = SN_JOB + '/MISCELLANEOUS_UPDATED' -export const JOB_MORE_UPDATED = SN_JOB + '/MORE_UPDATED' export const JOB_PIPELINE_FILTERS_UPDATED = SN_JOB + '/PIPELINE_FILTERS_UPDATED' export const JOB_PIPELINE_FILTERS_CLEARED = SN_JOB + '/PIPELINE_FILTERS_CLEARED' diff --git a/src/store/modules/job/mutations.ts b/src/store/modules/job/mutations.ts index 93295098..38c2ca5c 100644 --- a/src/store/modules/job/mutations.ts +++ b/src/store/modules/job/mutations.ts @@ -45,12 +45,6 @@ const mutations: MutationTree = { state.miscellaneous.list = payload.jobs; state.miscellaneous.total = payload.total; }, - [types.JOB_MORE_UPDATED] (state, payload){ - state.more.pending.list = payload.pendingJobs; - state.more.pending.total = payload.pendingTotal; - state.more.draft.list = payload.draftJobs; - state.more.draft.total = payload.draftTotal; - }, [types.JOB_PIPELINE_FILTERS_UPDATED] (state, payload){ state.pipelineFilters = payload.pipelineFilters; }, diff --git a/src/views/Inventory.vue b/src/views/Inventory.vue index a860a526..ffab2b8b 100644 --- a/src/views/Inventory.vue +++ b/src/views/Inventory.vue @@ -33,7 +33,7 @@ - +