Skip to content

Commit 88fd814

Browse files
fix(Tenant): fix tabs reset on schema object change
1 parent 9a502d2 commit 88fd814

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

src/containers/Tenant/Tenant.tsx

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import {PageError} from '../../components/Errors/PageError/PageError';
77
import {LoaderWrapper} from '../../components/LoaderWrapper/LoaderWrapper';
88
import SplitPane from '../../components/SplitPane';
99
import {setHeaderBreadcrumbs} from '../../store/reducers/header/header';
10-
import {overviewApi} from '../../store/reducers/overview/overview';
10+
import {selectSchemaData} from '../../store/reducers/schema/schema';
1111
import type {AdditionalNodesProps, AdditionalTenantsProps} from '../../types/additionalProps';
1212
import {cn} from '../../utils/cn';
1313
import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../../utils/constants';
14-
import {useAutoRefreshInterval, useTypedDispatch} from '../../utils/hooks';
14+
import {useTypedDispatch, useTypedSelector} from '../../utils/hooks';
1515
import {isAccessError} from '../../utils/response';
1616

1717
import ObjectGeneral from './ObjectGeneral/ObjectGeneral';
@@ -42,7 +42,6 @@ interface TenantProps {
4242
}
4343

4444
export function Tenant(props: TenantProps) {
45-
const [autoRefreshInterval] = useAutoRefreshInterval();
4645
const [summaryVisibilityState, dispatchSummaryVisibilityAction] = React.useReducer(
4746
paneVisibilityToggleReducerCreator(DEFAULT_IS_TENANT_SUMMARY_COLLAPSED),
4847
undefined,
@@ -90,18 +89,12 @@ export function Tenant(props: TenantProps) {
9089

9190
const path = schema ?? tenantName;
9291

93-
const {
94-
currentData: currentItem,
95-
error,
96-
isLoading,
97-
} = overviewApi.useGetOverviewQuery(
98-
{path, database: tenantName},
99-
{
100-
pollingInterval: autoRefreshInterval,
101-
},
92+
const {data, isLoading, error} = useTypedSelector((state) =>
93+
selectSchemaData(state, path, tenantName),
10294
);
95+
10396
const {PathType: currentPathType, PathSubType: currentPathSubType} =
104-
currentItem?.PathDescription?.Self || {};
97+
data?.[path]?.PathDescription?.Self || {};
10598

10699
const showBlockingError = isAccessError(error);
107100

src/store/reducers/schema/schema.ts

Lines changed: 16 additions & 1 deletion
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,17 @@ 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 selectSchemaData = createSelector(
122+
(state: RootState) => state,
123+
(_state: RootState, path: string, database: string) => getSchemaSelector(path, database),
124+
(state, selectSchema) => {
125+
return selectSchema(state);
126+
},
127+
);

0 commit comments

Comments
 (0)