fix(table): refresh data tabs after clearing tables

This commit is contained in:
zipg authored and GitHub committed 2026-07-11 17:48:51 +08:00
1 parent 085d7661af
commit 3747f08baa
6 files changed
+309 -13

No files matched your search

@@ -96,6 +96,7 @@ import {
} from "@/lib/table/objectBrowserRows";
import { resolveRowClickAction, shouldDeferSingleClick, type ObjectBrowserRowAction } from "@/lib/table/objectBrowserRowAction";
import { createSidePanelRequestGuard } from "@/lib/table/sidePanelRequestGuard";
import { runBatchTableTruncate } from "@/lib/table/batchTableTruncate";
type ObjectFilter = "all" | "tables" | "views" | "materializedViews" | "procedures" | "functions" | "sequences" | "packages";
type ObjectBrowserColumnKey = "select" | "name" | "type" | "estimatedRows" | "totalBytes" | "created_at" | "updated_at" | "comment";
@@ -1440,15 +1441,41 @@ function requestBatchTruncateTables() {
showBatchTruncateConfirm.value = true;
}
function tableDataRefreshTargetForRow(row: ObjectBrowserRow) {
return {
connectionId: props.connection.id,
database: props.database,
schema: row.schema || selectedSchema.value,
schemaCandidates: [row.schema, selectedSchema.value],
catalog: props.catalog,
name: row.name,
};
}
async function refreshMutatedTableDataTabsForRows(rows: readonly ObjectBrowserRow[]) {
for (const row of rows) {
const target = tableDataRefreshTargetForRow(row);
try {
await queryStore.refreshDataTabsForTable(target);
} catch (error) {
console.warn("[DBX][table-data-refresh-after-mutation:error]", { target, error });
}
}
}
async function confirmBatchTruncateTables() {
const targets = [...selectedTableRows.value];
if (targets.length === 0) return;
try {
const useCascade = canBatchTruncateCascade.value && batchTruncateCascade.value;
for (const row of targets) {
const sql = await buildTruncateTableSql(tableAdminSqlOptions(row, { cascade: useCascade }));
await api.executeQuery(props.connection.id, props.database, sql);
}
await runBatchTableTruncate(
targets,
async (row) => {
const sql = await buildTruncateTableSql(tableAdminSqlOptions(row, { cascade: useCascade }));
await api.executeQuery(props.connection.id, props.database, sql);
},
refreshMutatedTableDataTabsForRows,
);
toast(t("objects.batchTruncateSuccess", { count: targets.length }));
clearTableSelection();
showBatchTruncateConfirm.value = false;
@@ -1833,6 +1860,7 @@ async function confirmTruncateTable() {
const sql = truncatePreviewSql.value || (await buildTruncateTableSql(tableAdminSqlOptions(row, { cascade: canTruncateTargetCascade.value && truncateTableCascade.value })));
await api.executeQuery(props.connection.id, props.database, sql);
toast(t("contextMenu.truncateTableSuccess", { name: row.name }));
await refreshMutatedTableDataTabsForRows([row]);
} catch (e: any) {
toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);
}
@@ -1857,6 +1885,7 @@ async function confirmEmptyTable() {
const sql = emptyPreviewSql.value || (await buildEmptyTableSql(tableAdminSqlOptions(row)));
await api.executeQuery(props.connection.id, props.database, sql);
toast(t("contextMenu.emptyTableSuccess", { name: row.name }));
await refreshMutatedTableDataTabsForRows([row]);
} catch (e: any) {
toast(t("contextMenu.tableOperationFailed", { message: e?.message || String(e) }), 5000);
}