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

Fixed: Jobs repeatation in moreJobs sections on all pages(#2vjxdha) #296

Merged
merged 8 commits into from
Nov 24, 2022
4 changes: 2 additions & 2 deletions src/components/MoreJobs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</ion-card-header>
<ion-list>
<ion-item v-for="job in jobs" :key="job.jobId" @click="viewJobConfiguration(job)" detail button>
<ion-label class="ion-text-wrap">{{ job.jobName }}</ion-label>
<ion-label class="ion-text-wrap">{{ job.enumName || job.jobName }}</ion-label>
<ion-label slot="end">{{ job.statusId === "SERVICE_PENDING" ? temporalExpr(job.tempExprId)?.description : $t('Disabled') }}</ion-label>
</ion-item>
</ion-list>
Expand Down Expand Up @@ -37,7 +37,7 @@ export default defineComponent({
IonLabel,
IonList
},
props: ["jobs", "jobEnums"],
props: ["jobs"],
computed: {
...mapGetters({
getJobStatus: 'job/getJobStatus',
Expand Down
10 changes: 0 additions & 10 deletions src/store/modules/job/JobState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 1 addition & 64 deletions src/store/modules/job/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ const actions: ActionTree<JobState, RootState> = {
...payload.inputFields
},
"noConditionFind": "Y",
"viewSize": (payload.inputFields?.systemJobEnumId?.length * 3)
"viewSize": (payload.inputFields?.systemJobEnumId?.length * 3) || 50
} as any

if (payload?.orderBy) {
Expand Down Expand Up @@ -754,69 +754,6 @@ const actions: ActionTree<JobState, RootState> = {
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]
Expand Down
18 changes: 8 additions & 10 deletions src/store/modules/job/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,15 @@ const getters: GetterTree <JobState, RootState> = {
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((jobs: any, enumId: string) => {
if(state.cached[enumId]?.enumTypeId === enumTypeId && !orderJobEnumIds.includes(enumId)) {
jobs.push(state.cached[enumId])
}
return jobs
}, [])
},
getPipelineFilters: (state) => {
return state.pipelineFilters;
Expand Down
10 changes: 0 additions & 10 deletions src/store/modules/job/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@ const jobModule: Module<JobState, RootState> = {
list: [],
total: 0
},
more: {
pending: {
list: [],
total: 0
},
draft: {
list: [],
total: 0
},
},
temporalExp: [],
enumIds: {},
current: {},
Expand Down
1 change: 0 additions & 1 deletion src/store/modules/job/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
6 changes: 0 additions & 6 deletions src/store/modules/job/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ const mutations: MutationTree <JobState> = {
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;
},
Expand Down
18 changes: 5 additions & 13 deletions src/views/Inventory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
</ion-label>
</ion-item>
</ion-card>
<MoreJobs v-if="moreJobs.length" :jobs="moreJobs" :jobEnums="jobEnums" />
<MoreJobs v-if="getMoreJobs(jobEnums, enumTypeId).length" :jobs="getMoreJobs(jobEnums, enumTypeId)" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -96,7 +96,8 @@ export default defineComponent({
currentJobStatus: '',
freqType: '',
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop')
isDesktop: isPlatform('desktop'),
enumTypeId: 'INVENTORY_SYS_JOB'
}
},
computed: {
Expand All @@ -106,7 +107,7 @@ export default defineComponent({
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
moreJobs: 'job/getMoreJobs'
getMoreJobs: 'job/getMoreJobs'
}),
bopisCorrections(): boolean {
const status = this.getJobStatus(this.jobEnums["BOPIS_CORRECTION"]);
Expand Down Expand Up @@ -170,23 +171,14 @@ export default defineComponent({
return this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description ?
this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description :
this.$t('Disabled')
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "INVENTORY_SYS_JOB",
},
});
}
},
mounted () {
this.store.dispatch("job/fetchJobs", {
"inputFields":{
"systemJobEnumId": Object.values(this.jobEnums),
"systemJobEnumId_op": "in"
"enumTypeId": "INVENTORY_SYS_JOB"
}
});
this.fetchMoreJobs();
emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
Expand Down
19 changes: 6 additions & 13 deletions src/views/Orders.vue
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
</ion-item-sliding>
</ion-list>
</ion-card>
<MoreJobs v-if="moreJobs.length" :jobs="moreJobs" :jobEnums="jobEnums" />
<MoreJobs v-if="getMoreJobs({...jobEnums, ...initialLoadJobEnums}, enumTypeId).length" :jobs="getMoreJobs({...jobEnums, ...initialLoadJobEnums}, enumTypeId)" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -234,7 +234,9 @@ export default defineComponent({
freqType: '',
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop'),
autoCancelDays: ''
autoCancelDays: '',
enumTypeId: 'ORDER_SYS_JOB',
initialLoadJobEnums: JSON.parse(process.env?.VUE_APP_INITIAL_JOB_ENUMS as string) as any
}
},
computed: {
Expand All @@ -246,7 +248,7 @@ export default defineComponent({
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
getCachedWebhook: 'webhook/getCachedWebhook',
moreJobs: 'job/getMoreJobs'
getMoreJobs: 'job/getMoreJobs'
}),
promiseDateChanges(): boolean {
const status = this.getJobStatus(this.jobEnums['NTS_PRMS_DT_CHNG']);
Expand Down Expand Up @@ -474,20 +476,12 @@ export default defineComponent({
console.error(err)
this.autoCancelDays = "";
}
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "ORDER_SYS_JOB",
},
});
}
},
mounted () {
this.store.dispatch("job/fetchJobs", {
"inputFields":{
"systemJobEnumId": Object.values(this.jobEnums),
"systemJobEnumId_op": "in"
"enumTypeId": "ORDER_SYS_JOB"
}
});
this.store.dispatch("job/fetchJobs", {
Expand All @@ -500,7 +494,6 @@ export default defineComponent({
if (this.currentEComStore.productStoreId) {
this.getAutoCancelDays();
}
this.fetchMoreJobs();
emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
Expand Down
18 changes: 5 additions & 13 deletions src/views/PreOrder.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
<ion-label class="ion-text-wrap"><p>{{ $t("Re-allocation will re-calculate promise dates on all pre-orders based on upcoming inventory from purchase orders. Promise dates that were manually adjusted will be overriden.") }}</p></ion-label>
</ion-item>
</ion-card>
<MoreJobs v-if="moreJobs.length" :jobs="moreJobs" :jobEnums="jobEnums" />
<MoreJobs v-if="getMoreJobs(jobEnums, enumTypeId).length" :jobs="getMoreJobs(jobEnums, enumTypeId)" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -174,7 +174,7 @@ export default defineComponent({
currentShopifyConfig: 'user/getCurrentShopifyConfig',
currentEComStore: 'user/getCurrentEComStore',
getTemporalExpr: 'job/getTemporalExpr',
moreJobs: 'job/getMoreJobs'
getMoreJobs: 'job/getMoreJobs'
}),
preOrderManageCatalog(): boolean {
const status = this.getJobStatus(this.jobEnums["PRE_ORDER_CTLG"]);
Expand Down Expand Up @@ -238,7 +238,8 @@ export default defineComponent({
currentJobStatus: '',
freqType: '',
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop')
isDesktop: isPlatform('desktop'),
enumTypeId: 'PRE_ORD_SYS_JOB'
}
},
methods: {
Expand Down Expand Up @@ -322,23 +323,14 @@ export default defineComponent({
return this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description ?
this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description :
this.$t('Disabled')
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "PRE_ORD_SYS_JOB",
},
});
}
},
mounted () {
this.store.dispatch("job/fetchJobs", {
"inputFields":{
"systemJobEnumId": Object.values(this.jobEnums),
"systemJobEnumId_op": "in"
"enumTypeId": "PRE_ORD_SYS_JOB"
}
});
this.fetchMoreJobs();
emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
Expand Down
17 changes: 5 additions & 12 deletions src/views/Product.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<ion-toggle slot="end" :checked="deleteProductsWebhook" @ionChange="updateWebhook($event['detail'].checked, 'DELETE_PRODUCTS')" color="secondary" />
</ion-item>
</ion-card>
<MoreJobs v-if="moreJobs.length" :jobs="moreJobs" :jobEnums="jobEnums" />
<MoreJobs v-if="getMoreJobs({...jobEnums, ...initialLoadJobEnums}, enumTypeId).length" :jobs="getMoreJobs({...jobEnums, ...initialLoadJobEnums}, enumTypeId).length" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -100,7 +100,7 @@ export default defineComponent({
getJob: 'job/getJob',
currentShopifyConfig: 'user/getCurrentShopifyConfig',
getCachedWebhook: 'webhook/getCachedWebhook',
moreJobs: 'job/getMoreJobs'
getMoreJobs: 'job/getMoreJobs'
}),
newProductsWebhook(): boolean {
const webhookTopic = this.webhookEnums['NEW_PRODUCTS']
Expand All @@ -122,17 +122,17 @@ export default defineComponent({
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop'),
webhookEnums: JSON.parse(process.env?.VUE_APP_WEBHOOK_ENUMS as string) as any,
enumTypeId: 'PRODUCT_SYS_JOB',
initialLoadJobEnums: JSON.parse(process.env?.VUE_APP_INITIAL_JOB_ENUMS as string) as any
}
},
mounted () {
this.store.dispatch("job/fetchJobs", {
"inputFields":{
"systemJobEnumId": Object.values(this.jobEnums),
"systemJobEnumId_op": "in"
"enumTypeId": "PRODUCT_SYS_JOB"
}
});
this.store.dispatch('webhook/fetchWebhooks')
this.fetchMoreJobs();
emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
Expand Down Expand Up @@ -179,13 +179,6 @@ export default defineComponent({
return this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description ?
this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description :
this.$t('Disabled')
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "PRODUCT_SYS_JOB",
},
});
}
},
setup() {
Expand Down