feat(sidebar): extend table grouping to all object containers
This commit is contained in:
1 parent
e1a512fd59
commit
591e8f4909
20 files changed
+607
-169
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { shallowRef } from "vue";
|
||||
import type { TreeNode } from "@/types/database";
|
||||
import { findTreeNodeById } from "@/lib/sql/newQueryContext";
|
||||
import { isTableVGroupContainerNode } from "@/lib/table/tableVGroup";
|
||||
import { isTableVGroupContainerNode, tableVGroupDropAcceptsRow } from "@/lib/table/tableVGroup";
|
||||
|
||||
/**
|
||||
* Shared drop feedback for dragging a table row onto a virtual group row.
|
||||
@@ -26,7 +26,7 @@ export interface TableVGroupDropTarget {
|
||||
* above the row, so a single elementFromPoint hit often misses it. Cross-scope
|
||||
* drops are rejected so a table name never lands in another database's layout.
|
||||
*/
|
||||
export function resolveTableVGroupDropTarget(x: number, y: number, treeNodes: TreeNode[], source: { connectionId?: string; database?: string; schema?: string }): TableVGroupDropTarget | null {
|
||||
export function resolveTableVGroupDropTarget(x: number, y: number, treeNodes: TreeNode[], source: { connectionId?: string; database?: string; schema?: string; objectType?: TreeNode["type"] }): TableVGroupDropTarget | null {
|
||||
// Some environments (and component-test DOMs) do not implement hit testing.
|
||||
const elements = typeof document.elementsFromPoint === "function" ? document.elementsFromPoint(x, y) : [];
|
||||
for (const element of elements) {
|
||||
@@ -37,6 +37,9 @@ export function resolveTableVGroupDropTarget(x: number, y: number, treeNodes: Tr
|
||||
if (!node || node.connectionId !== source.connectionId || (node.database ?? "") !== (source.database ?? "")) continue;
|
||||
// 跨 schema:双方都声明且不同 → 拒绝(任一方未知则容忍,交给 database 校验兜底)。
|
||||
if (node.schema && source.schema && node.schema !== source.schema) continue;
|
||||
// 跨类别:视图/过程/触发器行不得落入其他类别的分组或容器,否则会写幻影成员、
|
||||
// 同名时还会误移真实成员。objectType 缺省(表引用拖拽)保持既有行为。
|
||||
if (source.objectType && !tableVGroupDropAcceptsRow(treeNodes, node, source.objectType)) continue;
|
||||
if (node.type === "table-vgroup" && node.vgroupId) return { node, groupId: node.vgroupId };
|
||||
if (isTableVGroupContainerNode(node)) return { node, groupId: null };
|
||||
}
|
||||
|
||||
@@ -8,7 +8,10 @@ import {
|
||||
createTableVGroup,
|
||||
deleteTableVGroups,
|
||||
emptyTableVGroupLayout,
|
||||
findTableVGroupContainerNode,
|
||||
hasTableTreeLoadMore,
|
||||
isTableVGroupContainerNode,
|
||||
isTableVGroupGroupableRowType,
|
||||
moveTableToVGroup,
|
||||
normalizeTableVGroupLayout,
|
||||
pruneTableVGroupMembers,
|
||||
@@ -17,6 +20,8 @@ import {
|
||||
selectedTableVGroupMoveTargets,
|
||||
stripTableVGroupsFromChildren,
|
||||
tableVGroupDestinationRows,
|
||||
tableVGroupDropAcceptsRow,
|
||||
tableVGroupKindOfContainerNode,
|
||||
tableVGroupPathForTable,
|
||||
tableVGroupScopeKey,
|
||||
toggleTableVGroupCollapsed,
|
||||
@@ -390,3 +395,144 @@ function findGroupChildren(layout: ReturnType<typeof reorderTableVGroupEntry>, g
|
||||
};
|
||||
return visit(layout.order);
|
||||
}
|
||||
|
||||
describe("container-kind scoped groups (views/procedures/triggers)", () => {
|
||||
const VIEW_SCOPE = { connectionId: "conn-1", database: "db1", objectType: "views" as const };
|
||||
|
||||
function viewNode(name: string): TreeNode {
|
||||
return { id: `view:${name}`, label: name, type: "view", connectionId: "conn-1", database: "db1" };
|
||||
}
|
||||
|
||||
function materializedViewNode(name: string): TreeNode {
|
||||
return { id: `mview:${name}`, label: name, type: "materialized_view", connectionId: "conn-1", database: "db1" };
|
||||
}
|
||||
|
||||
it("keeps the tables scope key byte-identical and suffixes the other kinds", () => {
|
||||
expect(tableVGroupScopeKey({ connectionId: "conn-1", database: "db1" })).toBe("conn-1\u0000\u0000\u0000db1\u0000");
|
||||
expect(tableVGroupScopeKey(VIEW_SCOPE)).toBe("conn-1\u0000\u0000\u0000db1\u0000\u0000views");
|
||||
expect(tableVGroupScopeKey({ connectionId: "conn-1", database: "db1", objectType: "triggers" })).toBe("conn-1\u0000\u0000\u0000db1\u0000\u0000triggers");
|
||||
});
|
||||
|
||||
it("maps containers to kinds and rejects table-child trigger groups", () => {
|
||||
expect(tableVGroupKindOfContainerNode({ type: "database" })).toBe("tables");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-tables" })).toBe("tables");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-views" })).toBe("views");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-materialized-views" })).toBe("materialized_views");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-procedures" })).toBe("procedures");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-functions" })).toBe("functions");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-triggers" })).toBe("triggers");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-triggers", tableName: "t1" })).toBeNull();
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-sequences" })).toBe("sequences");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-events" })).toBe("events");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-synonyms" })).toBe("synonyms");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-jobs" })).toBe("jobs");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-packages" })).toBe("packages");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-types" })).toBe("types");
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-tablespaces" })).toBeNull();
|
||||
expect(tableVGroupKindOfContainerNode({ type: "group-dolt-system-tables" })).toBeNull();
|
||||
});
|
||||
|
||||
it("projects view rows under the views scope and passes non-member rows through", () => {
|
||||
const created = createTableVGroup(emptyTableVGroupLayout(), "支付视图");
|
||||
const withMember = moveTableToVGroup(created.layout, "v_payment", created.groupId);
|
||||
const projected = applyTableVGroupsToChildren([materializedViewNode("mv_a"), viewNode("v_payment"), viewNode("v_other")], withMember, VIEW_SCOPE);
|
||||
expect(groupIds(projected)).toHaveLength(1);
|
||||
expect(projected[0]!.label).toBe("支付视图");
|
||||
expect((projected[0]!.children ?? []).map((node) => node.label)).toEqual(["v_payment"]);
|
||||
expect(projected.map((node) => node.type)).toEqual(["table-vgroup", "materialized_view", "view"]);
|
||||
});
|
||||
|
||||
it("re-projecting view containers stays idempotent", () => {
|
||||
const created = createTableVGroup(emptyTableVGroupLayout(), "分组");
|
||||
const withMember = moveTableToVGroup(created.layout, "v_a", created.groupId);
|
||||
const once = applyTableVGroupsToChildren([viewNode("v_a"), viewNode("v_b")], withMember, VIEW_SCOPE);
|
||||
const twice = applyTableVGroupsToChildren(once, withMember, VIEW_SCOPE);
|
||||
expect(groupIds(twice)).toEqual(groupIds(once));
|
||||
});
|
||||
|
||||
it("resolves view rows and projected group rows to the views scope of the host", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const groupRow: TreeNode = { id: "table-vgroup:g1", label: "分组", type: "table-vgroup", connectionId: "conn-1", database: "db1", vgroupId: "g1" };
|
||||
const groupViews: TreeNode = { id: "gv:conn-1:db1", label: "Views", type: "group-views", connectionId: "conn-1", database: "db1", children: [groupRow, viewNode("v_a")] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [groupViews, viewNode("v_a")] }];
|
||||
expect(resolveTableVGroupScopeFromNode(tree, viewNode("v_a"))).toMatchObject({ connectionId: "conn-1", database: "db1", objectType: "views" });
|
||||
expect(resolveTableVGroupScopeFromNode(tree, groupRow)).toMatchObject({ connectionId: "conn-1", database: "db1", objectType: "views" });
|
||||
});
|
||||
|
||||
it("refuses a scope for view rows without a views container (simple mixed lists)", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1", children: [tableNode("t_a"), viewNode("v_a")] };
|
||||
expect(tableVGroupScopeKey(resolveTableVGroupScopeFromNode([database], viewNode("v_a")))).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves a member row already inside a projected group to the same views scope", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const member: TreeNode = { id: "view:v_in_group", label: "v_in_group", type: "view", connectionId: "conn-1", database: "db1" };
|
||||
const groupRow: TreeNode = { id: "table-vgroup:g9", label: "组", type: "table-vgroup", connectionId: "conn-1", database: "db1", vgroupId: "g9", children: [member] };
|
||||
const groupViews: TreeNode = { id: "gv:2", label: "Views", type: "group-views", connectionId: "conn-1", database: "db1", children: [groupRow, viewNode("v_top")] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [groupViews] }];
|
||||
expect(resolveTableVGroupScopeFromNode(tree, member)).toMatchObject({ connectionId: "conn-1", database: "db1", objectType: "views" });
|
||||
});
|
||||
|
||||
it("narrows reprojection candidates to the scope kind even without a member label", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const groupTables: TreeNode = { id: "gt:1", label: "Tables", type: "group-tables", connectionId: "conn-1", database: "db1" };
|
||||
const groupFunctions: TreeNode = { id: "gf:1", label: "Functions", type: "group-functions", connectionId: "conn-1", database: "db1", children: [{ id: "fn:1", label: "vg_count", type: "function", connectionId: "conn-1", database: "db1" }] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [groupTables, groupFunctions] }];
|
||||
expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1", objectType: "tables" })).toBe(tree[0]);
|
||||
});
|
||||
|
||||
it("collects member names per container kind", () => {
|
||||
const children = [viewNode("v_a"), tableNode("t_a"), materializedViewNode("mv_a")];
|
||||
expect(collectTableTreeNames(children, "views")).toEqual(new Set(["v_a"]));
|
||||
expect(collectTableTreeNames(children, "materialized_views")).toEqual(new Set(["mv_a"]));
|
||||
expect(collectTableTreeNames(children, "tables")).toEqual(new Set(["t_a"]));
|
||||
});
|
||||
|
||||
it("keeps mixed selections type-pure when moving to groups", () => {
|
||||
const view = viewNode("v_a");
|
||||
const table = tableNode("t_a");
|
||||
expect(isTableVGroupGroupableRowType("materialized_view")).toBe(true);
|
||||
expect(isTableVGroupGroupableRowType("load-more")).toBe(false);
|
||||
expect(isTableVGroupGroupableRowType("index")).toBe(false);
|
||||
expect(selectedTableVGroupMoveTargets(view, [view, table])).toEqual([view]);
|
||||
expect(selectedTableVGroupMoveTargets(view, [view, viewNode("v_b")])).toEqual([view, viewNode("v_b")]);
|
||||
});
|
||||
|
||||
it("finds the holding container of a member row by kind", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const groupViews: TreeNode = { id: "gv:conn-1:db1", label: "Views", type: "group-views", connectionId: "conn-1", database: "db1", children: [viewNode("v_a")] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [groupViews] }];
|
||||
expect(isTableVGroupContainerNode(groupViews)).toBe(true);
|
||||
expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1" }, "v_a", "view")).toBe(groupViews);
|
||||
// kind 隔离:表成员定位永不落入 views 容器;缺失成员回退宿主(分页语义)
|
||||
expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1" }, "v_a", "table")).toBe(tree[0]);
|
||||
expect(findTableVGroupContainerNode(tree, { connectionId: "conn-1", database: "db1" }, "t_missing", "table")).toBe(tree[0]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("container-kind drop and scope isolation", () => {
|
||||
it("rejects cross-kind drop targets and accepts same-kind ones", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const groupViews: TreeNode = { id: "gv:1", label: "Views", type: "group-views", connectionId: "conn-1", database: "db1", children: [{ id: "vg-row:1", label: "分组", type: "table-vgroup", connectionId: "conn-1", database: "db1", vgroupId: "g1" }] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [groupViews] }];
|
||||
expect(tableVGroupDropAcceptsRow(tree, groupViews, "view")).toBe(true);
|
||||
expect(tableVGroupDropAcceptsRow(tree, groupViews, "table")).toBe(false);
|
||||
expect(tableVGroupDropAcceptsRow(tree, database, "view")).toBe(false);
|
||||
expect(tableVGroupDropAcceptsRow(tree, database, "table")).toBe(true);
|
||||
const groupRow = groupViews.children![0]!;
|
||||
expect(tableVGroupDropAcceptsRow(tree, groupRow, "view")).toBe(true);
|
||||
expect(tableVGroupDropAcceptsRow(tree, groupRow, "table")).toBe(false);
|
||||
});
|
||||
|
||||
it("refuses a scope for table-child trigger rows sharing names with database triggers", () => {
|
||||
const database: TreeNode = { id: "db:conn-1:db1", label: "db1", type: "database", connectionId: "conn-1", database: "db1" };
|
||||
const dbTrigger: TreeNode = { id: "dbtrig:1", label: "tg_a", type: "trigger", connectionId: "conn-1", database: "db1" };
|
||||
const dbTriggers: TreeNode = { id: "gt:1", label: "Triggers", type: "group-triggers", connectionId: "conn-1", database: "db1", children: [dbTrigger] };
|
||||
const tableTrigger: TreeNode = { id: "tbltrig:1", label: "tg_a", type: "trigger", connectionId: "conn-1", database: "db1", parentName: "t1" };
|
||||
const tableTriggers: TreeNode = { id: "tt:1", label: "Triggers", type: "group-triggers", connectionId: "conn-1", database: "db1", tableName: "t1", children: [tableTrigger] };
|
||||
const table: TreeNode = { id: "table:t1", label: "t1", type: "table", connectionId: "conn-1", database: "db1", children: [tableTriggers] };
|
||||
const tree: TreeNode[] = [{ ...database, children: [dbTriggers, table] }];
|
||||
expect(tableVGroupScopeKey(resolveTableVGroupScopeFromNode(tree, dbTrigger))).toBe("conn-1\u0000\u0000\u0000db1\u0000\u0000triggers");
|
||||
expect(tableVGroupScopeKey(resolveTableVGroupScopeFromNode(tree, tableTrigger))).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -13,12 +13,21 @@ export type { TableVGroupLayout, TableVGroupOrderEntry };
|
||||
|
||||
export type TableVGroupDropPosition = "before" | "after" | "inside";
|
||||
|
||||
/**
|
||||
* 分组作用域覆盖的对象容器类别。tables 是 #3470 起的既有行为;views /
|
||||
* procedures / triggers 对应 #9446 方向一与 #9733;其余容器类别为同一机制的
|
||||
* 全量补齐(与 groupDefs 的库级对象容器一一对应)。
|
||||
*/
|
||||
export type TableVGroupObjectKind = "tables" | "views" | "materialized_views" | "procedures" | "functions" | "triggers" | "sequences" | "events" | "synonyms" | "jobs" | "packages" | "types";
|
||||
|
||||
export interface TableVGroupScope {
|
||||
connectionId?: string;
|
||||
catalog?: string;
|
||||
database?: string;
|
||||
schema?: string;
|
||||
linkedServer?: string;
|
||||
/** 本布局归属的容器类别;缺省视为 tables(历史 scope 均为表分组)。 */
|
||||
objectType?: TableVGroupObjectKind;
|
||||
}
|
||||
|
||||
type TableVGroupEntry = Extract<TableVGroupOrderEntry, { type: "group" }>;
|
||||
@@ -38,7 +47,10 @@ export function tableVGroupsEnabled(layout: TableVGroupLayout | null | undefined
|
||||
|
||||
export function tableVGroupScopeKey(scope: TableVGroupScope): string | null {
|
||||
if (!scope.connectionId || !scope.database) return null;
|
||||
return [scope.connectionId, scope.linkedServer ?? "", scope.catalog ?? "", scope.database, scope.schema ?? ""].join("\u0000");
|
||||
const parts = [scope.connectionId, scope.linkedServer ?? "", scope.catalog ?? "", scope.database, scope.schema ?? ""];
|
||||
// 仅非表容器在尾部追加类别段:表分组的 key 与历史持久化逐字节一致,零迁移。
|
||||
if (scope.objectType && scope.objectType !== "tables") parts.push(scope.objectType);
|
||||
return parts.join("\u0000");
|
||||
}
|
||||
|
||||
const TABLE_VGROUP_NODE_ID_PREFIX = "table-vgroup:";
|
||||
@@ -53,28 +65,106 @@ export function tableVGroupIdFromNodeId(nodeId: string): string | null {
|
||||
return nodeId.startsWith(TABLE_VGROUP_NODE_ID_PREFIX) ? nodeId.slice(TABLE_VGROUP_NODE_ID_PREFIX.length) : null;
|
||||
}
|
||||
|
||||
/** Tree node types whose direct children may contain table nodes to group. */
|
||||
const TABLE_VGROUP_CONTAINER_TYPES: ReadonlySet<TreeNode["type"]> = new Set(["database", "schema", "linked-server-schema", "group-tables"]);
|
||||
/**
|
||||
* 承载可分组行的容器行 → 分组类别。group-triggers 双栖:库级触发器列表与
|
||||
* 表结构子组共用同一 type,表子级带 tableName,不算库级分组容器。
|
||||
*/
|
||||
export function tableVGroupKindOfContainerNode(node: Pick<TreeNode, "type" | "tableName">): TableVGroupObjectKind | null {
|
||||
switch (node.type) {
|
||||
case "database":
|
||||
case "schema":
|
||||
case "linked-server-schema":
|
||||
case "group-tables":
|
||||
return "tables";
|
||||
case "group-views":
|
||||
return "views";
|
||||
case "group-materialized-views":
|
||||
return "materialized_views";
|
||||
case "group-procedures":
|
||||
return "procedures";
|
||||
case "group-functions":
|
||||
return "functions";
|
||||
case "group-triggers":
|
||||
// 双栖 type:库级触发器列表与表结构子组共用;表子级带 tableName。
|
||||
return node.tableName ? null : "triggers";
|
||||
case "group-sequences":
|
||||
return "sequences";
|
||||
case "group-events":
|
||||
return "events";
|
||||
case "group-synonyms":
|
||||
return "synonyms";
|
||||
case "group-jobs":
|
||||
return "jobs";
|
||||
case "group-packages":
|
||||
return "packages";
|
||||
case "group-types":
|
||||
return "types";
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/** 各类别容器里可被分组的行 type;成员身份仍是容器内的行 label。 */
|
||||
const TABLE_VGROUP_KIND_ROW_TYPES: Record<TableVGroupObjectKind, Record<string, true>> = {
|
||||
tables: { table: true },
|
||||
views: { view: true },
|
||||
materialized_views: { materialized_view: true },
|
||||
procedures: { procedure: true },
|
||||
functions: { function: true },
|
||||
triggers: { trigger: true },
|
||||
sequences: { sequence: true },
|
||||
events: { event: true },
|
||||
synonyms: { synonym: true },
|
||||
jobs: { job: true },
|
||||
// packages/types 的 spec 与 body 行同名(label 键控成员身份),入组必然合并为
|
||||
// 单一成员条目——已知限制:同名双行无法分别归属不同分组。
|
||||
packages: { package: true, "package-body": true },
|
||||
types: { type: true, "type-body": true },
|
||||
};
|
||||
|
||||
/** 该行 type 是否可被分入某类容器(拖拽源、移动菜单等入口的快速过滤)。 */
|
||||
export function isTableVGroupGroupableRowType(type: TreeNode["type"]): boolean {
|
||||
switch (type) {
|
||||
case "table":
|
||||
case "view":
|
||||
case "materialized_view":
|
||||
case "procedure":
|
||||
case "function":
|
||||
case "trigger":
|
||||
case "sequence":
|
||||
case "event":
|
||||
case "synonym":
|
||||
case "job":
|
||||
case "package":
|
||||
case "package-body":
|
||||
case "type":
|
||||
case "type-body":
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 行的身份字段即 scope 字段;分组节点与各类容器直接自带这五项。 */
|
||||
function tableVGroupScopeFieldsOf(node: TreeNode): TableVGroupScope {
|
||||
return { connectionId: node.connectionId, catalog: node.catalog, database: node.database, schema: node.schema, linkedServer: node.linkedServer };
|
||||
}
|
||||
|
||||
/** 承载表行的容器行:分组投影的挂载点,也是拖拽「移出分组」的落点。 */
|
||||
/** 分组投影的挂载点,也是拖拽「移出分组」的落点。 */
|
||||
export function isTableVGroupContainerNode(node: TreeNode): boolean {
|
||||
return TABLE_VGROUP_CONTAINER_TYPES.has(node.type);
|
||||
return tableVGroupKindOfContainerNode(node) !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Selection semantics for "move to group", mirroring the connection tree: when
|
||||
* several rows are selected and the right-clicked table is part of that
|
||||
* several rows are selected and the right-clicked row is part of that
|
||||
* selection, the whole selection moves; anything outside the right-clicked
|
||||
* table's connection+database scope is ignored. Otherwise only the clicked row.
|
||||
* row's connection+database+type scope is ignored. Otherwise only the clicked
|
||||
* row.
|
||||
*/
|
||||
export function selectedTableVGroupMoveTargets(currentNode: TreeNode, selectedNodes: readonly TreeNode[]): TreeNode[] {
|
||||
if (currentNode.type !== "table" || !currentNode.connectionId) return currentNode.type === "table" ? [currentNode] : [];
|
||||
const inScope = (node: TreeNode) => node.type === "table" && node.connectionId === currentNode.connectionId && (node.database ?? "") === (currentNode.database ?? "") && (node.schema ?? "") === (currentNode.schema ?? "");
|
||||
if (!isTableVGroupGroupableRowType(currentNode.type) || !currentNode.connectionId) return isTableVGroupGroupableRowType(currentNode.type) ? [currentNode] : [];
|
||||
const inScope = (node: TreeNode) => node.type === currentNode.type && node.connectionId === currentNode.connectionId && (node.database ?? "") === (currentNode.database ?? "") && (node.schema ?? "") === (currentNode.schema ?? "");
|
||||
const selectedContainsCurrent = selectedNodes.some((node) => node.id === currentNode.id);
|
||||
if (selectedNodes.length > 1 && selectedContainsCurrent && selectedNodes.every(inScope)) return [...selectedNodes];
|
||||
return [currentNode];
|
||||
@@ -104,8 +194,13 @@ function containsGroup(entry: TableVGroupOrderEntry, groupId: string): boolean {
|
||||
return entryChildren(entry).some((child) => containsGroup(child, groupId));
|
||||
}
|
||||
|
||||
function removeTableFromEntries(entries: TableVGroupOrderEntry[], tableName: string): TableVGroupOrderEntry[] {
|
||||
return entries.filter((entry) => !(entry.type === "table" && entry.name === tableName)).map((entry) => (entry.type === "group" ? { type: "group" as const, id: entry.id, children: removeTableFromEntries(entryChildren(entry), tableName) } : entry));
|
||||
/** 成员条目与 (名字, 行类型) 的匹配:rowType 给定时旧的无类型条目(历史数据)也视为命中。 */
|
||||
function matchesTableEntry(entry: TableVGroupOrderEntry, name: string, rowType?: string): boolean {
|
||||
return entry.type === "table" && entry.name === name && (!rowType || !entry.rowType || entry.rowType === rowType);
|
||||
}
|
||||
|
||||
function removeTableFromEntries(entries: TableVGroupOrderEntry[], tableName: string, rowType?: string): TableVGroupOrderEntry[] {
|
||||
return entries.filter((entry) => !matchesTableEntry(entry, tableName, rowType)).map((entry) => (entry.type === "group" ? { type: "group" as const, id: entry.id, children: removeTableFromEntries(entryChildren(entry), tableName, rowType) } : entry));
|
||||
}
|
||||
|
||||
function expandGroup(layout: TableVGroupLayout, groupId: string): TableVGroupLayout {
|
||||
@@ -115,10 +210,10 @@ function expandGroup(layout: TableVGroupLayout, groupId: string): TableVGroupLay
|
||||
};
|
||||
}
|
||||
|
||||
export function moveTableToVGroup(layout: TableVGroupLayout, tableName: string, targetGroupId: string | null): TableVGroupLayout {
|
||||
export function moveTableToVGroup(layout: TableVGroupLayout, tableName: string, targetGroupId: string | null, rowType?: string): TableVGroupLayout {
|
||||
if (!hasTableVGroupEntries(layout)) return layout;
|
||||
const order = removeTableFromEntries(cloneEntries(layout.order), tableName);
|
||||
const entry: TableVGroupOrderEntry = { type: "table", name: tableName };
|
||||
const order = removeTableFromEntries(cloneEntries(layout.order), tableName, rowType);
|
||||
const entry: TableVGroupOrderEntry = { type: "table", name: tableName, ...(rowType ? { rowType } : {}) };
|
||||
|
||||
if (targetGroupId) {
|
||||
const group = findGroupEntry(order, targetGroupId);
|
||||
@@ -277,11 +372,11 @@ export function tableVGroupDestinationRows(layout: TableVGroupLayout | null | un
|
||||
}
|
||||
|
||||
/** Stable root-to-leaf group-id path containing the table, empty when ungrouped. */
|
||||
export function tableVGroupPathForTable(layout: TableVGroupLayout | null | undefined, tableName: string): string[] {
|
||||
export function tableVGroupPathForTable(layout: TableVGroupLayout | null | undefined, tableName: string, rowType?: string): string[] {
|
||||
if (!hasTableVGroupEntries(layout)) return [];
|
||||
const walk = (entries: TableVGroupOrderEntry[], path: string[]): string[] | null => {
|
||||
for (const entry of entries) {
|
||||
if (entry.type === "table" && entry.name === tableName) return path;
|
||||
if (matchesTableEntry(entry, tableName, rowType)) return path;
|
||||
if (entry.type !== "group") continue;
|
||||
const found = walk(entryChildren(entry), [...path, entry.id]);
|
||||
if (found) return found;
|
||||
@@ -295,17 +390,30 @@ export function tableVGroupPathForTable(layout: TableVGroupLayout | null | undef
|
||||
// Display projection
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
interface TableVGroupFlatTable {
|
||||
interface TableVGroupFlatRow {
|
||||
node: TreeNode;
|
||||
flatIndex: number;
|
||||
}
|
||||
|
||||
function buildVGroupChildNodes(entries: TableVGroupOrderEntry[], layout: TableVGroupLayout, tables: Map<string, TableVGroupFlatTable>, scope: TableVGroupScope): TreeNode[] {
|
||||
/** 双索引成员行查找:rowType 精确键 O(1);无 rowType(历史条目与表)走同名首行索引 O(1)。 */
|
||||
interface TableVGroupRowLookup {
|
||||
byKey: Map<string, TableVGroupFlatRow>;
|
||||
byLabel: Map<string, TableVGroupFlatRow>;
|
||||
}
|
||||
|
||||
function findRowIn(lookup: TableVGroupRowLookup, name: string, rowType?: string): TableVGroupFlatRow | undefined {
|
||||
if (rowType) return lookup.byKey.get(`${rowType}\u0000${name}`);
|
||||
return lookup.byLabel.get(name);
|
||||
}
|
||||
|
||||
const tableRowKey = (type: string, label: string): string => `${type}\u0000${label}`;
|
||||
|
||||
function buildVGroupChildNodes(entries: TableVGroupOrderEntry[], layout: TableVGroupLayout, lookup: TableVGroupRowLookup, scope: TableVGroupScope): TreeNode[] {
|
||||
const nodes: TreeNode[] = [];
|
||||
for (const entry of entries) {
|
||||
if (entry.type === "table") {
|
||||
const table = tables.get(entry.name);
|
||||
if (table) nodes.push(table.node);
|
||||
const row = findRowIn(lookup, entry.name, entry.rowType);
|
||||
if (row) nodes.push(row.node);
|
||||
continue;
|
||||
}
|
||||
const group = layout.groups.find((candidate) => candidate.id === entry.id);
|
||||
@@ -320,8 +428,9 @@ function buildVGroupChildNodes(entries: TableVGroupOrderEntry[], layout: TableVG
|
||||
schema: scope.schema,
|
||||
linkedServer: scope.linkedServer,
|
||||
vgroupId: entry.id,
|
||||
vgroupKind: scope.objectType ?? "tables",
|
||||
isExpanded: !group.collapsed,
|
||||
children: buildVGroupChildNodes(entryChildren(entry), layout, tables, scope),
|
||||
children: buildVGroupChildNodes(entryChildren(entry), layout, lookup, scope),
|
||||
});
|
||||
}
|
||||
return nodes;
|
||||
@@ -330,15 +439,15 @@ function buildVGroupChildNodes(entries: TableVGroupOrderEntry[], layout: TableVG
|
||||
/**
|
||||
* Build the root-level projected nodes. Virtual groups always float to the top
|
||||
* of the container in layout order (matching Navicat's table groups), followed
|
||||
* by ungrouped tables and non-table rows at their original flat positions.
|
||||
* by ungrouped rows and non-member rows at their original flat positions.
|
||||
*/
|
||||
function buildVGroupRootNodes(entries: TableVGroupOrderEntry[], layout: TableVGroupLayout, tables: Map<string, TableVGroupFlatTable>, scope: TableVGroupScope): Array<{ node: TreeNode; sortIndex: number }> {
|
||||
function buildVGroupRootNodes(entries: TableVGroupOrderEntry[], layout: TableVGroupLayout, lookup: TableVGroupRowLookup, scope: TableVGroupScope): Array<{ node: TreeNode; sortIndex: number }> {
|
||||
const out: Array<{ node: TreeNode; sortIndex: number }> = [];
|
||||
let groupSeq = 0;
|
||||
for (const entry of entries) {
|
||||
if (entry.type === "table") {
|
||||
const table = tables.get(entry.name);
|
||||
if (table) out.push({ node: table.node, sortIndex: table.flatIndex });
|
||||
const row = findRowIn(lookup, entry.name, entry.rowType);
|
||||
if (row) out.push({ node: row.node, sortIndex: row.flatIndex });
|
||||
continue;
|
||||
}
|
||||
const group = layout.groups.find((candidate) => candidate.id === entry.id);
|
||||
@@ -354,8 +463,9 @@ function buildVGroupRootNodes(entries: TableVGroupOrderEntry[], layout: TableVGr
|
||||
schema: scope.schema,
|
||||
linkedServer: scope.linkedServer,
|
||||
vgroupId: entry.id,
|
||||
vgroupKind: scope.objectType ?? "tables",
|
||||
isExpanded: !group.collapsed,
|
||||
children: buildVGroupChildNodes(entryChildren(entry), layout, tables, scope),
|
||||
children: buildVGroupChildNodes(entryChildren(entry), layout, lookup, scope),
|
||||
},
|
||||
// -1e6 keeps every group above flat rows while preserving layout order among groups.
|
||||
sortIndex: -1_000_000 + groupSeq++,
|
||||
@@ -365,11 +475,11 @@ function buildVGroupRootNodes(entries: TableVGroupOrderEntry[], layout: TableVGr
|
||||
}
|
||||
|
||||
/**
|
||||
* Rearrange loaded table nodes under their virtual groups. Pure display-level
|
||||
* transform over an already-loaded child list: table node objects are
|
||||
* re-parented by reference so per-node state (isExpanded / isLoading / loaded
|
||||
* children) survives projection. Members missing from the loaded page simply
|
||||
* stay absent (sidebar pagination); stale names are skipped.
|
||||
* Rearrange loaded container rows under their virtual groups. Pure
|
||||
* display-level transform over an already-loaded child list: row node objects
|
||||
* are re-parented by reference so per-node state (isExpanded / isLoading /
|
||||
* loaded children) survives projection. Members missing from the loaded page
|
||||
* simply stay absent (sidebar pagination); stale names are skipped.
|
||||
*/
|
||||
export function applyTableVGroupsToChildren(children: TreeNode[], layout: TableVGroupLayout | null | undefined, scope: TableVGroupScope): TreeNode[] {
|
||||
if (!children.length || !layout || !tableVGroupsEnabled(layout)) return children;
|
||||
@@ -379,27 +489,32 @@ export function applyTableVGroupsToChildren(children: TreeNode[], layout: TableV
|
||||
const activeLayout = layout;
|
||||
const flatChildren = stripTableVGroupsFromChildren(children);
|
||||
|
||||
const tables = new Map<string, TableVGroupFlatTable>();
|
||||
// scope.objectType 决定哪些行参与分组;缺省 tables 维持既有表分组行为。
|
||||
const rowTypes = TABLE_VGROUP_KIND_ROW_TYPES[scope.objectType ?? "tables"];
|
||||
const rows: TableVGroupRowLookup = { byKey: new Map(), byLabel: new Map() };
|
||||
const passthrough: Array<{ node: TreeNode; sortIndex: number }> = [];
|
||||
for (let i = 0; i < flatChildren.length; i++) {
|
||||
const node = flatChildren[i]!;
|
||||
if (node.type === "table" && !tables.has(node.label)) tables.set(node.label, { node, flatIndex: i });
|
||||
else passthrough.push({ node, sortIndex: i });
|
||||
// 键为 (行类型, 名字):包 spec/body 同名双行可各自独立成组员;同名首行别名供历史条目按名匹配。
|
||||
if (rowTypes[node.type] && !rows.byKey.has(tableRowKey(node.type, node.label))) {
|
||||
rows.byKey.set(tableRowKey(node.type, node.label), { node, flatIndex: i });
|
||||
if (!rows.byLabel.has(node.label)) rows.byLabel.set(node.label, { node, flatIndex: i });
|
||||
} else passthrough.push({ node, sortIndex: i });
|
||||
}
|
||||
if (!tables.size) return flatChildren;
|
||||
if (!rows.byKey.size) return flatChildren;
|
||||
|
||||
const rootBuilt = buildVGroupRootNodes(activeLayout.order, activeLayout, tables, scope);
|
||||
// Tables the layout does not reference stay ungrouped at their original slot.
|
||||
const rootBuilt = buildVGroupRootNodes(activeLayout.order, activeLayout, rows, scope);
|
||||
// Rows the layout does not reference stay ungrouped at their original slot.
|
||||
const consumed = new Set<TreeNode>();
|
||||
const consume = (nodes: TreeNode[]) => {
|
||||
for (const node of nodes) {
|
||||
if (node.type === "table") consumed.add(node);
|
||||
if (rowTypes[node.type]) consumed.add(node);
|
||||
else consume(node.children ?? []);
|
||||
}
|
||||
};
|
||||
consume(rootBuilt.map((item) => item.node));
|
||||
for (const table of tables.values()) {
|
||||
if (!consumed.has(table.node)) passthrough.push({ node: table.node, sortIndex: table.flatIndex });
|
||||
for (const row of rows.byKey.values()) {
|
||||
if (!consumed.has(row.node)) passthrough.push({ node: row.node, sortIndex: row.flatIndex });
|
||||
}
|
||||
|
||||
const merged = [...rootBuilt, ...passthrough];
|
||||
@@ -429,18 +544,38 @@ export function stripTableVGroupsFromChildren(children: TreeNode[]): TreeNode[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the live tree node whose children this scope's layout projects. Table
|
||||
* rows and their container do not always carry identical optional identity
|
||||
* fields (a simple-display database node has no schema while its table rows
|
||||
* do), so optional parts tolerate a missing value on either side; when several
|
||||
* containers match, the one that actually holds table rows wins.
|
||||
* Find the live tree node whose children this scope's layout projects. Rows
|
||||
* and their container do not always carry identical optional identity fields
|
||||
* (a simple-display database node has no schema while its rows do), so
|
||||
* optional parts tolerate a missing value on either side; when several
|
||||
* containers match, the one that actually holds member rows wins. A member
|
||||
* type narrows candidates to containers of a matching kind, and so does a
|
||||
* non-tables scope.objectType — without that, reprojection triggered by, say,
|
||||
* a functions-layout change could fall back onto the database container and
|
||||
* strip the tables grouping out of it.
|
||||
*/
|
||||
export function findTableVGroupContainerNode(nodes: TreeNode[], scope: TableVGroupScope, tableName?: string): TreeNode | null {
|
||||
export function findTableVGroupContainerNode(nodes: TreeNode[], scope: TableVGroupScope, memberLabel?: string, memberType?: string): TreeNode | null {
|
||||
const matchesOptional = (nodeValue: string | undefined, scopeValue: string | undefined) => nodeValue === scopeValue || !nodeValue || !scopeValue;
|
||||
// 目标类别:memberType(行解析)按成员类型收敛;scope.objectType(重投影)按
|
||||
// 类别收敛;tables 作用域(缺省)也必须收敛到 tables——否则其它类别的容器会混入
|
||||
// 候选池,tables 的无成员写入(建组/改名/折叠等)可能误路由过去并抹掉其分组投影。
|
||||
const scopeKind = scope.objectType && scope.objectType !== "tables" ? scope.objectType : null;
|
||||
const expectedKind = scopeKind ?? (memberType ? null : "tables");
|
||||
const memberRowTypes = memberType ? { [memberType]: true as const } : TABLE_VGROUP_KIND_ROW_TYPES[scope.objectType ?? "tables"];
|
||||
const candidates: TreeNode[] = [];
|
||||
const walk = (list: TreeNode[]) => {
|
||||
for (const node of list) {
|
||||
if (isTableVGroupContainerNode(node) && node.connectionId === scope.connectionId && (node.database ?? "") === (scope.database ?? "") && matchesOptional(node.catalog, scope.catalog) && matchesOptional(node.schema, scope.schema) && matchesOptional(node.linkedServer, scope.linkedServer)) {
|
||||
const kind = tableVGroupKindOfContainerNode(node);
|
||||
const kindMatches = expectedKind ? kind === expectedKind : kind !== null && TABLE_VGROUP_KIND_ROW_TYPES[kind][memberType!];
|
||||
if (
|
||||
kindMatches &&
|
||||
isTableVGroupContainerNode(node) &&
|
||||
node.connectionId === scope.connectionId &&
|
||||
(node.database ?? "") === (scope.database ?? "") &&
|
||||
matchesOptional(node.catalog, scope.catalog) &&
|
||||
matchesOptional(node.schema, scope.schema) &&
|
||||
matchesOptional(node.linkedServer, scope.linkedServer)
|
||||
) {
|
||||
candidates.push(node);
|
||||
}
|
||||
if (node.children) walk(node.children);
|
||||
@@ -449,11 +584,11 @@ export function findTableVGroupContainerNode(nodes: TreeNode[], scope: TableVGro
|
||||
walk(nodes);
|
||||
if (!candidates.length) return null;
|
||||
|
||||
if (tableName) {
|
||||
const holder = candidates.find((node) => (node.children ?? []).some((child) => child.type === "table" && child.label === tableName));
|
||||
if (memberLabel) {
|
||||
const holder = candidates.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] && child.label === memberLabel));
|
||||
if (holder) return holder;
|
||||
}
|
||||
return candidates.find((node) => (node.children ?? []).some((child) => child.type === "table" || child.type === "table-vgroup")) ?? candidates[0]!;
|
||||
return candidates.find((node) => (node.children ?? []).some((child) => memberRowTypes[child.type] || child.type === "table-vgroup")) ?? candidates[0]!;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -482,17 +617,20 @@ export function normalizeTableVGroupLayout(value: unknown): TableVGroupLayout {
|
||||
const normalizeEntries = (entries: unknown): TableVGroupOrderEntry[] => {
|
||||
const out: TableVGroupOrderEntry[] = [];
|
||||
if (!Array.isArray(entries)) return out;
|
||||
// 同一层里重复的表名或分组引用会投影出重复节点(渲染以 id 作 key),
|
||||
// 损坏的持久化数据必须在归一化这一步收敛。
|
||||
// 同一层里重复的成员条目或分组引用会投影出重复节点(渲染以 id 作 key),
|
||||
// 损坏的持久化数据必须在归一化这一步收敛。去重键含行类型:包 spec/body
|
||||
// 同名双行是合法共存,不算重复。
|
||||
const seenTableNames = new Set<string>();
|
||||
const seenGroupEntries = new Set<string>();
|
||||
for (const entry of entries) {
|
||||
if (!entry || typeof entry !== "object") continue;
|
||||
const candidate = entry as Partial<TableVGroupOrderEntry>;
|
||||
if (candidate.type === "table") {
|
||||
if (typeof candidate.name !== "string" || !candidate.name || seenTableNames.has(candidate.name)) continue;
|
||||
seenTableNames.add(candidate.name);
|
||||
out.push({ type: "table", name: candidate.name });
|
||||
const rowType = typeof candidate.rowType === "string" ? candidate.rowType : undefined;
|
||||
const dedupeKey = `${rowType ?? ""}\u0000${candidate.name}`;
|
||||
if (typeof candidate.name !== "string" || !candidate.name || seenTableNames.has(dedupeKey)) continue;
|
||||
seenTableNames.add(dedupeKey);
|
||||
out.push({ type: "table", name: candidate.name, ...(rowType ? { rowType } : {}) });
|
||||
} else if (candidate.type === "group" && typeof candidate.id === "string" && candidate.id && validGroupIds.has(candidate.id) && !seenGroupEntries.has(candidate.id)) {
|
||||
seenGroupEntries.add(candidate.id);
|
||||
out.push({ type: "group", id: candidate.id, children: normalizeEntries(entryChildren(candidate as TableVGroupEntry)) });
|
||||
@@ -540,24 +678,76 @@ function findTableVGroupHostContainer(nodes: TreeNode[], node: TreeNode): TreeNo
|
||||
return walk(nodes, []);
|
||||
}
|
||||
|
||||
/** 节点到根路径上最近的「可分组容器」;投影分组行的类别由它决定。 */
|
||||
function findTableVGroupHolderContainer(nodes: TreeNode[], node: TreeNode): TreeNode | null {
|
||||
const walk = (list: TreeNode[], ancestors: TreeNode[]): TreeNode | null => {
|
||||
for (const item of list) {
|
||||
if (item === node || item.id === node.id) {
|
||||
for (let i = ancestors.length - 1; i >= 0; i--) {
|
||||
const ancestor = ancestors[i]!;
|
||||
if (tableVGroupKindOfContainerNode(ancestor)) return ancestor;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
if (item.children) {
|
||||
const found = walk(item.children, [...ancestors, item]);
|
||||
if (found) return found;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
return walk(nodes, []);
|
||||
}
|
||||
|
||||
function tableVGroupScopeHostOf(nodes: TreeNode[], node: TreeNode): TreeNode {
|
||||
return isTableVGroupDisplayNode(node.type) ? (findTableVGroupHostContainer(nodes, node) ?? node) : node;
|
||||
}
|
||||
|
||||
/**
|
||||
* Derive the layout scope for any sidebar row: containers and group nodes own
|
||||
* their fields directly, while table rows resolve to their holding container —
|
||||
* in simple display mode a table row carries a schema its container lacks, so
|
||||
* using the row's own fields would split reads and writes across two keys.
|
||||
* Derive the layout scope for any sidebar row. Containers and projected group
|
||||
* rows resolve identity fields up to their host container (simple display
|
||||
* modes fill row-side schema fields the container lacks; using them would
|
||||
* split reads and writes across two keys) while the container kind comes from
|
||||
* the nearest groupable holder. Groupable rows resolve to the container of
|
||||
* their own type; when none exists (a view row in a mixed simple list, say)
|
||||
* the empty scope fails scope-key derivation so the row can never join a
|
||||
* tables-kind layout.
|
||||
*/
|
||||
export function resolveTableVGroupScopeFromNode(nodes: TreeNode[], node: TreeNode | TableVGroupScope): TableVGroupScope {
|
||||
const row = node as Partial<TreeNode> & TableVGroupScope;
|
||||
if (row.type === "table-vgroup" || row.type?.startsWith("group-")) return tableVGroupScopeFieldsOf(tableVGroupScopeHostOf(nodes, row as TreeNode));
|
||||
if (isTableVGroupContainerNode(row as TreeNode)) return tableVGroupScopeFieldsOf(row as TreeNode);
|
||||
const container = findTableVGroupContainerNode(nodes, row as TreeNode, row.type === "table" ? row.label : undefined);
|
||||
const containerKind = isTableVGroupContainerNode(row as TreeNode) ? tableVGroupKindOfContainerNode(row as TreeNode) : null;
|
||||
if (containerKind) return { ...tableVGroupScopeFieldsOf(tableVGroupScopeHostOf(nodes, row as TreeNode)), objectType: containerKind };
|
||||
if (row.type === "table-vgroup" || row.type?.startsWith("group-")) {
|
||||
const host = tableVGroupScopeHostOf(nodes, row as TreeNode);
|
||||
const holder = findTableVGroupHolderContainer(nodes, row as TreeNode);
|
||||
return { ...tableVGroupScopeFieldsOf(host), objectType: (holder && tableVGroupKindOfContainerNode(holder)) || "tables" };
|
||||
}
|
||||
if (row.type && isTableVGroupGroupableRowType(row.type)) {
|
||||
const holder = findTableVGroupContainerNode(nodes, tableVGroupScopeFieldsOf(row as TreeNode), row.label, row.type);
|
||||
// holder 子树(含投影出的分组层级)必须直接持有该行(同 id):label 在跨容器
|
||||
// 同名时会误配——表结构子组里的触发器行与库级触发器列表的行同名不同节点;
|
||||
// 而「子树」而非「顶层」是因为已入组的成员行挂在 table-vgroup 行下,仍属
|
||||
// 同一容器的管辖范围(移出/换组动作就是从这里发起的)。
|
||||
const holdsRow = (nodes?: TreeNode[]): boolean => (nodes ?? []).some((n) => n.id === row.id || (n.type === "table-vgroup" && holdsRow(n.children)));
|
||||
if (!holder || !holdsRow(holder.children)) return {};
|
||||
const host = tableVGroupScopeHostOf(nodes, holder);
|
||||
return { ...tableVGroupScopeFieldsOf(host), objectType: tableVGroupKindOfContainerNode(holder) ?? "tables" };
|
||||
}
|
||||
const container = findTableVGroupContainerNode(nodes, row as TreeNode);
|
||||
return tableVGroupScopeFieldsOf(container ? tableVGroupScopeHostOf(nodes, container) : (row as TreeNode));
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether a drag with the given source row type may land on this container or
|
||||
* projected group row. Cross-kind drops would write phantom members into the
|
||||
* other kind's layout (and same-label members could evict real ones), so the
|
||||
* drop target resolution has to reject them up front.
|
||||
*/
|
||||
export function tableVGroupDropAcceptsRow(nodes: TreeNode[], target: TreeNode, rowType: TreeNode["type"]): boolean {
|
||||
const kind = target.type === "table-vgroup" ? tableVGroupKindOfContainerNode(findTableVGroupHolderContainer(nodes, target) ?? target) : tableVGroupKindOfContainerNode(target);
|
||||
return !!kind && !!TABLE_VGROUP_KIND_ROW_TYPES[kind][rowType];
|
||||
}
|
||||
|
||||
/**
|
||||
* 任意深度出现分页游标都说明列表不完整:TDengine 等把末页游标嵌在 STABLE 的子表
|
||||
* 分区节点下,只看顶层会把部分页当成全量,进而误删分组成员。
|
||||
@@ -566,12 +756,13 @@ export function hasTableTreeLoadMore(nodes: readonly TreeNode[]): boolean {
|
||||
return nodes.some((node) => node.type === "load-more" || (node.children ? hasTableTreeLoadMore(node.children) : false));
|
||||
}
|
||||
|
||||
/** 收集子树里的表行名;多收只会让回收更保守,不会误删成员。 */
|
||||
export function collectTableTreeNames(nodes: readonly TreeNode[]): Set<string> {
|
||||
/** 收集子树里可分组行名;多收只会让回收更保守,不会误删成员。 */
|
||||
export function collectTableTreeNames(nodes: readonly TreeNode[], kind: TableVGroupObjectKind = "tables"): Set<string> {
|
||||
const rowTypes = TABLE_VGROUP_KIND_ROW_TYPES[kind];
|
||||
const names = new Set<string>();
|
||||
const walk = (list: readonly TreeNode[]) => {
|
||||
for (const node of list) {
|
||||
if (node.type === "table" && node.label) names.add(node.label);
|
||||
if (rowTypes[node.type] && node.label) names.add(node.label);
|
||||
if (node.children) walk(node.children);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user