Skip to content

Commit 7151974

Browse files
committed
fix: use render pattern
1 parent 7068373 commit 7151974

File tree

6 files changed

+25
-54
lines changed

6 files changed

+25
-54
lines changed

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,18 @@ function Diagnostics({additionalTenantProps}: DiagnosticsProps) {
214214
scrollContainerRef: containerRef,
215215
});
216216
}
217+
case TENANT_DIAGNOSTICS_TABS_IDS.monitoring: {
218+
return uiFactory.renderMonitoring?.({
219+
type,
220+
subType,
221+
database,
222+
path,
223+
databaseFullPath,
224+
additionalTenantProps,
225+
scrollContainerRef: containerRef,
226+
});
227+
}
217228
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-
234229
return <div>{i18n('no-data')}</div>;
235230
}
236231
}

src/containers/Tenant/Diagnostics/DiagnosticsPages.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ 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';
1110
import {uiFactory} from '../../../uiFactory/uiFactory';
1211
import type {TenantQuery} from '../TenantPages';
1312
import {TenantTabsGroups} from '../TenantPages';
@@ -112,6 +111,11 @@ const operations = {
112111
title: 'Operations',
113112
};
114113

114+
const monitoring = {
115+
id: TENANT_DIAGNOSTICS_TABS_IDS.monitoring,
116+
title: 'Monitoring',
117+
};
118+
115119
const ASYNC_REPLICATION_PAGES = [overview, tablets, describe, access];
116120

117121
const TRANSFER_PAGES = [overview, tablets, describe, access];
@@ -235,33 +239,13 @@ export const getPagesByType = (
235239
const dbContext = isDatabaseEntityType(type) || options?.isTopLevel;
236240
const seeded = dbContext ? getDatabasePages(options?.databaseType) : base;
237241

238-
const filtered = applyFilters(seeded, type, options);
242+
const result = applyFilters(seeded, type, options);
239243

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;
244+
// Add monitoring tab as second tab if renderMonitoring is available
245+
if (uiFactory.renderMonitoring) {
246+
result.splice(1, 0, monitoring);
248247
}
249248

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-
265249
return result;
266250
};
267251

src/lib.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,3 @@ 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/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export const TENANT_DIAGNOSTICS_TABS_IDS = {
3030
operations: 'operations',
3131
access: 'access',
3232
backups: 'backups',
33+
monitoring: 'monitoring',
3334
} as const;
3435

3536
export const TENANT_SUMMARY_TABS_IDS = {

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> | string;
17+
export type TenantDiagnosticsTab = ValueOf<typeof TENANT_DIAGNOSTICS_TABS_IDS>;
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: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export interface UIFactory<H extends string = CommonIssueType> {
3636

3737
renderBackups?: RenderBackups;
3838
renderEvents?: RenderEvents;
39-
additionalDiagnosticsTabs?: AdditionalDiagnosticsTab[];
39+
renderMonitoring?: RenderMonitoring;
4040
clusterOrDatabaseAccessError?: Partial<EmptyStateProps>;
4141

4242
healthcheck: {
@@ -88,20 +88,12 @@ export type RenderEvents = (props: {
8888
scrollContainerRef: React.RefObject<HTMLDivElement>;
8989
}) => React.ReactNode;
9090

91-
export type DiagnosticsTabProps = {
91+
export type RenderMonitoring = (props: {
9292
type?: EPathType;
9393
subType?: EPathSubType;
9494
database: string;
9595
path: string;
9696
databaseFullPath?: string;
9797
additionalTenantProps?: AdditionalTenantsProps;
9898
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-
};
99+
}) => React.ReactNode;

0 commit comments

Comments
 (0)