fix: preserve pending row edits when switching tabs (#362)

Wrap ContentArea in KeepAlive to cache tab instances across switches.
Add a module-level pending-changes cache in useDataGridEditor so edits
survive DataGrid destruction caused by result eviction and reload.
This commit is contained in:
t8y2 committed 2026-05-20 16:22:17 +08:00
1 parent fe6fead2dc
commit 47ec339d5a
8 files changed
+135 -65

No files matched your search

+54 -50
View File
@@ -204,10 +204,11 @@ const saveSqlFolders = computed(() => {
watch(
() => queryStore.activeTabId,
() => {
(id) => {
selectedSql.value = "";
activeOutputView.value = "result";
showDriverStore.value = false;
if (id) queryStore.reloadEvictedTab(id);
},
);
@@ -825,55 +826,58 @@ onUnmounted(() => {
@set-default-database="setActiveDatabaseAsDefault"
@clear-default-database="clearActiveDefaultDatabase"
/>
<ContentArea
ref="contentAreaRef"
:active-tab="activeTab"
:active-connection="activeConnection"
:executable-sql="executableSql"
:active-output-view="activeOutputView"
:format-sql-request-id="formatSqlRequestId"
:selected-sql="selectedSql"
:cursor-pos="cursorPos"
@update:active-output-view="activeOutputView = $event"
@fix-with-ai="fixWithAi"
@execute="tryExecute()"
@cancel="cancelActiveExecution()"
@explain="tryExplain()"
@editor-update="
(v: string) => {
if (queryStore.activeTabId) queryStore.updateSql(queryStore.activeTabId, v);
}
"
@editor-selection-change="(v: string) => (selectedSql = v)"
@editor-cursor-change="(p: number) => (cursorPos = p)"
@format-error="toast(t('toolbar.formatSqlFailed'))"
@save-sql="void openSaveSqlDialog()"
@reload="
(
sql?: string,
searchText?: string,
whereInput?: string,
orderBy?: string,
limit?: number,
offset?: number,
) => onReloadData(sql, searchText, whereInput, orderBy, limit, offset)
"
@paginate="onPaginate"
@sort="onSort"
@execute-sql="onExecuteSql"
@click-table="onClickTable"
@open-object-table="
(target) =>
activeTab &&
openTableTarget({
connectionId: activeTab.connectionId,
database: activeTab.database,
schema: target.schema,
tableName: target.tableName,
})
"
@object-schema-change="(schema) => activeTab && queryStore.updateSchema(activeTab.id, schema)"
/>
<KeepAlive :max="20">
<ContentArea
ref="contentAreaRef"
:key="activeTab.id"
:active-tab="activeTab"
:active-connection="activeConnection"
:executable-sql="executableSql"
:active-output-view="activeOutputView"
:format-sql-request-id="formatSqlRequestId"
:selected-sql="selectedSql"
:cursor-pos="cursorPos"
@update:active-output-view="activeOutputView = $event"
@fix-with-ai="fixWithAi"
@execute="tryExecute()"
@cancel="cancelActiveExecution()"
@explain="tryExplain()"
@editor-update="
(v: string) => {
if (queryStore.activeTabId) queryStore.updateSql(queryStore.activeTabId, v);
}
"
@editor-selection-change="(v: string) => (selectedSql = v)"
@editor-cursor-change="(p: number) => (cursorPos = p)"
@format-error="toast(t('toolbar.formatSqlFailed'))"
@save-sql="void openSaveSqlDialog()"
@reload="
(
sql?: string,
searchText?: string,
whereInput?: string,
orderBy?: string,
limit?: number,
offset?: number,
) => onReloadData(sql, searchText, whereInput, orderBy, limit, offset)
"
@paginate="onPaginate"
@sort="onSort"
@execute-sql="onExecuteSql"
@click-table="onClickTable"
@open-object-table="
(target) =>
activeTab &&
openTableTarget({
connectionId: activeTab.connectionId,
database: activeTab.database,
schema: target.schema,
tableName: target.tableName,
})
"
@object-schema-change="(schema) => activeTab && queryStore.updateSchema(activeTab.id, schema)"
/>
</KeepAlive>
</div>
<WelcomeScreen
v-else