feat(grid): show column index indicators in data headers
This commit is contained in:
16 files changed
+272
-5
No files matched your search
@@ -230,6 +230,7 @@ import { getTableMetadataCapabilities } from "@/lib/table/tableMetadataCapabilit
|
||||
import { getTableStructureCapabilities } from "@/lib/table/tableStructureCapabilities";
|
||||
import { filterObjectBrowserTableColumns } from "@/lib/table/objectBrowserTableInfo";
|
||||
import { reserveDataGridHeaderLine } from "@/lib/dataGrid/dataGridHeaderLayout";
|
||||
import { buildColumnIndexMap, columnIndexMetadataRequestCurrent, columnIndexNameKey, columnIndexTableIdentity } from "@/lib/dataGrid/dataGridColumnIndexIcon";
|
||||
import { supportsTableStructureEditing } from "@/lib/database/databaseCapabilities";
|
||||
import { rememberDataGridConditionHistory } from "@/lib/dataGrid/dataGridConditionHistory";
|
||||
import { restoreDataGridLocalColumnFilters, serializeDataGridLocalColumnFilters } from "@/lib/dataGrid/dataGridLocalColumnFilterState";
|
||||
@@ -495,6 +496,15 @@ const dataGridTopbarWidth = ref(0);
|
||||
const dataGridViewportWidth = ref(0);
|
||||
const showColumnCommentsInHeader = computed(() => settingsStore.editorSettings.showColumnCommentsInHeader);
|
||||
const showColumnTypesInHeader = computed(() => settingsStore.editorSettings.showColumnTypesInHeader);
|
||||
const showIndexIndicatorsInHeader = computed(() => settingsStore.editorSettings.showIndexIndicatorsInHeader !== false);
|
||||
const primaryKeyColumnNames = computed(() => {
|
||||
const names = new Set(props.tableMeta?.primaryKeys ?? []);
|
||||
for (const column of props.tableMeta?.columns ?? []) {
|
||||
if (column.is_primary_key) names.add(column.name);
|
||||
}
|
||||
return [...names];
|
||||
});
|
||||
const columnIndexMap = computed(() => buildColumnIndexMap(indexes.value, primaryKeyColumnNames.value));
|
||||
const compactColumnHeaderActions = computed(() => settingsStore.editorSettings.compactColumnHeaderActions);
|
||||
const dataGridRenderMode = computed(() => settingsStore.editorSettings.dataGridRenderMode);
|
||||
const dataGridSearchMode = computed(() => settingsStore.editorSettings.dataGridSearchMode);
|
||||
@@ -7480,6 +7490,16 @@ const indexes = ref<IndexInfo[]>([]);
|
||||
const indexesLoaded = ref(false);
|
||||
const indexesLoading = ref(false);
|
||||
const indexesError = ref("");
|
||||
const currentIndexTableIdentity = computed(() =>
|
||||
columnIndexTableIdentity({
|
||||
connectionId: props.connectionId,
|
||||
database: props.database,
|
||||
catalog: props.tableMeta?.catalog,
|
||||
schema: props.tableMeta?.schema,
|
||||
tableName: props.tableMeta?.tableName,
|
||||
}),
|
||||
);
|
||||
let indexesRequestGeneration = 0;
|
||||
const showDropMongoIndexConfirm = ref(false);
|
||||
const dropMongoIndexLoading = ref(false);
|
||||
const pendingDropMongoIndex = ref<IndexInfo | null>(null);
|
||||
@@ -7673,16 +7693,26 @@ async function fetchDdl() {
|
||||
}
|
||||
|
||||
async function fetchIndexes() {
|
||||
if (!props.connectionId || !props.tableMeta || indexesLoaded.value || indexesLoading.value) return;
|
||||
const requestIdentity = currentIndexTableIdentity.value;
|
||||
if (!props.connectionId || !props.tableMeta || !canShowTableIndexes.value || !requestIdentity || indexesLoaded.value || indexesLoading.value) return;
|
||||
const connectionId = props.connectionId;
|
||||
const database = props.database || "";
|
||||
const schema = props.tableMeta.schema || props.database || "";
|
||||
const tableName = props.tableMeta.tableName;
|
||||
const catalog = props.tableMeta.catalog;
|
||||
const requestGeneration = ++indexesRequestGeneration;
|
||||
indexesLoading.value = true;
|
||||
indexesError.value = "";
|
||||
try {
|
||||
indexes.value = await api.listIndexes(props.connectionId, props.database || "", props.tableMeta.schema || props.database || "", props.tableMeta.tableName, props.tableMeta.catalog);
|
||||
const nextIndexes = await api.listIndexes(connectionId, database, schema, tableName, catalog);
|
||||
if (!columnIndexMetadataRequestCurrent({ requestGeneration, currentGeneration: indexesRequestGeneration, requestIdentity, currentIdentity: currentIndexTableIdentity.value })) return;
|
||||
indexes.value = nextIndexes;
|
||||
indexesLoaded.value = true;
|
||||
} catch (e: any) {
|
||||
if (!columnIndexMetadataRequestCurrent({ requestGeneration, currentGeneration: indexesRequestGeneration, requestIdentity, currentIdentity: currentIndexTableIdentity.value })) return;
|
||||
indexesError.value = String(e?.message || e);
|
||||
} finally {
|
||||
indexesLoading.value = false;
|
||||
if (columnIndexMetadataRequestCurrent({ requestGeneration, currentGeneration: indexesRequestGeneration, requestIdentity, currentIdentity: currentIndexTableIdentity.value })) indexesLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7748,7 +7778,9 @@ watch(
|
||||
ddlContent.value = "";
|
||||
indexes.value = [];
|
||||
indexesLoaded.value = false;
|
||||
indexesLoading.value = false;
|
||||
indexesError.value = "";
|
||||
indexesRequestGeneration += 1;
|
||||
foreignKeys.value = [];
|
||||
foreignKeysLoaded.value = false;
|
||||
foreignKeysLoading.value = false;
|
||||
@@ -7761,6 +7793,14 @@ watch(
|
||||
},
|
||||
);
|
||||
|
||||
watch(
|
||||
() => [showIndexIndicatorsInHeader.value, canShowTableIndexes.value, currentIndexTableIdentity.value] as const,
|
||||
([showIndicators, canShowIndexes, tableIdentity]) => {
|
||||
if (showIndicators && canShowIndexes && tableIdentity) void fetchIndexes();
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
// ---- 外键单元格跳转 ----
|
||||
const columnForeignKeyMap = computed(() => buildColumnForeignKeyMap(foreignKeys.value));
|
||||
const foreignKeyNavigationEnabled = computed(() => !!props.connectionId && !!props.tableMeta?.tableName && tableMetadataCapabilities.value.foreignKeys);
|
||||
@@ -8941,6 +8981,11 @@ const gridContextMenuItems = computed<ContextMenuItem[]>(() => {
|
||||
:column-name-label="t('grid.columnName')"
|
||||
:column-type-label="t('grid.columnType')"
|
||||
:column-comment-label="t('grid.columnComment')"
|
||||
:column-index-label="t('grid.tableInfoIndexes')"
|
||||
:column-primary-index-label="t('grid.columnPrimaryIndex')"
|
||||
:column-unique-index-label="t('grid.columnUniqueIndex')"
|
||||
:column-regular-index-label="t('grid.columnRegularIndex')"
|
||||
:column-index-kind="showIndexIndicatorsInHeader ? columnIndexMap.get(columnIndexNameKey(col.name)) : undefined"
|
||||
@pointerdown="startColumnHeaderDrag(col.visibleColIdx, $event)"
|
||||
@click-capture="onHeaderClickCapture"
|
||||
@click="onHeaderClick(col.visibleColIdx, $event)"
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import type { CSSProperties, HTMLAttributes } from "vue";
|
||||
import { Copy } from "@lucide/vue";
|
||||
import { Copy, KeyRound, Hash } from "@lucide/vue";
|
||||
import LightTooltip from "@/components/ui/LightTooltip.vue";
|
||||
import { columnIndexColorClass, type ColumnIndexKind } from "@/lib/dataGrid/dataGridColumnIndexIcon";
|
||||
|
||||
defineProps<{
|
||||
const props = defineProps<{
|
||||
name: string;
|
||||
actualColumnIndex: number;
|
||||
visibleColumnIndex: number;
|
||||
@@ -26,8 +27,21 @@ defineProps<{
|
||||
columnNameLabel: string;
|
||||
columnTypeLabel: string;
|
||||
columnCommentLabel: string;
|
||||
columnIndexLabel: string;
|
||||
columnPrimaryIndexLabel: string;
|
||||
columnUniqueIndexLabel: string;
|
||||
columnRegularIndexLabel: string;
|
||||
/** 该列的索引类型,undefined 时不显示标识 */
|
||||
columnIndexKind?: ColumnIndexKind;
|
||||
}>();
|
||||
|
||||
function columnIndexText(kind: ColumnIndexKind): string {
|
||||
if (kind === "primary") return props.columnPrimaryIndexLabel;
|
||||
if (kind === "unique") return props.columnUniqueIndexLabel;
|
||||
if (kind === "index") return props.columnRegularIndexLabel;
|
||||
return "";
|
||||
}
|
||||
|
||||
const emit = defineEmits<{
|
||||
pointerdown: [event: PointerEvent];
|
||||
clickCapture: [event: MouseEvent];
|
||||
@@ -60,6 +74,9 @@ const emit = defineEmits<{
|
||||
@contextmenu="emit('contextmenu', $event)"
|
||||
>
|
||||
<span class="flex min-w-0 items-center gap-1 overflow-hidden">
|
||||
<!-- 索引标识:显示在列名左侧 -->
|
||||
<KeyRound v-if="columnIndexKind === 'primary'" class="h-3 w-3 shrink-0" :class="columnIndexColorClass(columnIndexKind)" :title="columnIndexText(columnIndexKind)" />
|
||||
<Hash v-else-if="columnIndexKind && columnIndexKind !== 'none'" class="h-3 w-3 shrink-0" :class="columnIndexColorClass(columnIndexKind)" :title="columnIndexText(columnIndexKind)" />
|
||||
<span class="flex min-w-0 flex-1 flex-col overflow-hidden">
|
||||
<span class="min-w-0 truncate leading-4">{{ name }}</span>
|
||||
<span v-if="showTypeLine" data-grid-header-type-line class="h-3 min-w-0 truncate text-[10px] font-normal leading-3" :class="[typeClass, { invisible: !columnType }]" :title="columnType || undefined" :aria-hidden="columnType ? undefined : true">{{ columnType }}</span>
|
||||
@@ -88,6 +105,14 @@ const emit = defineEmits<{
|
||||
<span class="text-background/70">{{ columnCommentLabel }}</span>
|
||||
<span>{{ tooltipColumnComment ?? columnComment }}</span>
|
||||
</template>
|
||||
<template v-if="columnIndexKind && columnIndexKind !== 'none'">
|
||||
<span class="text-background/70">{{ columnIndexLabel }}</span>
|
||||
<span class="flex items-center gap-1">
|
||||
<KeyRound v-if="columnIndexKind === 'primary'" class="h-3 w-3" :class="columnIndexColorClass(columnIndexKind)" />
|
||||
<Hash v-else class="h-3 w-3" :class="columnIndexColorClass(columnIndexKind)" />
|
||||
<span :class="columnIndexColorClass(columnIndexKind)">{{ columnIndexText(columnIndexKind) }}</span>
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
</LightTooltip>
|
||||
|
||||
Reference in new issue
Block a user