From 03bea705e74d6f4226771c704a99734e1be46e2b Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Mon, 11 May 2026 11:45:05 +0800 Subject: [PATCH] feat(objects): edit database object source --- src/App.vue | 20 ++++ src/components/layout/ContentArea.vue | 2 + src/components/objects/ObjectBrowser.vue | 134 +++++++++++++++++++++-- src/i18n/locales/en.ts | 1 + src/i18n/locales/zh-CN.ts | 1 + src/lib/api.ts | 1 + src/lib/http.ts | 14 +++ src/lib/objectSourceEditor.ts | 42 +++++++ src/lib/tauri.ts | 12 ++ src/types/database.ts | 9 ++ tests/objectSourceEditor.test.ts | 44 ++++++++ 11 files changed, 272 insertions(+), 8 deletions(-) create mode 100644 src/lib/objectSourceEditor.ts create mode 100644 tests/objectSourceEditor.test.ts diff --git a/src/App.vue b/src/App.vue index 68f7ba5a5..3be4fe3ca 100644 --- a/src/App.vue +++ b/src/App.vue @@ -319,6 +319,25 @@ async function onClickTable(tableName: string) { } } +function openObjectSourceEditor(target: { title: string; sql: string; schema?: string }) { + const tab = activeTab.value; + if (!tab) return; + const existing = queryStore.tabs.find( + (item) => + item.mode === "query" && + item.connectionId === tab.connectionId && + item.database === tab.database && + item.title === target.title, + ); + if (existing) { + queryStore.activeTabId = existing.id; + return; + } + const tabId = queryStore.createTab(tab.connectionId, tab.database, target.title); + if (target.schema) queryStore.updateSchema(tabId, target.schema); + queryStore.updateSql(tabId, target.sql); +} + async function changeActiveConnection(connectionId: string) { const tab = activeTab.value; if (!tab) return; @@ -640,6 +659,7 @@ onUnmounted(() => { tableName: target.tableName, }) " + @edit-object-source="openObjectSourceEditor" @object-schema-change="(schema) => activeTab && queryStore.updateSchema(activeTab.id, schema)" /> diff --git a/src/components/layout/ContentArea.vue b/src/components/layout/ContentArea.vue index 282fc0c36..690654051 100644 --- a/src/components/layout/ContentArea.vue +++ b/src/components/layout/ContentArea.vue @@ -46,6 +46,7 @@ const emit = defineEmits<{ executeSql: [sql: string]; clickTable: [tableName: string]; openObjectTable: [target: { tableName: string; schema?: string }]; + editObjectSource: [target: { title: string; sql: string; schema?: string }]; objectSchemaChange: [schema: string | undefined]; }>(); @@ -442,6 +443,7 @@ function onHandleCloseColumnPanel() { :database="activeTab.database" :schema="activeTab.objectBrowser?.schema" @open-table="emit('openObjectTable', $event)" + @edit-source="emit('editObjectSource', $event)" @schema-change="emit('objectSchemaChange', $event)" /> diff --git a/src/components/objects/ObjectBrowser.vue b/src/components/objects/ObjectBrowser.vue index 478c004c3..492f965fc 100644 --- a/src/components/objects/ObjectBrowser.vue +++ b/src/components/objects/ObjectBrowser.vue @@ -1,14 +1,29 @@