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..1536805 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) => {