Skip to content

Commit 82531a5

Browse files
authored
fix: get info about topic children from overview (#1489)
1 parent 4c91b29 commit 82531a5

File tree

9 files changed

+168
-105
lines changed

9 files changed

+168
-105
lines changed

src/containers/Tenant/Diagnostics/Describe/Describe.tsx

+13-32
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import {ClipboardButton} from '@gravity-ui/uikit';
2-
import {skipToken} from '@reduxjs/toolkit/query';
32
import JSONTree from 'react-json-inspector';
43
import {shallowEqual} from 'react-redux';
54

65
import {ResponseError} from '../../../../components/Errors/ResponseError';
76
import {Loader} from '../../../../components/Loader';
8-
import {overviewApi} from '../../../../store/reducers/overview/overview';
9-
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
7+
import {
8+
selectSchemaMergedChildrenPaths,
9+
useGetMultiOverviewQuery,
10+
} from '../../../../store/reducers/overview/overview';
1011
import type {EPathType} from '../../../../types/api/schema';
11-
import type {IDescribeData} from '../../../../types/store/describe';
1212
import {cn} from '../../../../utils/cn';
1313
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1414
import {isEntityWithMergedImplementation} from '../../utils/schema';
@@ -26,8 +26,6 @@ interface IDescribeProps {
2626
type?: EPathType;
2727
}
2828

29-
const emptyObject: IDescribeData = {};
30-
3129
const Describe = ({path, database, type}: IDescribeProps) => {
3230
const [autoRefreshInterval] = useAutoRefreshInterval();
3331

@@ -44,37 +42,20 @@ const Describe = ({path, database, type}: IDescribeProps) => {
4442
} else if (mergedChildrenPaths) {
4543
paths = [path, ...mergedChildrenPaths];
4644
}
47-
const {currentDescribe, currentData, isFetching, error} = overviewApi.useGetOverviewQuery(
48-
paths.length ? {paths, database} : skipToken,
49-
{
50-
pollingInterval: autoRefreshInterval,
51-
selectFromResult: (props) => {
52-
const {currentData} = props;
53-
if (!currentData) {
54-
return {currentDescribe: emptyObject, ...props};
55-
}
56-
57-
const mergedData = [currentData.data, ...currentData.additionalData];
5845

59-
const data = mergedData.reduce<IDescribeData>((acc, item) => {
60-
if (item?.Path) {
61-
acc[item.Path] = item;
62-
}
63-
return acc;
64-
}, {});
65-
return {currentDescribe: data, ...props};
66-
},
67-
},
68-
);
69-
const loading = isFetching && currentData === undefined;
46+
const {mergedDescribe, loading, error} = useGetMultiOverviewQuery({
47+
paths,
48+
autoRefreshInterval,
49+
database,
50+
});
7051

7152
let preparedDescribeData: Object | undefined;
72-
if (currentDescribe) {
73-
const paths = Object.keys(currentDescribe);
53+
if (mergedDescribe) {
54+
const paths = Object.keys(mergedDescribe);
7455
if (paths.length === 1) {
75-
preparedDescribeData = currentDescribe[paths[0]];
56+
preparedDescribeData = mergedDescribe[paths[0]];
7657
} else {
77-
preparedDescribeData = currentDescribe;
58+
preparedDescribeData = mergedDescribe;
7859
}
7960
}
8061

src/containers/Tenant/Diagnostics/HotKeys/HotKeys.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,15 @@ export function HotKeys({path, database}: HotKeysProps) {
6262
const {currentData: data, isFetching, error} = hotKeysApi.useGetHotKeysQuery({path, database});
6363
const loading = isFetching && data === undefined;
6464
const [autoRefreshInterval] = useAutoRefreshInterval();
65-
const {currentData, isLoading: schemaLoading} = overviewApi.useGetOverviewQuery(
65+
const {currentData: schemaData, isLoading: schemaLoading} = overviewApi.useGetOverviewQuery(
6666
{
67-
paths: [path],
67+
path,
6868
database,
6969
},
7070
{
7171
pollingInterval: autoRefreshInterval,
7272
},
7373
);
74-
const {data: schemaData} = currentData ?? {};
7574
const keyColumnsIds = schemaData?.PathDescription?.Table?.KeyColumnNames;
7675

7776
const tableColumns = React.useMemo(() => {

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

+29-21
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import React from 'react';
22

3-
import {skipToken} from '@reduxjs/toolkit/query';
43
import {shallowEqual} from 'react-redux';
54

65
import {ResponseError} from '../../../../components/Errors/ResponseError';
76
import {TableIndexInfo} from '../../../../components/InfoViewer/schemaInfo';
87
import {Loader} from '../../../../components/Loader';
9-
import {overviewApi} from '../../../../store/reducers/overview/overview';
10-
import {selectSchemaMergedChildrenPaths} from '../../../../store/reducers/schema/schema';
8+
import {
9+
selectSchemaMergedChildrenPaths,
10+
useGetMultiOverviewQuery,
11+
} from '../../../../store/reducers/overview/overview';
1112
import {EPathType} from '../../../../types/api/schema';
1213
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
1314
import {ExternalDataSourceInfo} from '../../Info/ExternalDataSource/ExternalDataSource';
@@ -45,16 +46,17 @@ function Overview({type, path, database}: OverviewProps) {
4546
}
4647

4748
const {
48-
currentData,
49-
isFetching,
50-
error: overviewError,
51-
} = overviewApi.useGetOverviewQuery(paths.length ? {paths, database} : skipToken, {
52-
pollingInterval: autoRefreshInterval,
49+
mergedDescribe,
50+
loading: entityLoading,
51+
error,
52+
} = useGetMultiOverviewQuery({
53+
paths,
54+
database,
55+
autoRefreshInterval,
5356
});
54-
const overviewLoading = isFetching && currentData === undefined;
55-
const {data: rawData, additionalData} = currentData || {};
5657

57-
const entityLoading = overviewLoading;
58+
const rawData = mergedDescribe[path];
59+
5860
const entityNotReady = isEntityWithMergedImpl && !mergedChildrenPaths;
5961

6062
const renderContent = () => {
@@ -70,14 +72,20 @@ function Overview({type, path, database}: OverviewProps) {
7072
[EPathType.EPathTypeExtSubDomain]: undefined,
7173
[EPathType.EPathTypeColumnStore]: undefined,
7274
[EPathType.EPathTypeColumnTable]: undefined,
73-
[EPathType.EPathTypeCdcStream]: () => (
74-
<ChangefeedInfo
75-
path={path}
76-
database={database}
77-
data={data}
78-
topic={additionalData?.[0] ?? undefined}
79-
/>
80-
),
75+
[EPathType.EPathTypeCdcStream]: () => {
76+
const topicPath = mergedChildrenPaths?.[0];
77+
if (topicPath) {
78+
return (
79+
<ChangefeedInfo
80+
path={path}
81+
database={database}
82+
data={data}
83+
topic={mergedDescribe?.[topicPath] ?? undefined}
84+
/>
85+
);
86+
}
87+
return undefined;
88+
},
8189
[EPathType.EPathTypePersQueueGroup]: () => (
8290
<TopicInfo data={data} path={path} database={database} />
8391
),
@@ -96,8 +104,8 @@ function Overview({type, path, database}: OverviewProps) {
96104

97105
return (
98106
<React.Fragment>
99-
{overviewError ? <ResponseError error={overviewError} /> : null}
100-
{overviewError && !rawData ? null : renderContent()}
107+
{error ? <ResponseError error={error} /> : null}
108+
{error && !rawData ? null : renderContent()}
101109
</React.Fragment>
102110
);
103111
}

src/containers/Tenant/Diagnostics/TenantOverview/TenantOverview.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@ export function TenantOverview({
4545

4646
const tenantType = mapDatabaseTypeToDBName(Type);
4747
// FIXME: remove after correct data is added to tenantInfo
48-
const {currentData} = overviewApi.useGetOverviewQuery(
48+
const {currentData: tenantSchemaData} = overviewApi.useGetOverviewQuery(
4949
{
50-
paths: [tenantName],
50+
path: tenantName,
5151
database: tenantName,
5252
},
5353
{
5454
pollingInterval: autoRefreshInterval,
5555
},
5656
);
57-
const {data: tenantSchemaData} = currentData ?? {};
5857
const {Tables, Topics} =
5958
tenantSchemaData?.PathDescription?.DomainDescription?.DiskSpaceUsage || {};
6059

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -93,16 +93,15 @@ export function ObjectSummary({
9393
ignoreQueryPrefix: true,
9494
});
9595

96-
const {currentData} = overviewApi.useGetOverviewQuery(
96+
const {currentData: currentObjectData} = overviewApi.useGetOverviewQuery(
9797
{
98-
paths: [path],
98+
path,
9999
database: tenantName,
100100
},
101101
{
102102
pollingInterval: autoRefreshInterval,
103103
},
104104
);
105-
const {data: currentObjectData} = currentData ?? {};
106105
const currentSchemaData = currentObjectData?.PathDescription?.Self;
107106

108107
React.useEffect(() => {

src/containers/Tenant/Schema/SchemaViewer/SchemaViewer.tsx

+2-4
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,16 @@ interface SchemaViewerProps {
3838

3939
export const SchemaViewer = ({type, path, tenantName, extended = false}: SchemaViewerProps) => {
4040
const [autoRefreshInterval] = useAutoRefreshInterval();
41-
const {currentData, isLoading: loading} = overviewApi.useGetOverviewQuery(
41+
const {currentData: schemaData, isLoading: loading} = overviewApi.useGetOverviewQuery(
4242
{
43-
paths: [path],
43+
path,
4444
database: tenantName,
4545
},
4646
{
4747
pollingInterval: autoRefreshInterval,
4848
},
4949
);
5050

51-
const {data: schemaData} = currentData ?? {};
52-
5351
const viewSchemaRequestParams = isViewType(type) ? {path, database: tenantName} : skipToken;
5452

5553
const {data: viewColumnsData, isLoading: isViewSchemaLoading} =

src/containers/Tenant/Tenant.tsx

+6-3
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,16 @@ export function Tenant(props: TenantProps) {
7575

7676
const path = schema ?? tenantName;
7777

78-
const {currentData, error, isLoading} = overviewApi.useGetOverviewQuery(
79-
{paths: [path], database: tenantName},
78+
const {
79+
currentData: currentItem,
80+
error,
81+
isLoading,
82+
} = overviewApi.useGetOverviewQuery(
83+
{path, database: tenantName},
8084
{
8185
pollingInterval: autoRefreshInterval,
8286
},
8387
);
84-
const {data: currentItem} = currentData ?? {};
8588
const {PathType: currentPathType, PathSubType: currentPathSubType} =
8689
currentItem?.PathDescription?.Self || {};
8790

src/store/reducers/overview/overview.ts

+111-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
import {createSelector} from '@reduxjs/toolkit';
2+
import {skipToken} from '@reduxjs/toolkit/query';
3+
4+
import {isEntityWithMergedImplementation} from '../../../containers/Tenant/utils/schema';
5+
import type {EPathType} from '../../../types/api/schema';
6+
import type {IDescribeData} from '../../../types/store/describe';
7+
import type {RootState} from '../../defaultStore';
18
import {api} from '../api';
29

310
export const overviewApi = api.injectEndpoints({
411
endpoints: (build) => ({
5-
getOverview: build.query({
12+
getMultiOverview: build.query({
613
queryFn: async ({paths, database}: {paths: string[]; database: string}, {signal}) => {
714
try {
8-
const [data, ...additionalData] = await Promise.all(
15+
const data = await Promise.all(
916
paths.map((p) =>
1017
window.api.getDescribe(
1118
{
@@ -16,7 +23,25 @@ export const overviewApi = api.injectEndpoints({
1623
),
1724
),
1825
);
19-
return {data: {data, additionalData}};
26+
return {data};
27+
} catch (error) {
28+
return {error};
29+
}
30+
},
31+
keepUnusedDataFor: 0,
32+
providesTags: ['All'],
33+
}),
34+
getOverview: build.query({
35+
queryFn: async ({path, database}: {path: string; database: string}, {signal}) => {
36+
try {
37+
const data = await window.api.getDescribe(
38+
{
39+
path,
40+
database,
41+
},
42+
{signal},
43+
);
44+
return {data};
2045
} catch (error) {
2146
return {error};
2247
}
@@ -26,3 +51,86 @@ export const overviewApi = api.injectEndpoints({
2651
}),
2752
}),
2853
});
54+
55+
const getOverviewSelector = createSelector(
56+
(path: string) => path,
57+
(_path: string, database: string) => database,
58+
(path, database) => overviewApi.endpoints.getOverview.select({path, database}),
59+
);
60+
61+
const selectGetOverview = createSelector(
62+
(state: RootState) => state,
63+
(_state: RootState, path: string, database: string) => getOverviewSelector(path, database),
64+
(state, selectOverview) => selectOverview(state).data,
65+
);
66+
67+
const selectOverviewChildren = (state: RootState, path: string, database: string) =>
68+
selectGetOverview(state, path, database)?.PathDescription?.Children;
69+
70+
export const selectSchemaMergedChildrenPaths = createSelector(
71+
[
72+
(_, path: string) => path,
73+
(_, _path, type: EPathType | undefined) => type,
74+
(state, path, _type, database: string) => selectOverviewChildren(state, path, database),
75+
],
76+
(path, type, children) => {
77+
return isEntityWithMergedImplementation(type)
78+
? children?.map(({Name}) => path + '/' + Name)
79+
: undefined;
80+
},
81+
);
82+
83+
//this hook is done not to refetch mainPath describe for entities with merged implementation
84+
export function useGetMultiOverviewQuery({
85+
paths,
86+
database,
87+
autoRefreshInterval,
88+
}: {
89+
paths: string[];
90+
database: string;
91+
autoRefreshInterval?: number;
92+
}) {
93+
const [mainPath, ...additionalPaths] = paths;
94+
95+
const {
96+
currentData: mainDescribe,
97+
isFetching: mainDescribeIsFetching,
98+
error: mainDescribeError,
99+
} = overviewApi.useGetOverviewQuery(
100+
{
101+
path: mainPath,
102+
database,
103+
},
104+
{
105+
pollingInterval: autoRefreshInterval,
106+
},
107+
);
108+
109+
const {
110+
currentData: currentChindrenDescribe = [],
111+
isFetching: childrenDescribeIsFetching,
112+
error: childrenDescribeError,
113+
} = overviewApi.useGetMultiOverviewQuery(
114+
additionalPaths.length ? {paths: additionalPaths, database} : skipToken,
115+
{
116+
pollingInterval: autoRefreshInterval,
117+
},
118+
);
119+
120+
const childrenDescribeLoading =
121+
childrenDescribeIsFetching && currentChindrenDescribe === undefined;
122+
const mainDescribeLoading = mainDescribeIsFetching && mainDescribe === undefined;
123+
124+
const loading = mainDescribeLoading || childrenDescribeLoading;
125+
126+
const describe = [mainDescribe, ...currentChindrenDescribe];
127+
128+
const mergedDescribe = describe.reduce<IDescribeData>((acc, item) => {
129+
if (item?.Path) {
130+
acc[item.Path] = item;
131+
}
132+
return acc;
133+
}, {});
134+
135+
return {loading, error: mainDescribeError || childrenDescribeError, mergedDescribe};
136+
}

0 commit comments

Comments
 (0)