Skip to content

Commit

Permalink
Merge pull request #109 from ymaheshwari1/feat/run
Browse files Browse the repository at this point in the history
Improved: code to sort the groups on the basis of runTime and improved the sort function to sort the array on the provided field
  • Loading branch information
ymaheshwari1 authored Feb 16, 2024
2 parents efe91dd + b7ce737 commit 9cbf983
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,11 @@ const actions: ActionTree<OrderRoutingState, RootState> = {

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)
Expand Down
16 changes: 12 additions & 4 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ const showToast = async (message: string) => {
return toast.present();
}

const sortSequence = (sequence: Array<Group | Route | Rule>) => {
// 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<Group | Route | Rule>, 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) => {
Expand Down

0 comments on commit 9cbf983

Please sign in to comment.