Skip to content

Commit 18b720d

Browse files
committed
feat: enhance menuItems functionality with sub-page support and feature toggling
1 parent c82cffc commit 18b720d

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

src/lib/menuItems.test.ts

+23-7
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,36 @@ describe('menuItems', () => {
5353
expect(
5454
menuItems({
5555
path: '/team/nais/prod-gcp/secret/github-backup-config',
56-
features: {
57-
redis: { enabled: true },
58-
valkey: { enabled: true },
59-
openSearch: { enabled: true },
60-
kafka: { enabled: true },
61-
unleash: { enabled: true }
62-
},
6356
member: true
6457
})
6558
.flatMap((g) => g)
6659
.find((i) => i.label === 'Secrets')?.active
6760
).toBe(true);
6861
});
6962

63+
test('postgres active for sub-pages', () => {
64+
expect(
65+
menuItems({
66+
path: '/team/nais/prod-gcp/postgres/gemini',
67+
member: true
68+
})
69+
.flatMap((g) => g)
70+
.find((i) => i.label === 'Postgres')?.active
71+
).toBe(true);
72+
});
73+
74+
test('valkey active for sub-pages with feature toogling', () => {
75+
expect(
76+
menuItems({
77+
path: '/team/nais/prod-gcp/valkey/gemini',
78+
features,
79+
member: true
80+
})
81+
.flatMap((g) => g)
82+
.find((i) => i.label === 'Valkey')?.active
83+
).toBe(true);
84+
});
85+
7086
test('no features', () => {
7187
expect(
7288
menuItems({

src/lib/menuItems.ts

+13-11
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,13 @@ export const menuItems = ({
5555

5656
const item =
5757
(baseUrl: string, page: string) =>
58-
(label: string, pageName?: string, matcher?: (url: string) => boolean) => {
58+
(label: string, pageName?: string, matchSubPath?: string) => {
5959
const href = pageName ? `${baseUrl}/${pageName}` : baseUrl;
6060
const { count, badge } = getInventory(pageName);
61-
const active = matcher?.(path) || pageName === page;
61+
const active =
62+
(matchSubPath && path.startsWith(`/team/${team}/${page}/${matchSubPath}/`)) ||
63+
pageName === page;
64+
6265
return {
6366
label,
6467
href,
@@ -89,15 +92,14 @@ export const menuItems = ({
8992
[menuItem('Overview')],
9093
[menuItem('Applications', 'applications'), menuItem('Jobs', 'jobs')],
9194
[
92-
member &&
93-
menuItem('Secrets', 'secrets', (url) => url.startsWith(`/team/${team}/${page}/secret/`)),
94-
menuItem('Postgres', 'postgres'),
95-
menuItem('Buckets', 'buckets'),
96-
features?.redis && menuItem('Redis', 'redis'),
97-
features?.valkey && menuItem('Valkey', 'valkey'),
98-
features?.openSearch && menuItem('OpenSearch', 'opensearch'),
99-
features?.kafka && menuItem('Kafka topics', 'kafka'),
100-
menuItem('BigQuery', 'bigquery'),
95+
member && menuItem('Secrets', 'secrets', 'secret'),
96+
menuItem('Postgres', 'postgres', 'postgres'),
97+
menuItem('Buckets', 'buckets', 'bucket'),
98+
features?.redis && menuItem('Redis', 'redis', 'redis'),
99+
features?.valkey && menuItem('Valkey', 'valkey', 'valkey'),
100+
features?.openSearch && menuItem('OpenSearch', 'opensearch', 'opensearch'),
101+
features?.kafka && menuItem('Kafka topics', 'kafka', 'kafka'),
102+
menuItem('BigQuery', 'bigquery', 'bigquery'),
101103
features?.unleash && menuItem('Unleash', 'unleash')
102104
].filter(Boolean) as { label: string; href: string; active?: boolean }[],
103105
[

0 commit comments

Comments
 (0)