File tree Expand file tree Collapse file tree 5 files changed +24
-17
lines changed Expand file tree Collapse file tree 5 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ export function useNavigationMenuItems() {
2626 const location = useLocation ( ) ;
2727 const history = useHistory ( ) ;
2828
29- const [ initialTenantPage , setInitialTenantPage ] = useSetting < string > ( TENANT_INITIAL_PAGE_KEY ) ;
30- const { tenantPage = initialTenantPage } = useTypedSelector ( ( state ) => state . tenant ) ;
29+ const [ , setInitialTenantPage ] = useSetting < string > ( TENANT_INITIAL_PAGE_KEY ) ;
30+ const { tenantPage} = useTypedSelector ( ( state ) => state . tenant ) ;
3131
3232 const { pathname} = location ;
3333 const queryParams = parseQuery ( location ) ;
Original file line number Diff line number Diff line change 11import { useThemeValue } from '@gravity-ui/uikit' ;
2- import { useLocation } from 'react-router' ;
32
4- import { parseQuery } from '../../../routes' ;
53import { TENANT_PAGES_IDS } from '../../../store/reducers/tenant/constants' ;
64import type { AdditionalNodesProps , AdditionalTenantsProps } from '../../../types/additionalProps' ;
75import type { EPathType } from '../../../types/api/schema' ;
86import { cn } from '../../../utils/cn' ;
9- import { TENANT_INITIAL_PAGE_KEY } from '../../../utils/constants' ;
10- import { useSetting } from '../../../utils/hooks' ;
7+ import { useTypedSelector } from '../../../utils/hooks' ;
118import Diagnostics from '../Diagnostics/Diagnostics' ;
129import { Query } from '../Query/Query' ;
1310
@@ -23,13 +20,9 @@ interface ObjectGeneralProps {
2320}
2421
2522function ObjectGeneral ( props : ObjectGeneralProps ) {
26- const location = useLocation ( ) ;
2723 const theme = useThemeValue ( ) ;
2824
29- const [ initialPage ] = useSetting < string > ( TENANT_INITIAL_PAGE_KEY ) ;
30-
31- const queryParams = parseQuery ( location ) ;
32- const { tenantPage = initialPage } = queryParams ;
25+ const { tenantPage} = useTypedSelector ( ( state ) => state . tenant ) ;
3326
3427 const renderTabContent = ( ) => {
3528 const { type, additionalTenantProps, additionalNodesProps, tenantName} = props ;
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ import {parseJson} from '../utils/utils';
2323export type SettingsObject = Record < string , unknown > ;
2424
2525/** User settings keys and their default values */
26- export const DEFAULT_USER_SETTINGS : SettingsObject = {
26+ export const DEFAULT_USER_SETTINGS = {
2727 [ THEME_KEY ] : 'system' ,
2828 [ LANGUAGE_KEY ] : undefined ,
2929 [ INVERTED_DISKS_KEY ] : false ,
@@ -40,7 +40,7 @@ export const DEFAULT_USER_SETTINGS: SettingsObject = {
4040 [ USE_CLUSTER_BALANCER_AS_BACKEND_KEY ] : true ,
4141 [ ENABLE_AUTOCOMPLETE ] : false ,
4242 [ AUTOCOMPLETE_ON_ENTER ] : true ,
43- } ;
43+ } as const satisfies SettingsObject ;
4444
4545class SettingsManager {
4646 /**
Original file line number Diff line number Diff line change 11import { createSlice } from '@reduxjs/toolkit' ;
22import type { PayloadAction } from '@reduxjs/toolkit' ;
33
4+ import { DEFAULT_USER_SETTINGS , settingsManager } from '../../../services/settings' ;
5+ import { TENANT_INITIAL_PAGE_KEY } from '../../../utils/constants' ;
46import { api } from '../api' ;
57
8+ import { tenantPageSchema } from './types' ;
69import type {
710 TenantDiagnosticsTab ,
811 TenantMetricsTab ,
@@ -12,9 +15,17 @@ import type {
1215 TenantSummaryTab ,
1316} from './types' ;
1417
18+ const tenantPage = tenantPageSchema
19+ . catch ( DEFAULT_USER_SETTINGS [ TENANT_INITIAL_PAGE_KEY ] )
20+ . parse ( settingsManager . readUserSettingsValue ( TENANT_INITIAL_PAGE_KEY ) ) ;
21+
22+ const initialState : TenantState = {
23+ tenantPage,
24+ } ;
25+
1526const slice = createSlice ( {
1627 name : 'tenant' ,
17- initialState : { } as TenantState ,
28+ initialState,
1829 reducers : {
1930 setTenantPage : ( state , action : PayloadAction < TenantPage > ) => {
2031 state . tenantPage = action . payload ;
Original file line number Diff line number Diff line change 1+ import { z } from 'zod' ;
2+
13import type { ValueOf } from '../../../types/common' ;
24
5+ import { TENANT_PAGES_IDS } from './constants' ;
36import type {
47 TENANT_DIAGNOSTICS_TABS_IDS ,
58 TENANT_METRICS_TABS_IDS ,
6- TENANT_PAGES_IDS ,
79 TENANT_QUERY_TABS_ID ,
810 TENANT_SUMMARY_TABS_IDS ,
911} from './constants' ;
1012
11- export type TenantPage = ValueOf < typeof TENANT_PAGES_IDS > ;
13+ export const tenantPageSchema = z . nativeEnum ( TENANT_PAGES_IDS ) ;
14+ export type TenantPage = z . infer < typeof tenantPageSchema > ;
1215
1316export type TenantQueryTab = ValueOf < typeof TENANT_QUERY_TABS_ID > ;
1417export type TenantDiagnosticsTab = ValueOf < typeof TENANT_DIAGNOSTICS_TABS_IDS > ;
1518export type TenantSummaryTab = ValueOf < typeof TENANT_SUMMARY_TABS_IDS > ;
1619export type TenantMetricsTab = ValueOf < typeof TENANT_METRICS_TABS_IDS > ;
1720
1821export interface TenantState {
19- tenantPage ? : TenantPage ;
22+ tenantPage : TenantPage ;
2023 queryTab ?: TenantQueryTab ;
2124 diagnosticsTab ?: TenantDiagnosticsTab ;
2225 summaryTab ?: TenantSummaryTab ;
You can’t perform that action at this time.
0 commit comments