fix(grid): protect unsaved cell edits on data tab reuse
This commit is contained in:
5 files changed
+49
-9
No files matched your search
@@ -79,6 +79,7 @@ describe("dataTabOpenPolicy", () => {
|
||||
["explaining", { isExplaining: true }],
|
||||
["manual transaction", { txnSessionId: "txn-1" }],
|
||||
["pending edits", { pendingDataChangeCount: 1 }],
|
||||
["pending editor draft", { hasPendingDataEditorDraft: true }],
|
||||
])("does not reuse the active tab when it is %s", (_label, patch) => {
|
||||
const active = Object.assign(dataTab("orders", "orders"), patch);
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { QueryTab, TreeNodeType } from "@/types/database";
|
||||
export type DataTabOpenMode = "default" | "new-tab";
|
||||
export type { DataTabReuseMode };
|
||||
|
||||
type DataTabLike = Pick<QueryTab, "id" | "mode" | "connectionId" | "database" | "catalog" | "schema" | "title" | "tableMeta" | "tableMetaUpdatedAt" | "pinned" | "isExecuting" | "isCancelling" | "isExplaining" | "txnSessionId" | "pendingDataChangeCount">;
|
||||
type DataTabLike = Pick<QueryTab, "id" | "mode" | "connectionId" | "database" | "catalog" | "schema" | "title" | "tableMeta" | "tableMetaUpdatedAt" | "pinned" | "isExecuting" | "isCancelling" | "isExplaining" | "txnSessionId" | "pendingDataChangeCount" | "hasPendingDataEditorDraft">;
|
||||
|
||||
export interface DataTabTarget {
|
||||
connectionId: string;
|
||||
@@ -45,7 +45,7 @@ function isSameTable(tab: DataTabLike, target: DataTabTarget): boolean {
|
||||
}
|
||||
|
||||
export function canReuseActiveDataTab(tab: DataTabLike | undefined, target: DataTabTarget): boolean {
|
||||
return tab !== undefined && isSameDatabase(tab, target) && dataTabCatalog(tab) === (target.catalog || "") && !tab.pinned && !tab.isExecuting && !tab.isCancelling && !tab.isExplaining && !tab.txnSessionId && !tab.pendingDataChangeCount;
|
||||
return tab !== undefined && isSameDatabase(tab, target) && dataTabCatalog(tab) === (target.catalog || "") && !tab.pinned && !tab.isExecuting && !tab.isCancelling && !tab.isExplaining && !tab.txnSessionId && !tab.pendingDataChangeCount && !tab.hasPendingDataEditorDraft;
|
||||
}
|
||||
|
||||
export function canApplyDataTabMetadata(tab: DataTabLike | undefined, target: DataTabTarget, signal?: AbortSignal): boolean {
|
||||
|
||||
Reference in new issue
Block a user