feat(sidebar): show connection note next to label with tight comment spacing

This commit is contained in:
t8y2 committed 2026-08-06 02:11:02 +08:00
1 parent 67e6b3f32d
commit 9dbbfb4a06
9 files changed
+37 -17

No files matched your search

@@ -7,8 +7,10 @@ describe("sidebar tree item layout", () => {
expect(usesFullWidthTreeLabel("table", true, true)).toBe(false);
});
it("lets a table name consume the available row width before truncating", () => {
expect(treeLabelWidthClass({ fullWidth: false, hasTrailingComment: true })).toBe("min-w-0 flex-1 truncate");
it("lets a table name consume the available row width before truncating when aligned", () => {
expect(treeLabelWidthClass({ fullWidth: false, hasTrailingComment: true, alignLeading: true })).toBe("min-w-0 flex-1 truncate");
// inline/right 模式 label 不撑满,让 comment 紧跟
expect(treeLabelWidthClass({ fullWidth: false, hasTrailingComment: true, alignLeading: false })).toBe("min-w-0 shrink truncate");
});
it("keeps a pinned action next to the name while preserving the aligned comment column", () => {
@@ -130,6 +130,8 @@ function makeConnectionNode(config: ConnectionConfig, pinned: boolean): TreeNode
isExpanded: false,
children: [],
pinned,
// 连接备注复用 TreeNode.comment 通道,侧边栏按 sidebarObjectInfoMode 渲染。
comment: config.note || null,
};
}
@@ -55,7 +55,7 @@ const pinnableTypes: Set<TreeNodeType> = new Set([
"nacos-namespace",
]);
const commentTypes: Set<TreeNodeType> = new Set(["schema", "table", "view", "materialized_view", "column", "mongo-collection", "vector-collection", "elasticsearch-index"]);
const commentTypes: Set<TreeNodeType> = new Set(["connection", "schema", "table", "view", "materialized_view", "column", "mongo-collection", "vector-collection", "elasticsearch-index"]);
export function treeItemPaddingLeft(depth: number): string {
return `${depth * 16 + 8}px`;
@@ -140,10 +140,13 @@ export function usesFullWidthTreeLabel(type: TreeNodeType, allowHorizontalScroll
return allowHorizontalScroll && !hasTrailingComment && fullWidthLabelTypes.has(type);
}
export function treeLabelWidthClass({ fullWidth, hasTrailingComment, hasInlineAction = false }: { fullWidth: boolean; hasTrailingComment: boolean; hasInlineAction?: boolean }): string {
export function treeLabelWidthClass({ fullWidth, hasTrailingComment, hasInlineAction = false, alignLeading = false }: { fullWidth: boolean; hasTrailingComment: boolean; hasInlineAction?: boolean; alignLeading?: boolean }): string {
if (fullWidth) return "shrink-0 whitespace-nowrap";
if (hasTrailingComment && hasInlineAction) return "min-w-0 shrink truncate";
return hasTrailingComment ? "min-w-0 flex-1 truncate" : "min-w-0 truncate";
// aligned 模式靠 leading 块固定宽度对齐 comment 列,label 需 flex-1 撑满 leading 块;
// inline/right 模式 label 用 shrink 让 comment 紧跟,避免 label 撑满把 comment 推到最右。
if (hasTrailingComment) return alignLeading ? "min-w-0 flex-1 truncate" : "min-w-0 shrink truncate";
return "min-w-0 truncate";
}
export function canTreeNodeExpand(type: TreeNodeType): boolean {