Skip to content

Commit 2efa15c

Browse files
authored
Sort naturally between tasks of equal dates (#2296)
1 parent ad20c6b commit 2efa15c

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

epictrack-web/src/components/workPlan/event/EventList.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import Moment from "moment";
1212
import { WorkplanContext } from "../WorkPlanContext";
1313
import { MRT_RowSelectionState } from "material-react-table";
14-
import { dateUtils } from "../../../utils";
14+
import { dateUtils, naturalSortCollator } from "../../../utils";
1515
import { Box, Button, Divider, Grid, Tooltip, Typography } from "@mui/material";
1616
import { Palette } from "../../../styles/theme";
1717
import { IconProps } from "../../icons/type";
@@ -231,7 +231,7 @@ const EventList = () => {
231231
(eventX.type === EVENT_TYPE.TASK &&
232232
eventY.type === EVENT_TYPE.TASK)
233233
) {
234-
return eventX.id < eventY.id ? -1 : 1;
234+
return naturalSortCollator.compare(eventX.name, eventY.name);
235235
}
236236
// MILESTONE should shows first, then TASK
237237
if (

epictrack-web/src/utils/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import dateUtils from "./dateUtils";
22

3+
export const naturalSortCollator = new Intl.Collator("en-GB", {
4+
numeric: true,
5+
ignorePunctuation: true,
6+
sensitivity: "base",
7+
});
38
const sort = (collection: any[], sortField: string) => {
4-
const collator = new Intl.Collator("en-GB", {
5-
numeric: true,
6-
ignorePunctuation: true,
7-
sensitivity: "base",
8-
});
99
const keys = sortField.split(".");
1010
if (keys.length > 1) {
1111
return collection.sort(function (a, b) {
12-
return collator.compare(a[keys[0]][keys[1]], b[keys[0]][keys[1]]);
12+
return naturalSortCollator.compare(
13+
a[keys[0]][keys[1]],
14+
b[keys[0]][keys[1]]
15+
);
1316
});
1417
} else {
1518
return collection.sort(function (a, b) {
16-
return collator.compare(a[sortField], b[sortField]);
19+
return naturalSortCollator.compare(a[sortField], b[sortField]);
1720
});
1821
}
1922
};

0 commit comments

Comments
 (0)