Skip to content

Commit fa85bda

Browse files
committed
Hide metrics tab and url behind a flag
1 parent b2147f5 commit fa85bda

File tree

5 files changed

+113
-10
lines changed

5 files changed

+113
-10
lines changed

packages/manager/src/featureFlags.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ interface AclpLogsFlag extends BetaFeatureFlag {
134134
* This property indicates whether to show Custom HTTPS destination type
135135
*/
136136
customHttpsEnabled?: boolean;
137+
/**
138+
* This property indicates whether to show the "Metrics" tab on Logs Stream details page or not
139+
*/
140+
metricsEnabled?: boolean;
137141
/**
138142
* This property indicates whether the feature is new or not
139143
*/
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { screen } from '@testing-library/react';
2+
import * as React from 'react';
3+
import { beforeEach, describe, it } from 'vitest';
4+
5+
import {
6+
akamaiObjectStorageDestinationFactory,
7+
streamFactory,
8+
} from 'src/factories';
9+
import { StreamLanding } from 'src/features/Delivery/Streams/Stream/StreamLanding';
10+
import { http, HttpResponse, server } from 'src/mocks/testServer';
11+
import { renderWithTheme } from 'src/utilities/testHelpers';
12+
13+
import type { Flags } from 'src/featureFlags';
14+
15+
const streamId = 123;
16+
const mockDestinations = [
17+
akamaiObjectStorageDestinationFactory.build({ id: 1 }),
18+
];
19+
const mockStream = streamFactory.build({
20+
id: streamId,
21+
label: `Stream ${streamId}`,
22+
destinations: mockDestinations,
23+
});
24+
25+
describe('StreamLanding', () => {
26+
const renderComponent = (flags: Partial<Flags>) => {
27+
renderWithTheme(<StreamLanding />, {
28+
flags,
29+
initialRoute: '/logs/delivery/streams/$streamId/summary',
30+
});
31+
};
32+
33+
beforeEach(async () => {
34+
server.use(
35+
http.get(`*/monitor/streams/${streamId}`, () => {
36+
return HttpResponse.json(mockStream);
37+
})
38+
);
39+
});
40+
41+
describe('and metrics are not enabled', () => {
42+
const flags = {
43+
aclpLogs: {
44+
enabled: true,
45+
beta: false,
46+
metricsEnabled: false,
47+
},
48+
};
49+
50+
it('should render the summary and not the metrics tab', async () => {
51+
renderComponent(flags);
52+
53+
screen.getByText('Summary');
54+
expect(screen.queryByText('Metrics')).not.toBeInTheDocument();
55+
});
56+
});
57+
58+
describe('and metrics are enabled', () => {
59+
const flags = {
60+
aclpLogs: {
61+
enabled: true,
62+
beta: false,
63+
metricsEnabled: true,
64+
},
65+
};
66+
67+
it('should render the summary tab and metrics tab', async () => {
68+
renderComponent(flags);
69+
70+
screen.getByText('Summary');
71+
expect(screen.queryByText('Metrics')).toBeInTheDocument();
72+
});
73+
});
74+
});

packages/manager/src/features/Delivery/Streams/Stream/StreamLanding.tsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useParams } from '@tanstack/react-router';
22
import * as React from 'react';
3+
import { useMemo } from 'react';
34

45
import { DocumentTitleSegment } from 'src/components/DocumentTitle';
56
import {
@@ -11,25 +12,38 @@ import { SafeTabPanel } from 'src/components/Tabs/SafeTabPanel';
1112
import { TabPanels } from 'src/components/Tabs/TabPanels';
1213
import { Tabs } from 'src/components/Tabs/Tabs';
1314
import { TanStackTabLinkList } from 'src/components/Tabs/TanStackTabLinkList';
15+
import { useIsACLPLogsEnabled } from 'src/features/Delivery/deliveryUtils';
1416
import { StreamMetrics } from 'src/features/Delivery/Streams/Stream/StreamMetrics';
1517
import { StreamEdit } from 'src/features/Delivery/Streams/StreamForm/StreamEdit';
1618
import { useTabs } from 'src/hooks/useTabs';
1719

20+
import type { Tab } from 'src/hooks/useTabs';
21+
1822
export const StreamLanding = () => {
1923
const { streamId } = useParams({
2024
strict: false,
2125
});
26+
const { isACLPLogsMetricsEnabled } = useIsACLPLogsEnabled();
2227

23-
const { handleTabChange, tabIndex, tabs } = useTabs([
24-
{
25-
title: 'Summary',
26-
to: `/logs/delivery/streams/$streamId/summary`,
27-
},
28-
{
29-
title: 'Metrics',
30-
to: `/logs/delivery/streams/$streamId/metrics`,
31-
},
32-
]);
28+
const activeTabs = useMemo(() => {
29+
const result: Tab[] = [
30+
{
31+
title: 'Summary',
32+
to: `/logs/delivery/streams/$streamId/summary`,
33+
},
34+
];
35+
36+
if (isACLPLogsMetricsEnabled) {
37+
result.push({
38+
title: 'Metrics',
39+
to: `/logs/delivery/streams/$streamId/metrics`,
40+
});
41+
}
42+
43+
return result;
44+
}, [isACLPLogsMetricsEnabled]);
45+
46+
const { handleTabChange, tabIndex, tabs } = useTabs(activeTabs);
3347

3448
const landingHeaderProps: LandingHeaderProps = {
3549
breadcrumbProps: {

packages/manager/src/features/Delivery/deliveryUtils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export const useIsACLPLogsEnabled = (): {
3939
isACLPLogsBeta: boolean;
4040
isACLPLogsCustomHttpsEnabled: boolean;
4141
isACLPLogsEnabled: boolean;
42+
isACLPLogsMetricsEnabled: boolean;
4243
isACLPLogsNew: boolean;
4344
} => {
4445
const { data: account } = useAccount();
@@ -55,6 +56,7 @@ export const useIsACLPLogsEnabled = (): {
5556
return {
5657
isACLPLogsBeta: !!flags.aclpLogs?.beta,
5758
isACLPLogsCustomHttpsEnabled: !!flags.aclpLogs?.customHttpsEnabled,
59+
isACLPLogsMetricsEnabled: !!flags.aclpLogs?.metricsEnabled,
5860
isACLPLogsNew: !!flags.aclpLogs?.new,
5961
isACLPLogsEnabled,
6062
};

packages/manager/src/routes/delivery/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,15 @@ const streamSummaryRoute = createRoute({
9292
);
9393

9494
const streamMetricsRoute = createRoute({
95+
beforeLoad: ({ params, context }) => {
96+
if (!context?.flags?.aclpLogs?.metricsEnabled) {
97+
throw redirect({
98+
to: '/logs/delivery/streams/$streamId/summary',
99+
params: { streamId: params.streamId },
100+
replace: true,
101+
});
102+
}
103+
},
95104
getParentRoute: () => streamRoute,
96105
path: 'metrics',
97106
}).lazy(() =>

0 commit comments

Comments
 (0)