Skip to content

Commit d97f7d5

Browse files
authored
fix(feo-interceptors): handle nav groups replacement (#2248)
1 parent a19f886 commit d97f7d5

File tree

4 files changed

+135
-0
lines changed

4 files changed

+135
-0
lines changed

packages/config-utils/src/feo/feo-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export type DirectNavItem = {
7878
expandable?: boolean;
7979
// should be removed
8080
appId?: string;
81+
groupId?: string;
8182
routes?: DirectNavItem[];
8283
navItems?: DirectNavItem[];
8384
bundleSegmentRef?: string;

packages/config-utils/src/feo/navigation-interceptor.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { DirectNavItem, FrontendCRD, Nav, SegmentRef } from './feo-types';
22
import navigationInterceptor from './navigation-interceptor';
33

4+
import costNav from './test-nav-cost.json';
5+
46
describe('NavigationInterceptor', () => {
57
describe('bundle segments', () => {
68
// Declare shared variables outside beforeEach for shared access
@@ -727,5 +729,59 @@ describe('NavigationInterceptor', () => {
727729
// Assert - Verify behavior
728730
expect(result).toEqual(expectedResult);
729731
});
732+
733+
it('should replace navigation segments', () => {
734+
const frontendName = 'cost-management';
735+
const frontendCRD: FrontendCRD = {
736+
objects: [
737+
{
738+
metadata: {
739+
name: frontendName,
740+
},
741+
spec: {
742+
frontend: {
743+
paths: ['/'],
744+
},
745+
module: {
746+
manifestLocation: 'http://localhost:3000/manifest.json',
747+
},
748+
navigationSegments: [
749+
{
750+
"segmentId": "cost-management",
751+
"navItems": [
752+
{
753+
"id": "cost-management.nav",
754+
"title": "Cost Management changed",
755+
"expandable": true,
756+
"routes": [
757+
{
758+
"id": "cost-management.overview",
759+
"title": "Overview changed",
760+
"href": "/openshift/cost-management",
761+
},
762+
{
763+
"id": "cost-management.systems",
764+
"title": "Systems",
765+
"href": "/openshift/cost-management/systems",
766+
},
767+
]
768+
}
769+
]
770+
}
771+
],
772+
},
773+
},
774+
],
775+
};
776+
777+
const remoteNav: Nav = costNav;
778+
const result = navigationInterceptor(frontendCRD, remoteNav, bundleId);
779+
const rootData = result[0].navItems?.find((item) => item.id === 'cost-management.nav');
780+
expect(rootData).toBeDefined();
781+
expect(rootData?.title).toEqual('Cost Management changed');
782+
const rootRoutes = rootData?.routes;
783+
expect(rootRoutes).toBeDefined();
784+
expect(rootRoutes?.[0].title).toEqual('Overview changed');
785+
});
730786
});
731787
});

packages/config-utils/src/feo/navigation-interceptor.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ function parseNavItems(
110110
if (segmentItemMatch && !hasSegmentRef(segmentItemMatch)) {
111111
return handleNestedNav(segmentItemMatch, navItem, bSegmentCache, nSegmentCache, bundleId, currentFrontendName, parentSegment);
112112
}
113+
} else if (typeof navItem.groupId === 'string' && navItem.groupId.length > 0) {
114+
navItem.navItems = parseNavItems(navItem.navItems || [], bSegmentCache, nSegmentCache, bundleId, currentFrontendName);
115+
return navItem;
113116
}
114117
}
115118
return navItem;
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
2+
{
3+
"id": "openshift",
4+
"navItems": [
5+
{
6+
"bundleSegmentRef": "openshift",
7+
"frontendRef": "openshift",
8+
"groupId": "cluster-management",
9+
"id": "cluster-management",
10+
"navItems": [
11+
{
12+
"bundleSegmentRef": "openshift",
13+
"expandable": true,
14+
"frontendRef": "cost-management",
15+
"id": "cost-management.nav",
16+
"routes": [
17+
{
18+
"href": "/openshift/cost-management",
19+
"id": "cost-management.overview",
20+
"title": "Overview"
21+
},
22+
{
23+
"href": "/openshift/cost-management/systems",
24+
"id": "cost-management.systems",
25+
"title": "Systems"
26+
},
27+
{
28+
"href": "/openshift/cost-management/optimizations",
29+
"id": "cost-management.optimizations",
30+
"title": "Optimizations"
31+
},
32+
{
33+
"href": "/openshift/cost-management/ocp",
34+
"id": "cost-management.ocp",
35+
"title": "OpenShift"
36+
},
37+
{
38+
"href": "/openshift/cost-management/aws",
39+
"id": "cost-management.aws",
40+
"title": "Amazon Web Services"
41+
},
42+
{
43+
"href": "/openshift/cost-management/gcp",
44+
"id": "cost-management.gcp",
45+
"title": "Google Cloud Platform"
46+
},
47+
{
48+
"href": "/openshift/cost-management/azure",
49+
"id": "cost-management.azure",
50+
"title": "Microsoft Azure"
51+
},
52+
{
53+
"href": "/openshift/cost-management/explorer",
54+
"id": "cost-management.explorer",
55+
"title": "Cost Explorer"
56+
},
57+
{
58+
"href": "/openshift/cost-management/settings",
59+
"id": "cost-management.settings",
60+
"title": "Settings"
61+
}
62+
],
63+
"segmentRef": {
64+
"frontendName": "cost-management",
65+
"segmentId": "cost-management"
66+
},
67+
"title": "Cost Management"
68+
}
69+
],
70+
"position": 100,
71+
"title": "Cluster Management"
72+
}
73+
],
74+
"title": "OpenShift"
75+
}

0 commit comments

Comments
 (0)