@@ -4,16 +4,16 @@ import type {LabelProps} from '@gravity-ui/uikit';
44import { useLocation } from 'react-router-dom' ;
55
66import { getTenantPath , parseQuery } from '../../../routes' ;
7- import {
8- TENANT_DIAGNOSTICS_TABS_IDS ,
9- TENANT_PAGE ,
10- TENANT_PAGES_IDS ,
11- } from '../../../store/reducers/tenant/constants' ;
12- import type { TenantDiagnosticsTab , TenantPage } from '../../../store/reducers/tenant/types' ;
7+ import { TENANT_DIAGNOSTICS_TABS_IDS , TENANT_PAGE } from '../../../store/reducers/tenant/constants' ;
8+ import type { TenantDiagnosticsTab } from '../../../store/reducers/tenant/types' ;
139import { EPathSubType , EPathType } from '../../../types/api/schema' ;
1410import type { ETenantType } from '../../../types/api/tenant' ;
1511import type { TenantQuery } from '../TenantPages' ;
1612import { TenantTabsGroups } from '../TenantPages' ;
13+ import {
14+ V2_DATABASE_PAGE_DIAGNOSTICS_TABS ,
15+ getTenantPageForDiagnosticsTab ,
16+ } from '../utils/diagnosticsNavigation' ;
1717import { useNavigationV2Enabled } from '../utils/useNavigationV2Enabled' ;
1818
1919import i18n from './i18n' ;
@@ -163,7 +163,18 @@ const ALL_DB_PAGES = [
163163 backups ,
164164] ;
165165
166- const DB_PAGES = [ database , monitoring , topQueries , storage , network , configs , operations , backups ] ;
166+ const databasePageById = {
167+ [ TENANT_DIAGNOSTICS_TABS_IDS . database ] : database ,
168+ [ TENANT_DIAGNOSTICS_TABS_IDS . monitoring ] : monitoring ,
169+ [ TENANT_DIAGNOSTICS_TABS_IDS . topQueries ] : topQueries ,
170+ [ TENANT_DIAGNOSTICS_TABS_IDS . storage ] : storage ,
171+ [ TENANT_DIAGNOSTICS_TABS_IDS . network ] : network ,
172+ [ TENANT_DIAGNOSTICS_TABS_IDS . configs ] : configs ,
173+ [ TENANT_DIAGNOSTICS_TABS_IDS . operations ] : operations ,
174+ [ TENANT_DIAGNOSTICS_TABS_IDS . backups ] : backups ,
175+ } satisfies Record < ( typeof V2_DATABASE_PAGE_DIAGNOSTICS_TABS ) [ number ] , Page > ;
176+
177+ const DB_PAGES = V2_DATABASE_PAGE_DIAGNOSTICS_TABS . map ( ( id ) => databasePageById [ id ] ) ;
167178
168179const DIAGNOSTICS_DB_PAGES = [ overview , topShards , nodes , tablets , describe , access ] ;
169180
@@ -328,39 +339,13 @@ export const getPagesByType = (
328339 return applyFilters ( seeded , options ) ;
329340} ;
330341
331- // In tenant navigation v2 the database-overview tabs are split across two
332- // top-level pages: the "stats"/management tabs (topQueries, storage, network,
333- // monitoring, configs, operations, backups) live on `databasePage=database`,
334- // while the rest (overview, topShards, nodes, tablets, describe, access) live
335- // on `databasePage=diagnostics`. We have to route every "See all" link to the
336- // correct top-level page, otherwise the target tab is missing from the active
337- // page and Diagnostics silently falls back to its first tab. In v1 everything
338- // lives under `databasePage=diagnostics`.
339- //
340- // Derive the set from the same DB_PAGES list used to render navigation, so the
341- // two stay in sync automatically if pages are moved between sections later.
342- // Serverless drops a few tabs from DB_PAGES (storage, network, nodes), but the
343- // set is only used to *decide which top-level page hosts a tab*; missing tabs
344- // just won't be rendered on either page, so we can safely use the regular-DB
345- // arrays without branching on databaseType.
346- const V2_DATABASE_PAGE_TABS = new Set < string > ( DB_PAGES . map ( ( page ) => page . id ) ) ;
347-
348- function getTenantPageForTab ( tab : string , isV2Enabled : boolean ) : TenantPage {
349- if ( ! isV2Enabled ) {
350- return TENANT_PAGES_IDS . diagnostics ;
351- }
352- return V2_DATABASE_PAGE_TABS . has ( tab )
353- ? TENANT_PAGES_IDS . database
354- : TENANT_PAGES_IDS . diagnostics ;
355- }
356-
357342export const useDiagnosticsPageLinkGetter = ( ) => {
358343 const location = useLocation ( ) ;
359344 const queryParams = parseQuery ( location ) ;
360345 const isV2Enabled = useNavigationV2Enabled ( ) ;
361346
362347 const getLink = React . useCallback (
363- ( tab : string , params ?: TenantQuery ) => {
348+ ( tab : TenantDiagnosticsTab , params ?: TenantQuery ) => {
364349 return getTenantPath ( {
365350 ...queryParams ,
366351 ...params ,
@@ -371,7 +356,7 @@ export const useDiagnosticsPageLinkGetter = () => {
371356 // tab does not exist (and gets silently replaced by the first tab).
372357 // Spread after `params` so callers cannot accidentally override the
373358 // page/tab the helper is responsible for.
374- [ TENANT_PAGE ] : getTenantPageForTab ( tab , isV2Enabled ) ,
359+ [ TENANT_PAGE ] : getTenantPageForDiagnosticsTab ( tab , isV2Enabled ) ,
375360 [ TenantTabsGroups . diagnosticsTab ] : tab ,
376361 } ) ;
377362 } ,
0 commit comments