fix(tabs): close dropped table tabs
This commit is contained in:
1 parent
90d2ede740
commit
32a9496d2a
4 files changed
+192
No files matched your search
@@ -62,6 +62,17 @@ interface BuildQueryResultExportRequestOptions {
|
||||
format: "csv" | "xlsx";
|
||||
}
|
||||
|
||||
type DroppedTableObjectType = "TABLE" | "VIEW" | "MATERIALIZED_VIEW";
|
||||
|
||||
interface DroppedTableObjectTarget {
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema?: string;
|
||||
schemaCandidates?: Array<string | undefined>;
|
||||
name: string;
|
||||
objectType?: DroppedTableObjectType;
|
||||
}
|
||||
|
||||
function tabClientSessionId(tab: Pick<QueryTab, "id">, suffix?: (typeof BACKGROUND_CLIENT_SESSION_SUFFIXES)[number]): string {
|
||||
return suffix ? `${tab.id}:${suffix}` : tab.id;
|
||||
}
|
||||
@@ -70,6 +81,15 @@ function resultRunCacheKey(tabId: string, runId: string): string {
|
||||
return `tab:${tabId}:run:${runId}`;
|
||||
}
|
||||
|
||||
function normalizeOptionalSchema(schema: string | null | undefined): string {
|
||||
return schema?.trim() ?? "";
|
||||
}
|
||||
|
||||
function droppedTableObjectSchemaCandidates(target: DroppedTableObjectTarget): Set<string> {
|
||||
const schemas = target.schemaCandidates?.length ? target.schemaCandidates : [target.schema];
|
||||
return new Set(schemas.map(normalizeOptionalSchema));
|
||||
}
|
||||
|
||||
function markQueryResultRowsRaw(result: QueryResult): QueryResult {
|
||||
markRaw(result.rows);
|
||||
return result;
|
||||
@@ -1219,6 +1239,30 @@ export const useQueryStore = defineStore("query", () => {
|
||||
closeTabsWhere((tab) => tab.connectionId === connectionId && tab.database === database);
|
||||
}
|
||||
|
||||
function tabMatchesDroppedTableObject(tab: QueryTab, target: DroppedTableObjectTarget): boolean {
|
||||
if (tab.connectionId !== target.connectionId || tab.database !== target.database) return false;
|
||||
const targetSchemas = droppedTableObjectSchemaCandidates(target);
|
||||
|
||||
if (tab.mode === "data") {
|
||||
const tableMeta = tableMetaForDataTab(tab);
|
||||
if (!tableMeta || tableMeta.tableName !== target.name) return false;
|
||||
return targetSchemas.has(normalizeOptionalSchema(tableMeta.schema ?? tab.schema));
|
||||
}
|
||||
|
||||
if ((target.objectType ?? "TABLE") === "TABLE" && tab.mode === "structure") {
|
||||
if ((tab.structureTableName || "") !== target.name) return false;
|
||||
return targetSchemas.has(normalizeOptionalSchema(tab.schema));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function closeDroppedTableObjectTabs(target: DroppedTableObjectTarget) {
|
||||
// A dropped table-like object makes existing data/structure tabs stale; close
|
||||
// them immediately instead of letting the next refresh fail against a missing object.
|
||||
closeTabsWhere((tab) => tabMatchesDroppedTableObject(tab, target));
|
||||
}
|
||||
|
||||
function releaseTabsWhere(predicate: (tab: QueryTab) => boolean) {
|
||||
closeTabsWhere((tab) => predicate(tab) && tab.mode !== "query");
|
||||
tabs.value
|
||||
@@ -2857,6 +2901,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
duplicateTab,
|
||||
closeConnectionTabs,
|
||||
closeDatabaseTabs,
|
||||
closeDroppedTableObjectTabs,
|
||||
releaseConnectionTabs,
|
||||
releaseDatabaseTabs,
|
||||
isDatabaseOpen,
|
||||
|
||||
Reference in new issue
Block a user