7 files changed
+97
-17
No files matched your search
@@ -27,4 +27,27 @@ describe("sidebar active-tab targets", () => {
|
||||
expect(matchesTarget(icebergDatabase, target!)).toBe(false);
|
||||
expect(matchesTarget(defaultDatabase, target!)).toBe(false);
|
||||
});
|
||||
|
||||
it("uses data-tab table metadata as the locate identity after a reload", () => {
|
||||
const target = activeTabSidebarTarget({
|
||||
mode: "data",
|
||||
connectionId: "dm-1",
|
||||
database: "SERVICE_DB",
|
||||
schema: "APP_OWNER",
|
||||
title: "ORDERS",
|
||||
sql: "SELECT * FROM APP_OWNER.ORDERS",
|
||||
tableMeta: {
|
||||
database: "APP_OWNER",
|
||||
schema: "APP_OWNER",
|
||||
tableName: "ORDERS",
|
||||
tableType: "TABLE",
|
||||
columns: [{ name: "ID", data_type: "INTEGER", is_nullable: false, column_default: null, is_primary_key: true, extra: null }],
|
||||
primaryKeys: ["ID"],
|
||||
},
|
||||
} as QueryTab);
|
||||
|
||||
expect(target).toEqual({ type: "table", connectionId: "dm-1", database: "APP_OWNER", schema: "APP_OWNER", tableName: "ORDERS" });
|
||||
expect(matchesTarget({ id: "dm-1:APP_OWNER:APP_OWNER:tables:ORDERS", label: "ORDERS", type: "table", connectionId: "dm-1", database: "APP_OWNER", schema: "APP_OWNER" } as TreeNode, target!)).toBe(true);
|
||||
expect(matchesTarget({ id: "dm-1:SERVICE_DB", label: "SERVICE_DB", type: "database", connectionId: "dm-1", database: "SERVICE_DB" } as TreeNode, target!)).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { SIDEBAR_TREE_ROW_HEIGHT, type FlatTreeNode } from "@/composables/useFlatTree";
|
||||
import { tableMetaForDataTab } from "@/lib/table/tableDataTabMeta";
|
||||
import type { QueryTab, TreeNode } from "@/types/database";
|
||||
|
||||
export type ActiveTabSidebarTarget =
|
||||
@@ -114,13 +115,14 @@ export function activeTabSidebarTarget(tab: QueryTab | undefined | null): Active
|
||||
}
|
||||
|
||||
if (tab.mode === "data") {
|
||||
const tableName = tab.tableMeta?.tableName || tab.title;
|
||||
const tableMeta = tableMetaForDataTab(tab);
|
||||
const tableName = tableMeta?.tableName || tab.title;
|
||||
if (!tableName) return null;
|
||||
return {
|
||||
type: "table",
|
||||
connectionId: tab.connectionId,
|
||||
database: tab.database,
|
||||
schema: tab.tableMeta?.schema ?? tab.schema,
|
||||
database: tableMeta?.database ?? tab.database,
|
||||
schema: tableMeta?.schema ?? tab.schema,
|
||||
tableName,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ export function tableMetaForDataTab(tab: QueryTab | undefined): DataTabTableMeta
|
||||
// Keep filters usable when the table identity loaded but its column metadata did not.
|
||||
return {
|
||||
...tab.tableMeta,
|
||||
schema: tab.schema,
|
||||
schema: tab.tableMeta?.schema ?? tab.schema,
|
||||
tableName,
|
||||
columns: (tab.result?.columns ?? []).map(fallbackColumnInfo),
|
||||
primaryKeys: tab.tableMeta?.primaryKeys ?? [],
|
||||
|
||||
Reference in new issue
Block a user