Skip to content

Commit 2aed714

Browse files
committed
feat(Tenant): table index overview
1 parent 8c09746 commit 2aed714

File tree

5 files changed

+140
-2
lines changed

5 files changed

+140
-2
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import type {TEvDescribeSchemeResult, TIndexDescription} from '../../types/api/schema';
2+
import {InfoViewer, createInfoFormatter} from '../InfoViewer';
3+
4+
const DISPLAYED_FIELDS: Set<keyof TIndexDescription> = new Set([
5+
'Type',
6+
'State',
7+
'DataSize',
8+
'KeyColumnNames',
9+
'DataColumnNames',
10+
]);
11+
12+
const formatItem = createInfoFormatter<TIndexDescription>({
13+
Type: (value) => value?.substring(10), // trims EIndexType prefix
14+
State: (value) => value?.substring(11), // trims EIndexState prefix
15+
KeyColumnNames: (value) => value?.join(', '),
16+
DataColumnNames: (value) => value?.join(', '),
17+
}, {
18+
KeyColumnNames: 'Columns',
19+
DataColumnNames: 'Includes',
20+
});
21+
22+
interface IndexInfoViewerProps {
23+
data?: TEvDescribeSchemeResult;
24+
}
25+
26+
export const IndexInfoViewer = ({data}: IndexInfoViewerProps) => {
27+
if (!data) {
28+
return (
29+
<div className="error">no index data</div>
30+
);
31+
}
32+
33+
const TableIndex = data.PathDescription?.TableIndex;
34+
const info: Array<{label?: string, value?: unknown}> = [];
35+
36+
let key: keyof TIndexDescription;
37+
for (key in TableIndex) {
38+
if (DISPLAYED_FIELDS.has(key)) {
39+
info.push(formatItem(key, TableIndex?.[key]));
40+
}
41+
}
42+
43+
return (
44+
<>
45+
{info.length ? (
46+
<InfoViewer info={info}></InfoViewer>
47+
) : (
48+
<>Empty</>
49+
)}
50+
</>
51+
);
52+
};

src/components/InfoViewer/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import InfoViewer from './InfoViewer';
2+
3+
export {InfoViewer};
4+
export * from './utils';

src/components/InfoViewer/utils.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
type LabelMap<T> = {
2+
[label in keyof T]?: string;
3+
}
4+
5+
type FieldMappers<T> = {
6+
[label in keyof T]?: (value: T[label]) => string | undefined;
7+
}
8+
9+
function formatLabel<Shape>(label: keyof Shape, map: LabelMap<Shape>) {
10+
return map[label] ?? label;
11+
}
12+
13+
function formatValue<Shape, Key extends keyof Shape>(
14+
label: Key,
15+
value: Shape[Key],
16+
mappers: FieldMappers<Shape>,
17+
) {
18+
const mapper = mappers[label];
19+
const mappedValue = mapper ? mapper(value) : value;
20+
21+
return String(mappedValue ?? '');
22+
}
23+
24+
export function createInfoFormatter<Shape extends Record<string, any>>(
25+
fieldMappers?: FieldMappers<Shape>,
26+
labelMap?: LabelMap<Shape>,
27+
) {
28+
return <Key extends keyof Shape>(label: Key, value: Shape[Key]) => ({
29+
label: formatLabel(label, labelMap || {}),
30+
value: formatValue(label, value, fieldMappers || {}),
31+
});
32+
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {Loader} from '@yandex-cloud/uikit';
66

77
//@ts-ignore
88
import SchemaInfoViewer from '../../Schema/SchemaInfoViewer/SchemaInfoViewer';
9+
import {IndexInfoViewer} from '../../../../components/IndexInfoViewer/IndexInfoViewer';
910

1011
import type {EPathType} from '../../../../types/api/schema';
11-
import {isColumnEntityType, isTableType} from '../../utils/schema';
12+
import {isColumnEntityType, isTableType, mapPathTypeToNavigationTreeType} from '../../utils/schema';
1213
import {AutoFetcher} from '../../../../utils/autofetcher';
1314
//@ts-ignore
1415
import {getSchema} from '../../../../store/reducers/schema';
@@ -112,11 +113,24 @@ function Overview(props: OverviewProps) {
112113
);
113114
};
114115

116+
const renderContent = () => {
117+
switch (mapPathTypeToNavigationTreeType(props.type)) {
118+
case 'index':
119+
return (
120+
<IndexInfoViewer data={schemaData} />
121+
);
122+
default:
123+
return (
124+
<SchemaInfoViewer fullPath={currentItem.Path} data={schemaData} />
125+
);
126+
}
127+
}
128+
115129
return loading && !wasLoaded ? (
116130
renderLoader()
117131
) : (
118132
<div className={props.className}>
119-
<SchemaInfoViewer fullPath={currentItem.Path} data={schemaData} />
133+
{renderContent()}
120134
</div>
121135
);
122136
}

src/types/api/schema.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ interface TPathDescription {
5454

5555
ColumnStoreDescription?: unknown;
5656
ColumnTableDescription?: unknown;
57+
58+
TableIndex?: TIndexDescription;
5759
}
5860

5961
interface TDirEntry {
@@ -80,6 +82,27 @@ interface TDirEntry {
8082
Version?: TPathVersion;
8183
}
8284

85+
export interface TIndexDescription {
86+
Name?: string;
87+
/** uint64 */
88+
LocalPathId?: string;
89+
90+
Type?: EIndexType;
91+
State?: EIndexState;
92+
93+
KeyColumnNames?: string[];
94+
95+
/** uint64 */
96+
SchemaVersion?: string;
97+
98+
/** uint64 */
99+
PathOwnerId?: string;
100+
101+
DataColumnNames?: string[];
102+
/** uint64 */
103+
DataSize?: string;
104+
}
105+
83106
// incomplete
84107
export enum EPathType {
85108
EPathTypeInvalid = 'EPathTypeInvalid',
@@ -112,6 +135,19 @@ enum EPathState {
112135
EPathStateMoving = 'EPathStateMoving',
113136
}
114137

138+
enum EIndexType {
139+
EIndexTypeInvalid = 'EIndexTypeInvalid',
140+
EIndexTypeGlobal = 'EIndexTypeGlobal',
141+
EIndexTypeGlobalAsync = 'EIndexTypeGlobalAsync',
142+
}
143+
144+
enum EIndexState {
145+
EIndexStateInvalid = 'EIndexStateInvalid',
146+
EIndexStateReady = 'EIndexStateReady',
147+
EIndexStateNotReady = 'EIndexStateNotReady',
148+
EIndexStateWriteOnly = 'EIndexStateWriteOnly',
149+
}
150+
115151
// incomplete
116152
interface TPathVersion {
117153
/** uint64 */

0 commit comments

Comments
 (0)