Skip to content

Commit ccaafe4

Browse files
fix(Diagnostics): remove unneded tenantInfo fetch (#420)
* refactor(Overview): use separate reducer * fix(Diagnostics): remove unnneded tenantInfo fetch * fixup! refactor(Overview): use separate reducer
1 parent 2d807d6 commit ccaafe4

File tree

9 files changed

+203
-99
lines changed

9 files changed

+203
-99
lines changed

src/containers/Tenant/Diagnostics/DetailedOverview/DetailedOverview.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ $section-title-line-height: 24px;
44
.kv-detailed-overview {
55
display: flex;
66
gap: 20px;
7+
8+
height: 100%;
9+
710
&__section {
811
display: flex;
912
overflow-x: hidden;

src/containers/Tenant/Diagnostics/Diagnostics.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ const b = cn('kv-tenant-diagnostics');
4949

5050
function Diagnostics(props: DiagnosticsProps) {
5151
const dispatch = useDispatch();
52-
const {currentSchemaPath, autorefresh} = useSelector((state: any) => state.schema);
53-
const {diagnosticsTab = TENANT_DIAGNOSTICS_TABS_IDS.overview, wasLoaded} = useTypedSelector(
52+
const {currentSchemaPath, autorefresh, wasLoaded} = useSelector((state: any) => state.schema);
53+
const {diagnosticsTab = TENANT_DIAGNOSTICS_TABS_IDS.overview} = useTypedSelector(
5454
(state) => state.tenant,
5555
);
5656

src/containers/Tenant/Diagnostics/Overview/ChangefeedInfo/ChangefeedInfo.tsx

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from '../../../../../components/InfoViewer/formatters';
88

99
import {useTypedSelector} from '../../../../../utils/hooks';
10-
import {selectSchemaData} from '../../../../../store/reducers/schema/schema';
1110

1211
import {getEntityName} from '../../../utils';
1312

@@ -42,27 +41,26 @@ const prepareChangefeedInfo = (
4241

4342
interface ChangefeedProps {
4443
data?: TEvDescribeSchemeResult;
45-
childrenPaths?: string[];
44+
topic?: TEvDescribeSchemeResult;
4645
}
4746

4847
/** Displays overview for CDCStream EPathType */
49-
export const ChangefeedInfo = ({data, childrenPaths}: ChangefeedProps) => {
48+
export const ChangefeedInfo = ({data, topic}: ChangefeedProps) => {
5049
const entityName = getEntityName(data?.PathDescription);
5150

5251
const {error: schemaError} = useTypedSelector((state) => state.schema);
53-
const pqGroupData = useTypedSelector((state) => selectSchemaData(state, childrenPaths?.[0]));
5452

5553
if (schemaError) {
5654
return <div className="error">{schemaError.statusText}</div>;
5755
}
5856

59-
if (!data || !pqGroupData) {
57+
if (!data || !topic) {
6058
return <div className="error">No {entityName} data</div>;
6159
}
6260

6361
return (
6462
<div>
65-
<InfoViewer title={entityName} info={prepareChangefeedInfo(data, pqGroupData)} />
63+
<InfoViewer title={entityName} info={prepareChangefeedInfo(data, topic)} />
6664
<TopicStats />
6765
</div>
6866
);
Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,88 @@
11
import {ReactNode, useCallback} from 'react';
2-
import {shallowEqual, useDispatch, useSelector} from 'react-redux';
2+
import {shallowEqual, useDispatch} from 'react-redux';
33

44
import {Loader} from '../../../../components/Loader';
5-
6-
//@ts-ignore
75
import {TableIndexInfo} from '../../../../components/InfoViewer/schemaInfo';
86
import {ResponseError} from '../../../../components/Errors/ResponseError';
97

10-
import {TopicInfo} from './TopicInfo';
11-
import {ChangefeedInfo} from './ChangefeedInfo';
12-
import {TableInfo} from './TableInfo';
13-
148
import {EPathType} from '../../../../types/api/schema';
9+
import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
10+
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
11+
import {getTopic} from '../../../../store/reducers/topic';
12+
import {
13+
getOlapStats,
14+
resetLoadingState as resetOlapLoadingState,
15+
} from '../../../../store/reducers/olapStats';
16+
import {
17+
getOverview,
18+
getOverviewBatched,
19+
setCurrentOverviewPath,
20+
setDataWasNotLoaded,
21+
} from '../../../../store/reducers/overview/overview';
22+
1523
import {
1624
isEntityWithMergedImplementation,
1725
isColumnEntityType,
1826
isTableType,
1927
isPathTypeWithTopic,
2028
} from '../../utils/schema';
21-
//@ts-ignore
22-
import {
23-
getSchema,
24-
getSchemaBatched,
25-
resetLoadingState,
26-
selectSchemaMergedChildrenPaths,
27-
} from '../../../../store/reducers/schema/schema';
28-
import {getTopic} from '../../../../store/reducers/topic';
29-
//@ts-ignore
30-
import {
31-
getOlapStats,
32-
resetLoadingState as resetOlapLoadingState,
33-
} from '../../../../store/reducers/olapStats';
34-
import {useAutofetcher, useTypedSelector} from '../../../../utils/hooks';
29+
30+
import {TopicInfo} from './TopicInfo';
31+
import {ChangefeedInfo} from './ChangefeedInfo';
32+
import {TableInfo} from './TableInfo';
3533

3634
interface OverviewProps {
3735
type?: EPathType;
38-
className?: string;
3936
tenantName?: string;
4037
}
4138

42-
function Overview({type, tenantName, className}: OverviewProps) {
39+
function Overview({type, tenantName}: OverviewProps) {
4340
const dispatch = useDispatch();
4441

42+
const {autorefresh, currentSchemaPath} = useTypedSelector((state) => state.schema);
4543
const {
46-
currentSchema: currentItem = {},
47-
loading: schemaLoading,
48-
wasLoaded,
49-
autorefresh,
50-
currentSchemaPath,
51-
error,
52-
} = useSelector((state: any) => state.schema);
53-
54-
const {data: {result: olapStats} = {result: undefined}, loading: olapStatsLoading} =
55-
useTypedSelector((state) => state.olapStats);
56-
57-
const loading = schemaLoading || olapStatsLoading;
44+
data,
45+
additionalData,
46+
loading: overviewLoading,
47+
wasLoaded: overviewWasLoaded,
48+
error: overviewError,
49+
} = useTypedSelector((state) => state.overview);
50+
const {
51+
data: {result: olapStats} = {result: undefined},
52+
loading: olapStatsLoading,
53+
wasLoaded: olapStatsWasLoaded,
54+
} = useTypedSelector((state) => state.olapStats);
5855

5956
const isEntityWithMergedImpl = isEntityWithMergedImplementation(type);
6057

61-
// There is a circular dependency here. Fetch data depends on children paths
62-
// When data in store updated on fetch request,
63-
// new object is set there, so source children array is updated
64-
// This updates selector, the selector returns a new array, and data is fetched again
65-
// To prevent it, shallowEqual, which compares array content, was added
58+
// shalloEqual prevents rerenders when new schema data is loaded
6659
const mergedChildrenPaths = useTypedSelector(
6760
(state) => selectSchemaMergedChildrenPaths(state, currentSchemaPath, type),
6861
shallowEqual,
6962
);
7063

64+
const entityLoading =
65+
(overviewLoading && !overviewWasLoaded) || (olapStatsLoading && !olapStatsWasLoaded);
66+
const entityNotReady = isEntityWithMergedImpl && !mergedChildrenPaths;
67+
7168
const fetchData = useCallback(
7269
(isBackground: boolean) => {
73-
if (!isBackground) {
74-
dispatch(resetLoadingState());
70+
const schemaPath = currentSchemaPath || tenantName;
71+
72+
if (!schemaPath) {
73+
return;
7574
}
7675

77-
const schemaPath = currentSchemaPath || tenantName;
76+
dispatch(setCurrentOverviewPath(schemaPath));
77+
78+
if (!isBackground) {
79+
dispatch(setDataWasNotLoaded());
80+
}
7881

7982
if (!isEntityWithMergedImpl) {
80-
dispatch(getSchema({path: schemaPath}));
83+
dispatch(getOverview({path: schemaPath}));
8184
} else if (mergedChildrenPaths) {
82-
dispatch(getSchemaBatched([schemaPath, ...mergedChildrenPaths]));
85+
dispatch(getOverviewBatched([schemaPath, ...mergedChildrenPaths]));
8386
}
8487

8588
if (isTableType(type) && isColumnEntityType(type)) {
@@ -113,32 +116,32 @@ function Overview({type, tenantName, className}: OverviewProps) {
113116
[EPathType.EPathTypeDir]: undefined,
114117
[EPathType.EPathTypeTable]: undefined,
115118
[EPathType.EPathTypeSubDomain]: undefined,
116-
[EPathType.EPathTypeTableIndex]: () => <TableIndexInfo data={currentItem} />,
119+
[EPathType.EPathTypeTableIndex]: () => <TableIndexInfo data={data} />,
117120
[EPathType.EPathTypeExtSubDomain]: undefined,
118121
[EPathType.EPathTypeColumnStore]: undefined,
119122
[EPathType.EPathTypeColumnTable]: undefined,
120123
[EPathType.EPathTypeCdcStream]: () => (
121-
<ChangefeedInfo data={currentItem} childrenPaths={mergedChildrenPaths} />
124+
<ChangefeedInfo data={data} topic={additionalData?.[0]} />
122125
),
123-
[EPathType.EPathTypePersQueueGroup]: () => <TopicInfo data={currentItem} />,
126+
[EPathType.EPathTypePersQueueGroup]: () => <TopicInfo data={data} />,
124127
};
125128

126129
return (
127130
(type && pathTypeToComponent[type]?.()) || (
128-
<TableInfo data={currentItem} type={type} olapStats={olapStats} />
131+
<TableInfo data={data} type={type} olapStats={olapStats} />
129132
)
130133
);
131134
};
132135

133-
if ((loading && !wasLoaded) || (isEntityWithMergedImpl && !mergedChildrenPaths)) {
136+
if (entityLoading || entityNotReady) {
134137
return <Loader size="m" />;
135138
}
136139

137-
if (error) {
138-
return <ResponseError error={error} />;
140+
if (overviewError) {
141+
return <ResponseError error={overviewError} />;
139142
}
140143

141-
return <div className={className}>{renderContent()}</div>;
144+
return <div>{renderContent()}</div>;
142145
}
143146

144147
export default Overview;

src/containers/Tenant/Tenant.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import {DEFAULT_IS_TENANT_SUMMARY_COLLAPSED, DEFAULT_SIZE_TENANT_KEY} from '../.
1010
import {useTypedSelector} from '../../utils/hooks';
1111
import routes, {createHref} from '../../routes';
1212
import {setHeader} from '../../store/reducers/header';
13-
import {disableAutorefresh, getSchema, resetLoadingState} from '../../store/reducers/schema/schema';
13+
import {disableAutorefresh, getSchema} from '../../store/reducers/schema/schema';
1414
import {getSchemaAcl} from '../../store/reducers/schemaAcl/schemaAcl';
15-
import {getTenantInfo, clearTenant} from '../../store/reducers/tenant/tenant';
1615

1716
import SplitPane from '../../components/SplitPane';
1817
import {AccessDenied} from '../../components/Errors/403';
@@ -64,7 +63,6 @@ function Tenant(props: TenantProps) {
6463
const {PathType: currentPathType, PathSubType: currentPathSubType} =
6564
(currentItem as TEvDescribeSchemeResult).PathDescription?.Self || {};
6665

67-
const {error: {status: tenantStatus = 200} = {}} = useTypedSelector((state) => state.tenant);
6866
const {error: {status: schemaStatus = 200} = {}} = useTypedSelector((state) => state.schema);
6967

7068
const dispatch = useDispatch();
@@ -84,7 +82,6 @@ function Tenant(props: TenantProps) {
8482
}, [tenantName, dispatch]);
8583

8684
useEffect(() => {
87-
dispatch(resetLoadingState());
8885
dispatch(getSchema({path: currentSchemaPath}));
8986
dispatch(getSchemaAcl({path: currentSchemaPath}));
9087
}, [currentSchemaPath, dispatch]);
@@ -95,7 +92,6 @@ function Tenant(props: TenantProps) {
9592

9693
useEffect(() => {
9794
if (tenantName) {
98-
dispatch(getTenantInfo({path: tenantName}));
9995
dispatch(
10096
setHeader([
10197
{
@@ -111,9 +107,6 @@ function Tenant(props: TenantProps) {
111107
]),
112108
);
113109
}
114-
return () => {
115-
dispatch(clearTenant());
116-
};
117110
}, [tenantName, dispatch]);
118111

119112
const onCollapseSummaryHandler = () => {
@@ -127,7 +120,7 @@ function Tenant(props: TenantProps) {
127120
dispatchSummaryVisibilityAction(PaneVisibilityActionTypes.clear);
128121
};
129122

130-
const showBlockingError = tenantStatus === 403 || schemaStatus === 403;
123+
const showBlockingError = schemaStatus === 403;
131124

132125
return (
133126
<div className={b()}>

src/store/reducers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import tooltip from './tooltip';
1010
import tablets from './tablets';
1111
import heatmap from './heatmap';
1212
import schema from './schema/schema';
13+
import overview from './overview/overview';
1314
import host from './host';
1415
import network from './network/network';
1516
import tenants from './tenants/tenants';
@@ -46,6 +47,7 @@ export const rootReducer = {
4647
tooltip,
4748
tablets,
4849
schema,
50+
overview,
4951
olapStats,
5052
host,
5153
network,

0 commit comments

Comments
 (0)