Skip to content

Commit cd645c6

Browse files
committed
refactor(ObjectSummary): allow custom overviews for node types
1 parent cbd525d commit cd645c6

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

src/containers/Tenant/ObjectSummary/ObjectSummary.tsx

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, {useEffect, useReducer} from 'react';
1+
import React, {ReactNode, useEffect, useReducer} from 'react';
22
import {useDispatch, useSelector} from 'react-redux';
33
import {Link} from 'react-router-dom';
44
import cn from 'bem-cn-lite';
@@ -16,7 +16,7 @@ import CopyToClipboard from '../../../components/CopyToClipboard/CopyToClipboard
1616
import InfoViewer from '../../../components/InfoViewer/InfoViewer';
1717
import Icon from '../../../components/Icon/Icon';
1818

19-
import type {EPathSubType, EPathType, TDirEntry} from '../../../types/api/schema';
19+
import {EPathSubType, EPathType, TDirEntry} from '../../../types/api/schema';
2020
import {isColumnEntityType, isIndexTable, isTableType} from '../utils/schema';
2121

2222
import {
@@ -151,14 +151,35 @@ function ObjectSummary(props: ObjectSummaryProps) {
151151
};
152152

153153
const renderObjectOverview = () => {
154-
const startTimeInMilliseconds = Number(currentSchemaData?.CreateStep);
155-
let createTime = '';
156-
if (startTimeInMilliseconds) {
157-
createTime = new Date(startTimeInMilliseconds).toUTCString();
154+
// verbose mapping to guarantee a correct render for new path types
155+
// TS will error when a new type is added but not mapped here
156+
const pathTypeToComponent: Record<EPathType, (() => ReactNode) | undefined> = {
157+
[EPathType.EPathTypeInvalid]: undefined,
158+
[EPathType.EPathTypeDir]: undefined,
159+
[EPathType.EPathTypeTable]: undefined,
160+
[EPathType.EPathTypeSubDomain]: undefined,
161+
[EPathType.EPathTypeTableIndex]: undefined,
162+
[EPathType.EPathTypeExtSubDomain]: undefined,
163+
[EPathType.EPathTypeColumnStore]: undefined,
164+
[EPathType.EPathTypeColumnTable]: undefined,
165+
[EPathType.EPathTypeCdcStream]: () => undefined,
166+
};
167+
168+
let component = currentSchemaData?.PathType && pathTypeToComponent[currentSchemaData.PathType]?.();
169+
170+
if (!component) {
171+
const startTimeInMilliseconds = Number(currentSchemaData?.CreateStep);
172+
let createTime = '';
173+
if (startTimeInMilliseconds) {
174+
createTime = new Date(startTimeInMilliseconds).toUTCString();
175+
}
176+
177+
component = <InfoViewer info={[{label: 'Create time', value: createTime}]} />;
158178
}
179+
159180
return (
160181
<div className={b('overview-wrapper')}>
161-
<InfoViewer info={[{label: 'Create time', value: createTime}]} />
182+
{component}
162183
</div>
163184
);
164185
};

0 commit comments

Comments
 (0)