From 5b3b69f7fbb8154ca7da7b51f7b1cb549ce0000a Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Tue, 19 May 2026 12:58:10 +0800 Subject: [PATCH] fix(structure): load editor on open --- .../structure/TableStructureEditorDialog.vue | 36 ++++++++++++------- .../src/lib/tableStructureEditorState.ts | 12 +++++++ .../tableStructureEditorPresentation.test.ts | 4 +++ .../tableStructureEditorState.test.ts | 12 +++++++ 4 files changed, 52 insertions(+), 12 deletions(-) diff --git a/apps/desktop/src/components/structure/TableStructureEditorDialog.vue b/apps/desktop/src/components/structure/TableStructureEditorDialog.vue index 017a0f0a8..f128c08e1 100644 --- a/apps/desktop/src/components/structure/TableStructureEditorDialog.vue +++ b/apps/desktop/src/components/structure/TableStructureEditorDialog.vue @@ -39,7 +39,12 @@ import { type EditableStructureIndex, } from "@/lib/tableStructureEditorSql"; import { getTableStructureCapabilities } from "@/lib/tableStructureCapabilities"; -import { createColumnDrafts, createIndexDrafts, toColumnNames } from "@/lib/tableStructureEditorState"; +import { + buildStructureTargetLabel, + createColumnDrafts, + createIndexDrafts, + toColumnNames, +} from "@/lib/tableStructureEditorState"; import type { ForeignKeyInfo, TriggerInfo } from "@/types/database"; import * as api from "@/lib/api"; @@ -116,11 +121,14 @@ const indexColLabels = computed(() => [ const targetSchema = computed(() => props.prefillSchema || props.prefillDatabase || ""); const isCreateMode = computed(() => !props.prefillTable); const newTableName = ref(""); -const targetLabel = computed(() => { - const parts = [connection.value?.name, props.prefillDatabase, props.prefillSchema]; - if (!isCreateMode.value) parts.push(props.prefillTable); - return parts.filter(Boolean).join(" / "); -}); +const targetLabel = computed(() => + buildStructureTargetLabel( + connection.value?.name, + props.prefillDatabase, + props.prefillSchema, + isCreateMode.value ? undefined : props.prefillTable, + ), +); const changeSql = computed(() => { if (isCreateMode.value) { @@ -331,12 +339,16 @@ async function applyChanges() { } } -watch(open, (value) => { - if (value) { - resetState(); - void loadStructure(); - } -}); +watch( + open, + (value) => { + if (value) { + resetState(); + void loadStructure(); + } + }, + { immediate: true }, +);