Skip to content

Commit b6a6269

Browse files
Merge pull request #4603 from bcgov/4600-sort-methodologies-chronologically-in-review-changes-page
4600 sort methodologies chronologically in review changes page
2 parents d17643b + a5f494b commit b6a6269

2 files changed

Lines changed: 19 additions & 8 deletions

File tree

bciers/apps/reporting/src/app/components/changeReview/utils/activityViewHelpers.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
compareMethodologyKeys,
23
formatKey,
34
singularizeLabel,
45
} from "@reporting/src/app/components/shared/activityRenderUtils";
@@ -331,6 +332,14 @@ export const renderDiffTree = (items: SegmentedChange[]): React.ReactNode => {
331332
}
332333
}
333334

335+
// Sort methodology period (months/quarters) chronologically
336+
const methodologyGroup = grouped.get("methodology");
337+
if (methodologyGroup) {
338+
methodologyGroup.children.sort((a, b) =>
339+
compareMethodologyKeys(a.segs[0] ?? "", b.segs[0] ?? ""),
340+
);
341+
}
342+
334343
return (
335344
<>
336345
{Array.from(grouped.entries()).map(([key, { label, children }]) => {

bciers/apps/reporting/src/app/components/shared/activityRenderUtils.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ export const MONTH_QUARTER_ORDER: string[] = [
2828
"quarter4",
2929
];
3030

31+
export const compareMethodologyKeys = (a: string, b: string): number => {
32+
const aIdx = MONTH_QUARTER_ORDER.indexOf(a);
33+
const bIdx = MONTH_QUARTER_ORDER.indexOf(b);
34+
if (aIdx === -1 && bIdx === -1) return 0;
35+
if (aIdx === -1) return -1;
36+
if (bIdx === -1) return 1;
37+
return aIdx - bIdx;
38+
};
39+
3140
export const sortMethodologyEntries = (
3241
entries: [string, unknown][],
3342
): [string, unknown][] =>
34-
[...entries].sort(([a], [b]) => {
35-
const aIdx = MONTH_QUARTER_ORDER.indexOf(a);
36-
const bIdx = MONTH_QUARTER_ORDER.indexOf(b);
37-
if (aIdx === -1 && bIdx === -1) return 0; // both non-period: preserve order
38-
if (aIdx === -1) return -1; // a is non-period: float to front
39-
if (bIdx === -1) return 1; // b is non-period: float to front
40-
return aIdx - bIdx; // both periods: sort chronologically
41-
});
43+
[...entries].sort(([a], [b]) => compareMethodologyKeys(a, b));
4244

4345
/**
4446
* Explicit plural → singular label map for common array keys.

0 commit comments

Comments
 (0)