|
| 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 | +}; |
0 commit comments