feat(ui): refresh latest ddl on demand

This commit is contained in:
zipg authored and GitHub committed 2026-09-01 01:46:39 +08:00
1 parent f9ff9245ce
commit cd008b2d56
17 files changed
+186 -11

No files matched your search

@@ -12,6 +12,8 @@ import { formatSqlForDisplay, type SqlFormatDialect } from "@/lib/sql/sqlFormatt
import { loadObjectDdl } from "@/lib/metadata/objectDdlCache";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Switch } from "@/components/ui/switch";
import { HelpTooltip } from "@/components/ui/tooltip";
import EditorSearchPanel from "@/components/editor/EditorSearchPanel.vue";
import type { EditorView } from "@codemirror/view";
import type { DatabaseType, ObjectSourceKind } from "@/types/database";
@@ -131,7 +133,7 @@ async function loadDdl(force = false) {
}
}
/** Loads the persisted table DDL when the dialog opens. */
/** Loads from the persisted snapshot by default; users can opt into a fresh database query on every open. */
watch(
() => props.open,
async (open) => {
@@ -140,7 +142,7 @@ watch(
const active = document.activeElement;
editorRootToRestoreFocus = active instanceof HTMLElement ? active.closest(".cm-editor") : null;
ddlContent.value = "";
await loadDdl();
await loadDdl(settingsStore.editorSettings.refreshDdlOnOpen);
},
{ immediate: true },
);
@@ -269,6 +271,11 @@ function retry() {
void loadDdl(true);
}
function setRefreshDdlOnOpen(value: boolean) {
settingsStore.updateEditorSettings({ refreshDdlOnOpen: value });
if (value) void loadDdl(true);
}
function onClose() {
emit("update:open", false);
}
@@ -298,6 +305,15 @@ function onClose() {
</div>
</div>
<DialogFooter>
<div class="mr-auto flex items-center gap-2 text-sm text-muted-foreground">
<Switch id="ddl-refresh-on-open" size="sm" :model-value="settingsStore.editorSettings.refreshDdlOnOpen" @update:model-value="setRefreshDdlOnOpen" />
<div class="flex items-center gap-1">
<label for="ddl-refresh-on-open" class="cursor-pointer">{{ t("contextMenu.refreshDdlOnOpen") }}</label>
<HelpTooltip :label="t('contextMenu.refreshDdlOnOpenHint')" trigger-class="[&_svg]:h-3 [&_svg]:w-3">
{{ t("contextMenu.refreshDdlOnOpenHint") }}
</HelpTooltip>
</div>
</div>
<Button variant="outline" @click="onClose">{{ t("common.close") }}</Button>
<Button variant="outline" :disabled="ddlLoading" :title="t('structureEditor.refresh')" @click="loadDdl(true)">
<RefreshCw class="h-4 w-4" />