feat(tabs): show table comments in tab tooltips

Closes #8342
This commit is contained in:
t8y2 committed 2026-09-07 14:10:16 +08:00
1 parent c0c97ef0e4
commit 5f81ed2e11
21 files changed
+75 -11

No files matched your search

@@ -27,6 +27,8 @@ const translations: Record<string, string> = {
"tabs.tooltipConnection": "Connection:",
"tabs.tooltipGroup": "Group:",
"tabs.tooltipDatabase": "Database:",
"tabs.tooltipTable": "Table:",
"tabs.tooltipTableComment": "Table Comment:",
"connectionGroup.ungroupedLabel": "Ungrouped",
"editor.noDatabase": "No database",
};
@@ -209,6 +211,22 @@ describe("tab group presentation", () => {
expect(connectionGroupDisplayName("conn-1", translate)).toBe("Ungrouped");
});
it("shows a bounded table comment only when it is non-empty", () => {
const lines = tabTooltipLines(
queryTab({
mode: "data",
tableComment: ` ${"表".repeat(55)}\narchive `,
tableMeta: { schema: "public", tableName: "users", columns: [], primaryKeys: [] },
}),
translate,
);
const comment = lines.find((line) => line.label === "Table Comment:")?.value;
expect(Array.from(comment || "")).toHaveLength(50);
expect(comment?.endsWith("…")).toBe(true);
expect(tabTooltipLines(queryTab({ mode: "data", tableComment: " ", tableMeta: { schema: "public", tableName: "users", columns: [], primaryKeys: [] } }), translate).some((line) => line.label === "Table Comment:")).toBe(false);
});
});
describe("query result source ranges", () => {
@@ -53,6 +53,7 @@ export interface SavedOpenTab {
objectBrowser?: QueryTab["objectBrowser"];
objectSource?: QueryTab["objectSource"];
sourceView?: boolean;
tableComment?: QueryTab["tableComment"];
tableMeta?: QueryTab["tableMeta"];
mongoEditTarget?: QueryTab["mongoEditTarget"];
resultEvicted?: boolean;
@@ -148,6 +149,7 @@ export function serializeOpenTabs(tabs: QueryTab[]): SavedOpenTab[] {
objectBrowser: tab.objectBrowser,
objectSource: tab.objectSource,
...(tab.sourceView ? { sourceView: true } : {}),
...(tab.tableComment !== undefined ? { tableComment: tab.tableComment } : {}),
tableMeta: tab.tableMeta,
...(tab.mongoEditTarget !== undefined ? { mongoEditTarget: tab.mongoEditTarget } : {}),
...(tab.mode !== "data" && tab.resultEvicted ? { resultEvicted: true } : {}),
@@ -11,6 +11,14 @@ import type { BatchSqlExecution, ConnectionConfig, DatabaseType, QueryResult, Qu
type Translate = (key: string, params?: Record<string, unknown>) => string;
export type OutputView = "result" | "summary" | "explain" | "chart";
const TABLE_COMMENT_TOOLTIP_MAX_LENGTH = 50;
function tableCommentTooltipValue(comment: string | null | undefined): string | undefined {
const normalized = comment?.trim().replace(/\s+/g, " ");
if (!normalized) return undefined;
const characters = Array.from(normalized);
return characters.length <= TABLE_COMMENT_TOOLTIP_MAX_LENGTH ? normalized : `${characters.slice(0, TABLE_COMMENT_TOOLTIP_MAX_LENGTH - 1).join("")}…`;
}
export function connectionDisplayName(connectionId: string): string {
const connectionStore = useConnectionStore();
@@ -170,6 +178,10 @@ export function tabTooltipLines(tab: QueryTab, t: Translate): { label: string; v
}
if (tab.mode === "data" && tab.tableMeta?.tableName) {
lines.push({ label: t("tabs.tooltipTable"), value: tab.tableMeta.tableName });
const comment = tableCommentTooltipValue(tab.tableComment);
if (comment) {
lines.push({ label: t("tabs.tooltipTableComment"), value: comment });
}
}
if (tab.mode === "mongo" && tab.sql) {
lines.push({ label: t("tabs.tooltipCollection"), value: tab.sql });