From e8fea8b0df0ea9c6235dd93eb1b6fe46e78514b4 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 16 Feb 2024 16:14:53 +0530 Subject: [PATCH 1/2] Improved: code to sort the groups on the basis of runTime --- src/store/modules/orderRouting/actions.ts | 3 ++- src/utils/index.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 4d3a3c6..b7e4ea7 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -47,10 +47,11 @@ const actions: ActionTree = { routingGroups = routingGroups.map((group: any) => ({ ...group, + runTime: schedules[group.jobName]?.nextExecutionDateTime, // Using this value just to sort the groups on the basis of runTime schedule: schedules[group.jobName] })) - routingGroups = sortSequence(routingGroups) + routingGroups = sortSequence(routingGroups, "runTime") } commit(types.ORDER_ROUTING_GROUPS_UPDATED, routingGroups) diff --git a/src/utils/index.ts b/src/utils/index.ts index bd03e36..21791d0 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -19,10 +19,18 @@ const showToast = async (message: string) => { return toast.present(); } -const sortSequence = (sequence: Array) => { - // Currently, sorting is only performed on sequenceNum, so if two seqence have same seqNum then they will be arranged in FCFS basis - // TODO: Need to check that if for the above case we need to define the sorting on name as well, when seqNum is same - return sequence.sort((a, b) => a.sequenceNum - b.sequenceNum) +const sortSequence = (sequence: Array, sortOnField = "sequenceNum") => { + // Currently, sorting is only performed on a single parameter, so if two sequence have same value for that parameter then they will be arranged in FCFS basis + // TODO: Need to check that if for the above case we need to define the sorting on name as well, when previous param is same + return sequence.sort((a: any, b: any) => { + if(a[sortOnField] === b[sortOnField]) return 0; + + // Sort undefined values at last + if(a[sortOnField] == undefined) return 1; + if(b[sortOnField] === undefined) return -1; + + return a[sortOnField] - b[sortOnField] + }) } const getTime = (time: any) => { From b7ce73790fa5b59c08033dc3f52eff81c24e72e7 Mon Sep 17 00:00:00 2001 From: Yash Maheshwari Date: Fri, 16 Feb 2024 16:17:42 +0530 Subject: [PATCH 2/2] Removed: type checking for undefined param --- src/utils/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/index.ts b/src/utils/index.ts index 21791d0..1536805 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -27,7 +27,7 @@ const sortSequence = (sequence: Array, sortOnField = "sequ // Sort undefined values at last if(a[sortOnField] == undefined) return 1; - if(b[sortOnField] === undefined) return -1; + if(b[sortOnField] == undefined) return -1; return a[sortOnField] - b[sortOnField] })