diff --git a/src/App.vue b/src/App.vue index 68f7ba5a5f..3be4fe3cab 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 282fc0c36a..6906540511 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 478c004c33..492f965fc0 100644 --- a/src/components/objects/ObjectBrowser.vue +++ b/src/components/objects/ObjectBrowser.vue @@ -1,14 +1,29 @@