forked from ydb-platform/ydb-embedded-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOverview.tsx
116 lines (100 loc) · 4.33 KB
/
Overview.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React from 'react';
import {shallowEqual} from 'react-redux';
import {ResponseError} from '../../../../components/Errors/ResponseError';
import {TableIndexInfo} from '../../../../components/InfoViewer/schemaInfo';
import {Loader} from '../../../../components/Loader';
import {
selectSchemaMergedChildrenPaths,
useGetMultiOverviewQuery,
} from '../../../../store/reducers/overview/overview';
import {EPathType} from '../../../../types/api/schema';
import {useAutoRefreshInterval, useTypedSelector} from '../../../../utils/hooks';
import {ExternalDataSourceInfo} from '../../Info/ExternalDataSource/ExternalDataSource';
import {ExternalTableInfo} from '../../Info/ExternalTable/ExternalTable';
import {ViewInfo} from '../../Info/View/View';
import {isEntityWithMergedImplementation} from '../../utils/schema';
import {AsyncReplicationInfo} from './AsyncReplicationInfo';
import {ChangefeedInfo} from './ChangefeedInfo';
import {TableInfo} from './TableInfo';
import {TopicInfo} from './TopicInfo';
import {TransferInfo} from './TransferInfo';
interface OverviewProps {
type?: EPathType;
path: string;
database: string;
}
function Overview({type, path, database}: OverviewProps) {
const [autoRefreshInterval] = useAutoRefreshInterval();
const isEntityWithMergedImpl = isEntityWithMergedImplementation(type);
// shallowEqual prevents rerenders when new schema data is loaded
const mergedChildrenPaths = useTypedSelector(
(state) => selectSchemaMergedChildrenPaths(state, path, type, database),
shallowEqual,
);
let paths: string[] = [];
if (!isEntityWithMergedImpl) {
paths = [path];
} else if (mergedChildrenPaths) {
paths = [path, ...mergedChildrenPaths];
}
const {
mergedDescribe,
loading: entityLoading,
error,
} = useGetMultiOverviewQuery({
paths,
database,
autoRefreshInterval,
});
const rawData = mergedDescribe[path];
const entityNotReady = isEntityWithMergedImpl && !mergedChildrenPaths;
const renderContent = () => {
const data = rawData ?? undefined;
// verbose mapping to guarantee a correct render for new path types
// TS will error when a new type is added but not mapped here
const pathTypeToComponent: Record<EPathType, (() => React.ReactNode) | undefined> = {
[EPathType.EPathTypeInvalid]: undefined,
[EPathType.EPathTypeDir]: undefined,
[EPathType.EPathTypeResourcePool]: undefined,
[EPathType.EPathTypeTable]: undefined,
[EPathType.EPathTypeSubDomain]: undefined,
[EPathType.EPathTypeTableIndex]: () => <TableIndexInfo data={data} />,
[EPathType.EPathTypeExtSubDomain]: undefined,
[EPathType.EPathTypeColumnStore]: undefined,
[EPathType.EPathTypeColumnTable]: undefined,
[EPathType.EPathTypeCdcStream]: () => {
const topicPath = mergedChildrenPaths?.[0];
if (topicPath) {
return (
<ChangefeedInfo
path={path}
database={database}
data={data}
topic={mergedDescribe?.[topicPath] ?? undefined}
/>
);
}
return undefined;
},
[EPathType.EPathTypePersQueueGroup]: () => (
<TopicInfo data={data} path={path} database={database} />
),
[EPathType.EPathTypeExternalTable]: () => <ExternalTableInfo data={data} />,
[EPathType.EPathTypeExternalDataSource]: () => <ExternalDataSourceInfo data={data} />,
[EPathType.EPathTypeView]: () => <ViewInfo data={data} />,
[EPathType.EPathTypeReplication]: () => <AsyncReplicationInfo data={data} />,
[EPathType.EPathTypeTransfer]: () => <TransferInfo data={data} />,
};
return (type && pathTypeToComponent[type]?.()) || <TableInfo data={data} type={type} />;
};
if (entityLoading || entityNotReady) {
return <Loader size="m" />;
}
return (
<React.Fragment>
{error ? <ResponseError error={error} /> : null}
{error && !rawData ? null : renderContent()}
</React.Fragment>
);
}
export default Overview;