|
| 1 | +import type {TIndexDescription} from '../../../types/api/schema'; |
| 2 | +import type { |
| 3 | + TVectorIndexKmeansTreeDescriptionSettings, |
| 4 | + TVectorIndexKmeansTreeDescriptionSettingsInner, |
| 5 | +} from '../../../types/api/schema/tableIndex'; |
| 6 | +import {formatNumber} from '../../../utils/dataFormatters/dataFormatters'; |
| 7 | +import type {InfoViewerItem} from '../InfoViewer'; |
| 8 | +import {formatTableIndexItem} from '../formatters'; |
| 9 | +import {createInfoFormatter} from '../utils'; |
| 10 | + |
| 11 | +import i18n from './i18n'; |
| 12 | + |
| 13 | +const DISPLAYED_FIELDS_KEYS = [ |
| 14 | + 'Type', |
| 15 | + 'State', |
| 16 | + 'DataSize', |
| 17 | + 'KeyColumnNames', |
| 18 | + 'DataColumnNames', |
| 19 | +] as const; |
| 20 | +type DisplayedIndexField = (typeof DISPLAYED_FIELDS_KEYS)[number]; |
| 21 | + |
| 22 | +export function getDisplayedIndexFields(): ReadonlySet<DisplayedIndexField> { |
| 23 | + return new Set<DisplayedIndexField>(DISPLAYED_FIELDS_KEYS); |
| 24 | +} |
| 25 | + |
| 26 | +export function buildIndexInfo(tableIndex?: TIndexDescription): InfoViewerItem[] { |
| 27 | + const info: InfoViewerItem[] = []; |
| 28 | + if (!tableIndex) { |
| 29 | + return info; |
| 30 | + } |
| 31 | + |
| 32 | + getDisplayedIndexFields().forEach((key) => { |
| 33 | + const value = tableIndex[key]; |
| 34 | + if (value !== undefined) { |
| 35 | + info.push(formatTableIndexItem(key, value)); |
| 36 | + } |
| 37 | + }); |
| 38 | + |
| 39 | + return info; |
| 40 | +} |
| 41 | + |
| 42 | +type VectorSettings = TVectorIndexKmeansTreeDescriptionSettings; |
| 43 | + |
| 44 | +export function buildVectorIndexInfo(vectorSettings?: VectorSettings): InfoViewerItem[] { |
| 45 | + const info: InfoViewerItem[] = []; |
| 46 | + if (!vectorSettings) { |
| 47 | + return info; |
| 48 | + } |
| 49 | + |
| 50 | + const vectorFormatter = createInfoFormatter<Pick<VectorSettings, 'clusters' | 'levels'>>({ |
| 51 | + values: { |
| 52 | + clusters: (v) => (typeof v === 'number' ? formatNumber(v) : v), |
| 53 | + levels: (v) => (typeof v === 'number' ? formatNumber(v) : v), |
| 54 | + }, |
| 55 | + labels: { |
| 56 | + clusters: i18n('field_clusters'), |
| 57 | + levels: i18n('field_levels'), |
| 58 | + }, |
| 59 | + }); |
| 60 | + |
| 61 | + const settingsFormatter = createInfoFormatter<TVectorIndexKmeansTreeDescriptionSettingsInner>({ |
| 62 | + values: { |
| 63 | + vector_dimension: (v) => (typeof v === 'number' ? formatNumber(v) : v), |
| 64 | + }, |
| 65 | + labels: { |
| 66 | + vector_dimension: i18n('field_vector-dimension'), |
| 67 | + vector_type: i18n('field_vector-type'), |
| 68 | + metric: i18n('field_metric'), |
| 69 | + }, |
| 70 | + }); |
| 71 | + |
| 72 | + const {clusters, levels, settings} = vectorSettings ?? {}; |
| 73 | + if (clusters !== undefined) { |
| 74 | + info.push(vectorFormatter('clusters', clusters)); |
| 75 | + } |
| 76 | + if (levels !== undefined) { |
| 77 | + info.push(vectorFormatter('levels', levels)); |
| 78 | + } |
| 79 | + |
| 80 | + const {vector_dimension: vectorDimension, vector_type: vectorType, metric} = settings ?? {}; |
| 81 | + |
| 82 | + if (vectorDimension !== undefined) { |
| 83 | + info.push(settingsFormatter('vector_dimension', vectorDimension)); |
| 84 | + } |
| 85 | + if (vectorType !== undefined) { |
| 86 | + info.push(settingsFormatter('vector_type', vectorType)); |
| 87 | + } |
| 88 | + if (metric !== undefined) { |
| 89 | + info.push(settingsFormatter('metric', metric)); |
| 90 | + } |
| 91 | + |
| 92 | + return info; |
| 93 | +} |
0 commit comments