Skip to content

Commit 7068373

Browse files
committed
feat: option to insert additional diagnostics tab
1 parent 44dd3b4 commit 7068373

File tree

6 files changed

+103
-3
lines changed

6 files changed

+103
-3
lines changed

.rooignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
playwright-artifacts
11+
12+
# production
13+
/build
14+
/dist
15+
*.zip
16+
17+
# misc
18+
.idea
19+
.DS_Store
20+
.env.local
21+
.env.development.local
22+
.env.test.local
23+
.env.production.local
24+
.vscode
25+
.cursor
26+
27+
npm-debug.log*
28+
yarn-debug.log*
29+
yarn-error.log*
30+
31+
.env
32+
33+
34+
embedded-ui.tar.bz2

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,22 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
215215
});
216216
}
217217
default: {
218+
const customTab = uiFactory.additionalDiagnosticsTabs?.find(
219+
(tab) => tab.id === activeTab?.id,
220+
);
221+
222+
if (customTab) {
223+
return customTab.render({
224+
type,
225+
subType,
226+
database,
227+
path,
228+
databaseFullPath,
229+
additionalTenantProps,
230+
scrollContainerRef: containerRef,
231+
});
232+
}
233+
218234
return <div>{i18n('no-data')}</div>;
219235
}
220236
}

src/containers/Tenant/Diagnostics/DiagnosticsPages.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import {TENANT_DIAGNOSTICS_TABS_IDS} from '../../../store/reducers/tenant/consta
77
import type {TenantDiagnosticsTab} from '../../../store/reducers/tenant/types';
88
import {EPathSubType, EPathType} from '../../../types/api/schema';
99
import type {ETenantType} from '../../../types/api/tenant';
10+
import type {AdditionalDiagnosticsTab} from '../../../uiFactory/types';
11+
import {uiFactory} from '../../../uiFactory/uiFactory';
1012
import type {TenantQuery} from '../TenantPages';
1113
import {TenantTabsGroups} from '../TenantPages';
1214
import {isDatabaseEntityType, isTopicEntityType} from '../utils/schema';
@@ -233,7 +235,34 @@ export const getPagesByType = (
233235
const dbContext = isDatabaseEntityType(type) || options?.isTopLevel;
234236
const seeded = dbContext ? getDatabasePages(options?.databaseType) : base;
235237

236-
return applyFilters(seeded, type, options);
238+
const filtered = applyFilters(seeded, type, options);
239+
240+
// Add custom tabs from uiFactory if available
241+
const customTabsToInsert =
242+
uiFactory.additionalDiagnosticsTabs?.filter(
243+
(tab: AdditionalDiagnosticsTab) => !tab.shouldShow || tab.shouldShow(type, subType),
244+
) || [];
245+
246+
if (customTabsToInsert.length === 0) {
247+
return filtered;
248+
}
249+
250+
const result = [...filtered];
251+
252+
customTabsToInsert.forEach((customTab: AdditionalDiagnosticsTab) => {
253+
const tabPage = {id: customTab.id, title: customTab.title};
254+
255+
if (customTab.insertAfter === undefined) {
256+
// Append at the end
257+
result.push(tabPage);
258+
} else {
259+
// Insert at specific index
260+
const index = Math.max(0, Math.min(customTab.insertAfter, result.length));
261+
result.splice(index, 0, tabPage);
262+
}
263+
});
264+
265+
return result;
237266
};
238267

239268
export const useDiagnosticsPageLinkGetter = () => {

src/lib.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ export type {AsideNavigationProps} from './containers/AsideNavigation/AsideNavig
3535
export type {GetMonitoringLink, GetMonitoringClusterLink} from './utils/monitoring';
3636

3737
export {configureUIFactory} from './uiFactory/uiFactory';
38+
export type {DiagnosticsTabProps, AdditionalDiagnosticsTab} from './uiFactory/types';

src/store/reducers/tenant/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export const tenantPageSchema = z.nativeEnum(TENANT_PAGES_IDS);
1414
export type TenantPage = z.infer<typeof tenantPageSchema>;
1515

1616
export type TenantQueryTab = ValueOf<typeof TENANT_QUERY_TABS_ID>;
17-
export type TenantDiagnosticsTab = ValueOf<typeof TENANT_DIAGNOSTICS_TABS_IDS>;
17+
export type TenantDiagnosticsTab = ValueOf<typeof TENANT_DIAGNOSTICS_TABS_IDS> | string;
1818
export type TenantSummaryTab = ValueOf<typeof TENANT_SUMMARY_TABS_IDS>;
1919
export type TenantMetricsTab = ValueOf<typeof TENANT_METRICS_TABS_IDS>;
2020

src/uiFactory/types.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import type {
99
import type {ClusterInfo} from '../store/reducers/cluster/cluster';
1010
import type {IssuesTree} from '../store/reducers/healthcheckInfo/types';
1111
import type {PreparedTenant} from '../store/reducers/tenants/types';
12-
import type {ClusterLink, DatabaseLink} from '../types/additionalProps';
12+
import type {AdditionalTenantsProps, ClusterLink, DatabaseLink} from '../types/additionalProps';
1313
import type {MetaBaseClusterInfo} from '../types/api/meta';
14+
import type {EPathSubType, EPathType} from '../types/api/schema/schema';
1415
import type {ETenantType} from '../types/api/tenant';
1516
import type {GetLogsLink} from '../utils/logs';
1617
import type {GetMonitoringClusterLink, GetMonitoringLink} from '../utils/monitoring';
@@ -35,6 +36,7 @@ export interface UIFactory<H extends string = CommonIssueType> {
3536

3637
renderBackups?: RenderBackups;
3738
renderEvents?: RenderEvents;
39+
additionalDiagnosticsTabs?: AdditionalDiagnosticsTab[];
3840
clusterOrDatabaseAccessError?: Partial<EmptyStateProps>;
3941

4042
healthcheck: {
@@ -85,3 +87,21 @@ export type RenderBackups = (props: {
8587
export type RenderEvents = (props: {
8688
scrollContainerRef: React.RefObject<HTMLDivElement>;
8789
}) => React.ReactNode;
90+
91+
export type DiagnosticsTabProps = {
92+
type?: EPathType;
93+
subType?: EPathSubType;
94+
database: string;
95+
path: string;
96+
databaseFullPath?: string;
97+
additionalTenantProps?: AdditionalTenantsProps;
98+
scrollContainerRef: React.RefObject<HTMLDivElement>;
99+
};
100+
101+
export type AdditionalDiagnosticsTab = {
102+
id: string;
103+
title: string;
104+
render: (props: DiagnosticsTabProps) => React.ReactNode;
105+
shouldShow?: (type?: EPathType, subType?: EPathSubType) => boolean;
106+
insertAfter?: number;
107+
};

0 commit comments

Comments
 (0)