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
2 changes: 1 addition & 1 deletion 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
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) || 0) + 30
} 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((orders: any, enumId: any) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Object.keys(state.cached).reduce((orders: any, enumId: any) => {
return Object.keys(state.cached).reduce((orders: any, enumId: string) => {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

if(orderJobEnumIds.indexOf(enumId) === -1 && state.cached[enumId]?.enumTypeId === enumTypeId) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead in place of indexOf, I think using includes will be a good option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure sir

orders.push(state.cached[enumId])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should change order specific variable name, the same getter is being used on all pages.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right sir. Fixed it.

}
return orders
}, [])
},
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
14 changes: 4 additions & 10 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, 'INVENTORY_SYS_JOB').length" :jobs="getMoreJobs(jobEnums, 'INVENTORY_SYS_JOB')" :jobEnums="jobEnums" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -171,22 +171,16 @@ export default defineComponent({
this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description :
this.$t('Disabled')
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "INVENTORY_SYS_JOB",
},
});
getMoreJobs(jobEnums: any, enumTypeId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is needed? we could directly use moreJobs(jobEnums, enumTypeId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sir. Fixed it.

return this.moreJobs(jobEnums, enumTypeId);
}
},
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
15 changes: 5 additions & 10 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, 'ORDER_SYS_JOB').length" :jobs="getMoreJobs(jobEnums, 'ORDER_SYS_JOB')" :jobEnums="jobEnums" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -475,19 +475,14 @@ export default defineComponent({
this.autoCancelDays = "";
}
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "ORDER_SYS_JOB",
},
});
getMoreJobs(jobEnums: any, enumTypeId: string) {
return this.moreJobs(jobEnums, enumTypeId);
}
},
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 +495,7 @@ export default defineComponent({
if (this.currentEComStore.productStoreId) {
this.getAutoCancelDays();
}
this.fetchMoreJobs();
// this.moreJobs = this.getMoreJobs(this.jobEnums, "ORDER_SYS_JOB");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this comment if not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done sir

emitter.on('viewJobConfiguration', this.viewJobConfiguration)
},
unmounted() {
Expand Down
16 changes: 5 additions & 11 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, 'PRE_ORD_SYS_JOB').length" :jobs="getMoreJobs(jobEnums, 'PRE_ORD_SYS_JOB')" :jobEnums="jobEnums" />
</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -238,7 +238,7 @@ export default defineComponent({
currentJobStatus: '',
freqType: '',
isJobDetailAnimationCompleted: false,
isDesktop: isPlatform('desktop')
isDesktop: isPlatform('desktop'),
}
},
methods: {
Expand Down Expand Up @@ -323,22 +323,16 @@ export default defineComponent({
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",
},
});
getMoreJobs(jobEnums: any, enumTypeId: string) {
return this.moreJobs(jobEnums, enumTypeId);
}
},
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
14 changes: 4 additions & 10 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, 'PRODUCT_SYS_JOB').length" :jobs="getMoreJobs(jobEnums, 'PRODUCT_SYS_JOB').length" :jobEnums="jobEnums" />
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Define a local property to declare the enumTypeId value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done sir

</section>

<aside class="desktop-only" v-if="isDesktop" v-show="currentJob">
Expand Down Expand Up @@ -127,12 +127,10 @@ export default defineComponent({
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 @@ -180,12 +178,8 @@ export default defineComponent({
this.getTemporalExpr(this.getJobStatus(this.jobEnums[enumId]))?.description :
this.$t('Disabled')
},
async fetchMoreJobs() {
await this.store.dispatch("job/fetchMoreJobs", {
"inputFields":{
"enumTypeId": "PRODUCT_SYS_JOB",
},
});
getMoreJobs(jobEnums: any, enumTypeId: string) {
return this.moreJobs(jobEnums, enumTypeId);
}
},
setup() {
Expand Down