Skip to content

Commit edbb4b3

Browse files
restore lexicographic sort to navigation group (opendatahub-io#5273)
1 parent 76e772d commit edbb4b3

File tree

3 files changed

+7
-26
lines changed

3 files changed

+7
-26
lines changed

frontend/src/app/navigation/__tests__/NavSection.spec.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,7 @@ describe('NavSection', () => {
12711271
title: 'Without Group',
12721272
href: '/withoutGroup',
12731273
section: 'settings',
1274-
// No group property (should use default '8_default')
1274+
// No group property (should use default)
12751275
},
12761276
flags: {},
12771277
};
@@ -1287,7 +1287,7 @@ describe('NavSection', () => {
12871287
await userEvent.setup().click(expandButton);
12881288
}
12891289

1290-
// Child with group should come first (1_early < 8_default)
1290+
// Child with group should come first
12911291
await waitFor(() => {
12921292
const items = screen.getAllByRole('link');
12931293
expect(items[0]).toHaveTextContent('With Group');
Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
11
import { NavExtension } from '@odh-dashboard/plugin-core/extension-points';
22

3-
const DEFAULT_GROUP = '8_default';
3+
const DEFAULT_GROUP = '5_default';
44

5-
/** Comparison function for navigation items sorting. */
6-
export const compareNavItemGroups = <T extends NavExtension>(a: T, b: T): number => {
7-
const groupA = a.properties.group || DEFAULT_GROUP;
8-
const groupB = b.properties.group || DEFAULT_GROUP;
9-
10-
// Extract numeric prefix and suffix for proper sorting
11-
const extractParts = (group: string) => {
12-
const match = group.match(/^(\d+)_(.*)$/);
13-
return match ? { num: parseInt(match[1], 10), suffix: match[2] } : { num: 0, suffix: group };
14-
};
15-
16-
const partsA = extractParts(groupA);
17-
const partsB = extractParts(groupB);
18-
19-
// First compare by numeric prefix
20-
if (partsA.num !== partsB.num) {
21-
return partsA.num - partsB.num;
22-
}
23-
24-
// If numeric parts are equal, compare by suffix
25-
return partsA.suffix.localeCompare(partsB.suffix);
26-
};
5+
/** Lexicographic comparison function for navigation items sorting. */
6+
export const compareNavItemGroups = <T extends NavExtension>(a: T, b: T): number =>
7+
(a.properties.group || DEFAULT_GROUP).localeCompare(b.properties.group || DEFAULT_GROUP);

packages/plugin-core/src/extension-points/navigation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export type NavItemProperties = {
4040
section?: string;
4141
/** Adds data attributes to the DOM. */
4242
dataAttributes?: { [key: string]: string };
43-
/** Group are used to sort items lexographically. Unspecified items will be sorted into the '5_default' group. */
43+
/** Group are used to sort items lexicographically. Unspecified items will be sorted into the '5_default' group. */
4444
group?: string;
4545
/** Icon reference for this item. */
4646
iconRef?: ComponentCodeRef;

0 commit comments

Comments
 (0)