feat(sidebar): show comments for procedures and functions in object tree
Refs: #9962
This commit is contained in:
1 parent
c2d9610d1c
commit
235a2d2dbb
4 files changed
+209
-6
No files matched your search
@@ -56,7 +56,7 @@ import { Input } from "@/components/ui/input";
|
|||||||
import { Switch } from "@/components/ui/switch";
|
import { Switch } from "@/components/ui/switch";
|
||||||
import LightTooltip from "@/components/ui/LightTooltip.vue";
|
import LightTooltip from "@/components/ui/LightTooltip.vue";
|
||||||
import type { ColumnInfo, ConnectionConfig, CustomTypeTreeMemberMeta, DatabaseType, TreeNode, TriggerInfo } from "@/types/database";
|
import type { ColumnInfo, ConnectionConfig, CustomTypeTreeMemberMeta, DatabaseType, TreeNode, TriggerInfo } from "@/types/database";
|
||||||
import { alignedCommentLeadingWidth, canTreeNodePin, canTreeNodeShowExpander, sidebarTreeNodeComment, trailingCommentAvailableWidth, trailingCommentGapPx, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";
|
import { alignedCommentLeadingWidth, canTreeNodePin, canTreeNodeShowExpander, isSidebarCommentSupportedType, sidebarTreeNodeComment, trailingCommentAvailableWidth, trailingCommentGapPx, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";
|
||||||
import {
|
import {
|
||||||
clearActiveTableReferencePayload,
|
clearActiveTableReferencePayload,
|
||||||
createColumnReferencePayload,
|
createColumnReferencePayload,
|
||||||
@@ -639,7 +639,7 @@ const detailTooltip = computed(() => {
|
|||||||
}
|
}
|
||||||
const column = node.type === "column" ? (node.meta as ColumnInfo | undefined) : undefined;
|
const column = node.type === "column" ? (node.meta as ColumnInfo | undefined) : undefined;
|
||||||
const comment = column && "comment" in column ? column.comment : node.comment;
|
const comment = column && "comment" in column ? column.comment : node.comment;
|
||||||
if ((!comment && !column) || (node.type !== "schema" && node.type !== "table" && node.type !== "view" && node.type !== "column")) return null;
|
if ((!comment && !column) || !isSidebarCommentSupportedType(node.type)) return null;
|
||||||
const rows: DetailTooltipRow[] = [
|
const rows: DetailTooltipRow[] = [
|
||||||
{ label: t("connection.name"), value: visibleLabel(node) },
|
{ label: t("connection.name"), value: visibleLabel(node) },
|
||||||
...(column ? [{ label: t("structureEditor.nullable"), value: t(column.is_nullable ? "structureEditor.nullable" : "structureEditor.notNull") }] : []),
|
...(column ? [{ label: t("structureEditor.nullable"), value: t(column.is_nullable ? "structureEditor.nullable" : "structureEditor.notNull") }] : []),
|
||||||
|
|||||||
+151
@@ -0,0 +1,151 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
|
||||||
|
import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";
|
||||||
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import i18n, { setLocale } from "@/i18n";
|
||||||
|
import TreeItem from "@/components/sidebar/TreeItem.vue";
|
||||||
|
import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHost } from "@/lib/sidebar/sidebarTreeRuntime";
|
||||||
|
import type { ConnectionConfig, TreeNode } from "@/types/database";
|
||||||
|
|
||||||
|
let commentMode = "comment-inline";
|
||||||
|
|
||||||
|
const connectionStore = {
|
||||||
|
activeConnectionId: "connection-1",
|
||||||
|
connectedIds: new Set(["connection-1"]),
|
||||||
|
connectingIds: new Set<string>(),
|
||||||
|
connectionMultiSelectActive: false,
|
||||||
|
connections: [],
|
||||||
|
getConfig: (): ConnectionConfig =>
|
||||||
|
({
|
||||||
|
id: "connection-1",
|
||||||
|
name: "Local SQL Server",
|
||||||
|
db_type: "sqlserver",
|
||||||
|
host: "127.0.0.1",
|
||||||
|
port: 1433,
|
||||||
|
username: "sa",
|
||||||
|
database: "master",
|
||||||
|
}) as ConnectionConfig,
|
||||||
|
getSidebarVisibleFilterSummary: () => null,
|
||||||
|
clearConnectionError: vi.fn(),
|
||||||
|
isDefaultDatabase: () => false,
|
||||||
|
isDefaultSchema: () => false,
|
||||||
|
isPinnedTreeNodeReorderTarget: () => false,
|
||||||
|
isTreeNodeChildrenLoaded: () => false,
|
||||||
|
isTreeNodePinned: () => false,
|
||||||
|
selectedTreeNodeId: null as string | null,
|
||||||
|
selectedTreeNodeIds: [] as string[],
|
||||||
|
selectedTreeNodeIdsSet: new Set<string>(),
|
||||||
|
sidebarTableSearchQueries: {},
|
||||||
|
tableNameFilterForScope: () => undefined,
|
||||||
|
treeNodes: [],
|
||||||
|
treeSelectionAnchorId: null as string | null,
|
||||||
|
};
|
||||||
|
|
||||||
|
vi.mock("@/stores/connectionStore", () => ({ useConnectionStore: () => connectionStore }));
|
||||||
|
vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ openDatabaseKeys: new Set<string>() }) }));
|
||||||
|
vi.mock("@/stores/settingsStore", () => ({
|
||||||
|
useSettingsStore: () => ({
|
||||||
|
editorSettings: {
|
||||||
|
shortcuts: { openDataInNewTab: "" },
|
||||||
|
sidebarActivation: "double",
|
||||||
|
sidebarAllowHorizontalScroll: false,
|
||||||
|
sidebarHiddenTablePrefixes: [],
|
||||||
|
sidebarObjectInfoMode: commentMode,
|
||||||
|
sidebarShowConnectionNotes: false,
|
||||||
|
sidebarShowTooltips: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
}));
|
||||||
|
vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));
|
||||||
|
|
||||||
|
const mountedApps: App[] = [];
|
||||||
|
|
||||||
|
async function mountTreeItem(initialNode: TreeNode, commentLabelWidth?: number) {
|
||||||
|
const container = document.createElement("div");
|
||||||
|
document.body.appendChild(container);
|
||||||
|
const node = ref(initialNode);
|
||||||
|
const host: SidebarTreeRuntimeHost = {
|
||||||
|
activeConnectionId: () => "connection-1",
|
||||||
|
connectionConfig: () => connectionStore.getConfig(),
|
||||||
|
isExpanded: () => false,
|
||||||
|
isLoading: () => false,
|
||||||
|
isSelected: () => false,
|
||||||
|
isFocused: () => false,
|
||||||
|
loadChildren: vi.fn(),
|
||||||
|
toggleNode: vi.fn(),
|
||||||
|
};
|
||||||
|
const runtime = createSidebarTreeRuntime();
|
||||||
|
runtime.bindHost(host);
|
||||||
|
const app = createApp(
|
||||||
|
defineComponent({
|
||||||
|
setup: () => () => h(TreeItem, { node: node.value, depth: 3, commentLabelWidth }),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
mountedApps.push(app);
|
||||||
|
app.use(i18n);
|
||||||
|
app.provide(sidebarTreeRuntimeKey, runtime);
|
||||||
|
app.mount(container);
|
||||||
|
await nextTick();
|
||||||
|
return { container, node, host };
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
commentMode = "comment-inline";
|
||||||
|
await setLocale("en");
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
for (const app of mountedApps.splice(0)) app.unmount();
|
||||||
|
document.body.replaceChildren();
|
||||||
|
await setLocale("en");
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("TreeItem routine and object comments (#9962)", () => {
|
||||||
|
it("renders inline comments for procedures and functions", async () => {
|
||||||
|
const procedureNode: TreeNode = {
|
||||||
|
id: "connection-1:master:dbo:usp_calculate_tax:PROCEDURE",
|
||||||
|
label: "usp_calculate_tax",
|
||||||
|
type: "procedure",
|
||||||
|
comment: "Calculates order taxes",
|
||||||
|
connectionId: "connection-1",
|
||||||
|
database: "master",
|
||||||
|
schema: "dbo",
|
||||||
|
};
|
||||||
|
|
||||||
|
const { container } = await mountTreeItem(procedureNode);
|
||||||
|
const commentEl = container.querySelector(".sidebar-object-comment");
|
||||||
|
expect(commentEl).not.toBeNull();
|
||||||
|
expect(commentEl?.textContent).toBe("Calculates order taxes");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("renders inline comments for functions", async () => {
|
||||||
|
const functionNode: TreeNode = {
|
||||||
|
id: "connection-1:master:dbo:fn_get_total:FUNCTION",
|
||||||
|
label: "fn_get_total",
|
||||||
|
type: "function",
|
||||||
|
comment: "Sums line items",
|
||||||
|
connectionId: "connection-1",
|
||||||
|
database: "master",
|
||||||
|
schema: "dbo",
|
||||||
|
};
|
||||||
|
|
||||||
|
const { container } = await mountTreeItem(functionNode);
|
||||||
|
const commentEl = container.querySelector(".sidebar-object-comment");
|
||||||
|
expect(commentEl).not.toBeNull();
|
||||||
|
expect(commentEl?.textContent).toBe("Sums line items");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("does not render comment element when procedure has no comment", async () => {
|
||||||
|
const procedureNode: TreeNode = {
|
||||||
|
id: "connection-1:master:dbo:usp_no_comment:PROCEDURE",
|
||||||
|
label: "usp_no_comment",
|
||||||
|
type: "procedure",
|
||||||
|
connectionId: "connection-1",
|
||||||
|
database: "master",
|
||||||
|
schema: "dbo",
|
||||||
|
};
|
||||||
|
|
||||||
|
const { container } = await mountTreeItem(procedureNode);
|
||||||
|
expect(container.querySelector(".sidebar-object-comment")).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,17 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { alignedCommentLeadingWidth, alignedSidebarCommentLabelWidths, canTreeNodeShowExpander, sidebarTreeNaturalContentWidth, sidebarTreeNodeComment, trailingCommentAvailableWidth, treeItemPaddingLeft, treeLabelWidthClass, usesFullWidthTreeLabel } from "@/lib/sidebar/sidebarTreeItemLayout";
|
import {
|
||||||
|
alignedCommentLeadingWidth,
|
||||||
|
alignedSidebarCommentLabelWidths,
|
||||||
|
canTreeNodeShowExpander,
|
||||||
|
isSidebarCommentAlignableNode,
|
||||||
|
isSidebarCommentSupportedType,
|
||||||
|
sidebarTreeNaturalContentWidth,
|
||||||
|
sidebarTreeNodeComment,
|
||||||
|
trailingCommentAvailableWidth,
|
||||||
|
treeItemPaddingLeft,
|
||||||
|
treeLabelWidthClass,
|
||||||
|
usesFullWidthTreeLabel,
|
||||||
|
} from "@/lib/sidebar/sidebarTreeItemLayout";
|
||||||
import type { TreeNode } from "@/types/database";
|
import type { TreeNode } from "@/types/database";
|
||||||
|
|
||||||
describe("sidebar tree item layout", () => {
|
describe("sidebar tree item layout", () => {
|
||||||
@@ -106,4 +118,40 @@ describe("sidebar tree item layout", () => {
|
|||||||
expect(sidebarTreeNaturalContentWidth(items, measure, 16)).toBe(4 * 16 + 8 + 54 + "nested".length * 7 + 20);
|
expect(sidebarTreeNaturalContentWidth(items, measure, 16)).toBe(4 * 16 + 8 + 54 + "nested".length * 7 + 20);
|
||||||
expect(sidebarTreeNaturalContentWidth(items, measure, 32)).toBe(4 * 32 + 8 + 54 + "nested".length * 7 + 20);
|
expect(sidebarTreeNaturalContentWidth(items, measure, 32)).toBe(4 * 32 + 8 + 54 + "nested".length * 7 + 20);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("supports comments and full-width labels for stored procedures and functions (#9962)", () => {
|
||||||
|
const procedure: TreeNode = { id: "p1", label: "calculate_tax", type: "procedure", comment: "Computes order tax" };
|
||||||
|
const func: TreeNode = { id: "f1", label: "get_user_name", type: "function", comment: "Returns formatted user name" };
|
||||||
|
const trigger: TreeNode = { id: "t1", label: "trg_audit", type: "trigger", comment: "Audit changes" };
|
||||||
|
const seq: TreeNode = { id: "s1", label: "order_id_seq", type: "sequence", comment: "Order id sequence" };
|
||||||
|
|
||||||
|
expect(sidebarTreeNodeComment(procedure, false)).toBe("Computes order tax");
|
||||||
|
expect(sidebarTreeNodeComment(func, false)).toBe("Returns formatted user name");
|
||||||
|
expect(sidebarTreeNodeComment(trigger, false)).toBe("Audit changes");
|
||||||
|
expect(sidebarTreeNodeComment(seq, false)).toBe("Order id sequence");
|
||||||
|
|
||||||
|
expect(isSidebarCommentSupportedType("procedure")).toBe(true);
|
||||||
|
expect(isSidebarCommentSupportedType("function")).toBe(true);
|
||||||
|
expect(isSidebarCommentSupportedType("materialized_view")).toBe(true);
|
||||||
|
expect(isSidebarCommentAlignableNode(procedure)).toBe(true);
|
||||||
|
expect(isSidebarCommentAlignableNode(func)).toBe(true);
|
||||||
|
|
||||||
|
expect(usesFullWidthTreeLabel("procedure", true)).toBe(true);
|
||||||
|
expect(usesFullWidthTreeLabel("procedure", true, true)).toBe(false);
|
||||||
|
expect(usesFullWidthTreeLabel("function", true)).toBe(true);
|
||||||
|
expect(usesFullWidthTreeLabel("function", true, true)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("aligns routine comments among sibling procedures and functions", () => {
|
||||||
|
const widths = alignedSidebarCommentLabelWidths([
|
||||||
|
{ id: "group-procedures", depth: 1, alignable: false, hasComment: false, labelWidth: 0 },
|
||||||
|
{ id: "proc-short", depth: 2, alignable: true, hasComment: true, labelWidth: 50 },
|
||||||
|
{ id: "proc-long", depth: 2, alignable: true, hasComment: false, labelWidth: 120 },
|
||||||
|
{ id: "group-functions", depth: 1, alignable: false, hasComment: false, labelWidth: 0 },
|
||||||
|
{ id: "func-one", depth: 2, alignable: true, hasComment: true, labelWidth: 80 },
|
||||||
|
]);
|
||||||
|
|
||||||
|
expect(widths.get("proc-short")).toBe(120);
|
||||||
|
expect(widths.get("func-one")).toBe(80);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -43,7 +43,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
|||||||
"datafile",
|
"datafile",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "procedure", "function", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
||||||
|
|
||||||
const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder", "type"]);
|
const emptyContainerTypes: Set<TreeNodeType> = new Set(["saved-sql-root", "saved-sql-folder", "type"]);
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ const pinnableTypes: Set<TreeNodeType> = new Set([
|
|||||||
"nacos-namespace",
|
"nacos-namespace",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const commentTypes: Set<TreeNodeType> = new Set(["connection", "schema", "table", "view", "materialized_view", "column", "mongo-collection", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
const commentTypes: Set<TreeNodeType> = new Set(["connection", "schema", "table", "view", "materialized_view", "column", "procedure", "function", "trigger", "sequence", "synonym", "package", "mongo-collection", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
|
||||||
|
|
||||||
export const SIDEBAR_INDENT_DEFAULT_PX = 16;
|
export const SIDEBAR_INDENT_DEFAULT_PX = 16;
|
||||||
|
|
||||||
@@ -149,8 +149,12 @@ export function sidebarTreeNodeComment(node: TreeNode, showConnectionNotes: bool
|
|||||||
return node.comment || null;
|
return node.comment || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isSidebarCommentSupportedType(type: TreeNodeType): boolean {
|
||||||
|
return commentTypes.has(type);
|
||||||
|
}
|
||||||
|
|
||||||
export function isSidebarCommentAlignableNode(node: TreeNode): boolean {
|
export function isSidebarCommentAlignableNode(node: TreeNode): boolean {
|
||||||
return commentTypes.has(node.type);
|
return isSidebarCommentSupportedType(node.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function usesFullWidthTreeLabel(type: TreeNodeType, allowHorizontalScroll: boolean, hasTrailingComment = false): boolean {
|
export function usesFullWidthTreeLabel(type: TreeNodeType, allowHorizontalScroll: boolean, hasTrailingComment = false): boolean {
|
||||||
|
|||||||
Reference in new issue
Block a user