Skip to content

Commit 4dd053d

Browse files
fix(Tenant): fix tabs reset on schema object change (#1881)
1 parent a0ba20f commit 4dd053d

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/containers/Tenant/Tenant.tsx

+14-3
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
88
import SplitPane from '../../components/SplitPane';
99
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
1010
import {overviewApi} from '../../store/reducers/overview/overview';
11+
import {selectSchemaObjectData} from '../../store/reducers/schema/schema';
1112
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/additionalProps';
1213
import {cn} from '../../utils/cn';
1314
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
14-
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
15+
import {useAutoRefreshInterval, useTypedDispatch, useTypedSelector} from '../../utils/hooks';
1516
import {isAccessError} from '../../utils/response';
1617

1718
import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
@@ -100,8 +101,18 @@ export function Tenant(props: TenantProps) {
100101
pollingInterval: autoRefreshInterval,
101102
},
102103
);
103-
const {PathType: currentPathType, PathSubType: currentPathSubType} =
104-
currentItem?.PathDescription?.Self || {};
104+
105+
const preloadedData = useTypedSelector((state) =>
106+
selectSchemaObjectData(state, path, tenantName),
107+
);
108+
109+
// Use preloaded data if there is no current item data yet
110+
const currentPathType =
111+
currentItem?.PathDescription?.Self?.PathType ??
112+
preloadedData?.PathDescription?.Self?.PathType;
113+
const currentPathSubType =
114+
currentItem?.PathDescription?.Self?.PathSubType ??
115+
preloadedData?.PathDescription?.Self?.PathSubType;
105116

106117
const showBlockingError = isAccessError(error);
107118

src/store/reducers/schema/schema.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import React from 'react';
22

3-
import {createSlice} from '@reduxjs/toolkit';
3+
import {createSelector, createSlice} from '@reduxjs/toolkit';
44
import type {PayloadAction} from '@reduxjs/toolkit';
55

66
import type {TEvDescribeSchemeResult} from '../../../types/api/schema';
7+
import type {RootState} from '../../defaultStore';
78
import {api} from '../api';
89

910
const initialState = {
@@ -110,3 +111,18 @@ export function useGetSchemaQuery({path, database}: {path: string; database: str
110111

111112
return {data, isLoading, error: currentPathError};
112113
}
114+
115+
const getSchemaSelector = createSelector(
116+
(path: string) => path,
117+
(_path: string, database: string) => database,
118+
(path, database) => schemaApi.endpoints.getSchema.select({path, database}),
119+
);
120+
121+
export const selectSchemaObjectData = createSelector(
122+
(state: RootState) => state,
123+
(_state: RootState, path: string) => path,
124+
(_state: RootState, path: string, database: string) => getSchemaSelector(path, database),
125+
(state, path, selectSchemaData) => {
126+
return selectSchemaData(state).data?.[path];
127+
},
128+
);

0 commit comments

Comments
 (0)