File tree 5 files changed +24
-17
lines changed
5 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,8 @@ export function useNavigationMenuItems() {
26
26
const location = useLocation ( ) ;
27
27
const history = useHistory ( ) ;
28
28
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 ) ;
31
31
32
32
const { pathname} = location ;
33
33
const queryParams = parseQuery ( location ) ;
Original file line number Diff line number Diff line change 1
1
import { useThemeValue } from '@gravity-ui/uikit' ;
2
- import { useLocation } from 'react-router' ;
3
2
4
- import { parseQuery } from '../../../routes' ;
5
3
import { TENANT_PAGES_IDS } from '../../../store/reducers/tenant/constants' ;
6
4
import type { AdditionalNodesProps , AdditionalTenantsProps } from '../../../types/additionalProps' ;
7
5
import type { EPathType } from '../../../types/api/schema' ;
8
6
import { 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' ;
11
8
import Diagnostics from '../Diagnostics/Diagnostics' ;
12
9
import { Query } from '../Query/Query' ;
13
10
@@ -23,13 +20,9 @@ interface ObjectGeneralProps {
23
20
}
24
21
25
22
function ObjectGeneral ( props : ObjectGeneralProps ) {
26
- const location = useLocation ( ) ;
27
23
const theme = useThemeValue ( ) ;
28
24
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 ) ;
33
26
34
27
const renderTabContent = ( ) => {
35
28
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';
23
23
export type SettingsObject = Record < string , unknown > ;
24
24
25
25
/** User settings keys and their default values */
26
- export const DEFAULT_USER_SETTINGS : SettingsObject = {
26
+ export const DEFAULT_USER_SETTINGS = {
27
27
[ THEME_KEY ] : 'system' ,
28
28
[ LANGUAGE_KEY ] : undefined ,
29
29
[ INVERTED_DISKS_KEY ] : false ,
@@ -40,7 +40,7 @@ export const DEFAULT_USER_SETTINGS: SettingsObject = {
40
40
[ USE_CLUSTER_BALANCER_AS_BACKEND_KEY ] : true ,
41
41
[ ENABLE_AUTOCOMPLETE ] : false ,
42
42
[ AUTOCOMPLETE_ON_ENTER ] : true ,
43
- } ;
43
+ } as const satisfies SettingsObject ;
44
44
45
45
class SettingsManager {
46
46
/**
Original file line number Diff line number Diff line change 1
1
import { createSlice } from '@reduxjs/toolkit' ;
2
2
import type { PayloadAction } from '@reduxjs/toolkit' ;
3
3
4
+ import { DEFAULT_USER_SETTINGS , settingsManager } from '../../../services/settings' ;
5
+ import { TENANT_INITIAL_PAGE_KEY } from '../../../utils/constants' ;
4
6
import { api } from '../api' ;
5
7
8
+ import { tenantPageSchema } from './types' ;
6
9
import type {
7
10
TenantDiagnosticsTab ,
8
11
TenantMetricsTab ,
@@ -12,9 +15,17 @@ import type {
12
15
TenantSummaryTab ,
13
16
} from './types' ;
14
17
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
+
15
26
const slice = createSlice ( {
16
27
name : 'tenant' ,
17
- initialState : { } as TenantState ,
28
+ initialState,
18
29
reducers : {
19
30
setTenantPage : ( state , action : PayloadAction < TenantPage > ) => {
20
31
state . tenantPage = action . payload ;
Original file line number Diff line number Diff line change
1
+ import { z } from 'zod' ;
2
+
1
3
import type { ValueOf } from '../../../types/common' ;
2
4
5
+ import { TENANT_PAGES_IDS } from './constants' ;
3
6
import type {
4
7
TENANT_DIAGNOSTICS_TABS_IDS ,
5
8
TENANT_METRICS_TABS_IDS ,
6
- TENANT_PAGES_IDS ,
7
9
TENANT_QUERY_TABS_ID ,
8
10
TENANT_SUMMARY_TABS_IDS ,
9
11
} from './constants' ;
10
12
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 > ;
12
15
13
16
export type TenantQueryTab = ValueOf < typeof TENANT_QUERY_TABS_ID > ;
14
17
export type TenantDiagnosticsTab = ValueOf < typeof TENANT_DIAGNOSTICS_TABS_IDS > ;
15
18
export type TenantSummaryTab = ValueOf < typeof TENANT_SUMMARY_TABS_IDS > ;
16
19
export type TenantMetricsTab = ValueOf < typeof TENANT_METRICS_TABS_IDS > ;
17
20
18
21
export interface TenantState {
19
- tenantPage ? : TenantPage ;
22
+ tenantPage : TenantPage ;
20
23
queryTab ?: TenantQueryTab ;
21
24
diagnosticsTab ?: TenantDiagnosticsTab ;
22
25
summaryTab ?: TenantSummaryTab ;
You can’t perform that action at this time.
0 commit comments