Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

feat(tabs): support renaming query tabs

t8y2b75219ab4048
diff --git a/apps/desktop/src/components/layout/AppTabBar.vue b/apps/desktop/src/components/layout/AppTabBar.vue
index 24eec344f6..8380f52e1c 100644
--- a/apps/desktop/src/components/layout/AppTabBar.vue
+++ b/apps/desktop/src/components/layout/AppTabBar.vue
@@ -12,6 +12,7 @@ import {
Code2,
TableProperties,
PencilRuler,
+ Pencil,
Package,
Check,
} from "lucide-vue-next";
@@ -43,6 +44,8 @@ const emit = defineEmits<{
const { t } = useI18n();
const queryStore = useQueryStore();
const settingsStore = useSettingsStore();
+const editingTabId = ref<string | null>(null);
+const editingTitle = ref("");
const compactTabTitle = computed({
get: () => settingsStore.editorSettings.compactTabTitle,
set: (checked: boolean | "indeterminate") => {
@@ -54,6 +57,32 @@ function toggleCompactTabTitle() {
compactTabTitle.value = !compactTabTitle.value;
}
+function canRenameTab(tab: QueryTab) {
+ return tab.mode === "query";
+}
+
+function startRenameTab(tab: QueryTab) {
+ if (!canRenameTab(tab)) return;
+ editingTabId.value = tab.id;
+ editingTitle.value = tab.title;
+ nextTick(() => {
+ const input = document.querySelector<HTMLInputElement>(`[data-tab-title-input="${tab.id}"]`);
+ input?.focus();
+ input?.select();
+ });
+}
+
+function commitRenameTab(tab: QueryTab) {
+ if (editingTabId.value !== tab.id) return;
+ const title = editingTitle.value.trim();
+ if (title) queryStore.renameTab(tab.id, title);
+ editingTabId.value = null;
+}
+
+function cancelRenameTab() {
+ editingTabId.value = null;
+}
+
function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
return [
{
@@ -62,6 +91,12 @@ function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
icon: Check,
iconClass: compactTabTitle.value ? "opacity-100" : "opacity-0",
},
+ {
+ label: t("contextMenu.renameTab"),
+ action: () => startRenameTab(tab),
+ icon: Pencil,
+ visible: canRenameTab(tab),
+ },
{ label: "", separator: true },
{
label: tab.pinned ? t("contextMenu.unpin") : t("contextMenu.pin"),
@@ -277,6 +312,7 @@ const tabOverflowControlClass = computed(() =>
queryStore.activeTabId = tab.id;
emit('close-driver-store');
"
+ @dblclick.stop="startRenameTab(tab)"
@mousedown.middle.prevent="queryStore.closeTab(tab.id)"
>
<span class="shrink-0" :class="tabIconClass(tab)">
@@ -285,7 +321,19 @@ const tabOverflowControlClass = computed(() =>
<PencilRuler v-else-if="tab.mode === 'structure'" class="h-3.5 w-3.5" />
<Code2 v-else class="h-3.5 w-3.5" />
</span>
- <span class="min-w-0 truncate flex-1">{{ tabDisplayTitle(tab, t) }}</span>
+ <input
+ v-if="editingTabId === tab.id"
+ v-model="editingTitle"
+ :data-tab-title-input="tab.id"
+ :aria-label="t('contextMenu.renameTab')"
+ class="h-5 min-w-0 flex-1 rounded border border-ring bg-background px-1.5 text-xs font-normal text-foreground outline-none"
+ @click.stop
+ @mousedown.stop
+ @keydown.enter.prevent="commitRenameTab(tab)"
+ @keydown.escape.prevent="cancelRenameTab"
+ @blur="commitRenameTab(tab)"
+ />
+ <span v-else class="min-w-0 truncate flex-1">{{ tabDisplayTitle(tab, t) }}</span>
<Tooltip>
<TooltipTrigger as-child>
<button
diff --git a/apps/desktop/src/i18n/locales/en.ts b/apps/desktop/src/i18n/locales/en.ts
index 6e482a7627..bce00a5822 100644
--- a/apps/desktop/src/i18n/locales/en.ts
+++ b/apps/desktop/src/i18n/locales/en.ts
@@ -358,6 +358,7 @@ export default {
redis: "Redis",
mongo: "Mongo",
objects: "Objects",
+ tooltipTitle: "Title:",
tooltipConnection: "Connection:",
tooltipDatabase: "Database:",
tooltipTable: "Table:",
@@ -880,6 +881,7 @@ export default {
pin: "Pin",
unpin: "Unpin",
refreshTab: "Refresh Data",
+ renameTab: "Rename Tab",
compactTabTitle: "Shorten Tab Titles",
closeTab: "Close Tab",
closeOtherTabs: "Close Other Tabs",
diff --git a/apps/desktop/src/i18n/locales/es.ts b/apps/desktop/src/i18n/locales/es.ts
index ddff6db931..b6a592cf65 100644
--- a/apps/desktop/src/i18n/locales/es.ts
+++ b/apps/desktop/src/i18n/locales/es.ts
@@ -356,6 +356,7 @@ export default {
redis: "Redis",
mongo: "Mongo",
objects: "Objetos",
+ tooltipTitle: "Título:",
tooltipConnection: "Conexión:",
tooltipDatabase: "Base de datos:",
tooltipTable: "Tabla:",
@@ -782,6 +783,7 @@ export default {
pin: "Fijar",
unpin: "Desfijar",
refreshTab: "Actualizar datos",
+ renameTab: "Renombrar pestaña",
closeTab: "Cerrar pestaña",
closeOtherTabs: "Cerrar otras pestañas",
closeAllTabs: "Cerrar todas las pestañas",
diff --git a/apps/desktop/src/i18n/locales/zh-CN.ts b/apps/desktop/src/i18n/locales/zh-CN.ts
index 05781737a1..addc4a64e0 100644
--- a/apps/desktop/src/i18n/locales/zh-CN.ts
+++ b/apps/desktop/src/i18n/locales/zh-CN.ts
@@ -354,6 +354,7 @@ export default {
redis: "Redis",
mongo: "Mongo",
objects: "对象",
+ tooltipTitle: "标题:",
tooltipConnection: "连接:",
tooltipDatabase: "数据库:",
tooltipTable: "表:",
@@ -861,6 +862,7 @@ export default {
pin: "置顶",
unpin: "取消置顶",
refreshTab: "刷新数据",
+ renameTab: "重命名标签页",
compactTabTitle: "缩短标签标题",
closeTab: "关闭标签页",
closeOtherTabs: "关闭其他标签页",
diff --git a/apps/desktop/src/lib/openTabsPersistence.ts b/apps/desktop/src/lib/openTabsPersistence.ts
index f9e1f6aafc..cd1bc1d9cd 100644
--- a/apps/desktop/src/lib/openTabsPersistence.ts
+++ b/apps/desktop/src/lib/openTabsPersistence.ts
@@ -3,6 +3,7 @@ import type { QueryTab } from "@/types/database";
export interface SavedOpenTab {
id: string;
title: string;
+ customTitle?: boolean;
connectionId: string;
database: string;
schema?: string;
@@ -24,6 +25,7 @@ export function serializeOpenTabs(tabs: QueryTab[]): SavedOpenTab[] {
return tabs.map((tab) => ({
id: tab.id,
title: tab.title,
+ ...(tab.customTitle ? { customTitle: true } : {}),
connectionId: tab.connectionId,
database: tab.database,
schema: tab.schema,
diff --git a/apps/desktop/src/lib/tabPresentation.ts b/apps/desktop/src/lib/tabPresentation.ts
index 11a62842a1..98eee142a9 100644
--- a/apps/desktop/src/lib/tabPresentation.ts
+++ b/apps/desktop/src/lib/tabPresentation.ts
@@ -27,6 +27,11 @@ export function isPreviewTab(tab: QueryTab): boolean {
return !!config?.name.startsWith("[Preview]");
}
+function queryTitle(tab: QueryTab): string | undefined {
+ if (tab.customTitle || tab.savedSqlId || tab.objectSource) return tab.title.trim() || undefined;
+ return undefined;
+}
+
export function tabDisplayTitle(tab: QueryTab, t: Translate): string {
const database = databaseDisplayNameForTab(tab.connectionId, tab.database, t);
const settingsStore = useSettingsStore();
@@ -41,6 +46,8 @@ export function tabDisplayTitle(tab: QueryTab, t: Translate): string {
return `${tab.tableMeta.tableName}${suffix}`;
}
if (tab.mode === "query") {
+ const title = queryTitle(tab);
+ if (title) return title;
if (compact) return connectionDisplayName(tab.connectionId);
return `${connectionDisplayName(tab.connectionId)}@${database}`;
}
@@ -67,6 +74,9 @@ export function tabTooltipLines(tab: QueryTab, t: Translate): { label: string; v
{ label: t("tabs.tooltipConnection"), value: connName },
{ label: t("tabs.tooltipDatabase"), value: database },
];
+ if (tab.mode === "query" && queryTitle(tab)) {
+ lines.unshift({ label: t("tabs.tooltipTitle"), value: tab.title });
+ }
if (tab.mode === "data" && tab.tableMeta?.tableName) {
lines.push({ label: t("tabs.tooltipTable"), value: tab.tableMeta.tableName });
}
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index aa7defc34c..79766f3a25 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -171,6 +171,7 @@ export const useQueryStore = defineStore("query", () => {
const tab: QueryTab = {
id,
title: title || `Query ${tabs.value.length + 1}`,
+ customTitle: mode === "query" && !!title ? true : undefined,
connectionId,
database,
schema,
@@ -311,11 +312,24 @@ export const useQueryStore = defineStore("query", () => {
}
}
+ function renameTab(id: string, title: string) {
+ const trimmed = title.trim();
+ if (!trimmed) return false;
+ const tab = tabs.value.find((t) => t.id === id);
+ if (!tab || tab.mode !== "query") return false;
+ tab.title = trimmed;
+ tab.customTitle = true;
+ return true;
+ }
+
function linkSavedSql(id: string, savedSqlId: string, title?: string) {
const tab = tabs.value.find((t) => t.id === id);
if (!tab) return;
tab.savedSqlId = savedSqlId;
- if (title) tab.title = title;
+ if (title) {
+ tab.title = title;
+ tab.customTitle = true;
+ }
}
function openSavedSql(file: SavedSqlFile) {
@@ -329,6 +343,7 @@ export const useQueryStore = defineStore("query", () => {
const tab: QueryTab = {
id,
title: file.name,
+ customTitle: true,
connectionId: file.connectionId,
database: file.database,
schema: file.schema,
@@ -1066,6 +1081,7 @@ export const useQueryStore = defineStore("query", () => {
closeOtherTabs,
closeAllTabs,
updateSql,
+ renameTab,
openObjectBrowser,
openTableStructure,
linkSavedSql,
diff --git a/apps/desktop/src/types/database.ts b/apps/desktop/src/types/database.ts
index 6a3de06c0d..2126797f73 100644
--- a/apps/desktop/src/types/database.ts
+++ b/apps/desktop/src/types/database.ts
@@ -321,6 +321,7 @@ export interface TreeNode {
export interface QueryTab {
id: string;
title: string;
+ customTitle?: boolean;
connectionId: string;
database: string;
schema?: string;
diff --git a/packages/app-tests/openTabsPersistence.test.ts b/packages/app-tests/openTabsPersistence.test.ts
index 402cf75f8e..caf5aabfcb 100644
--- a/packages/app-tests/openTabsPersistence.test.ts
+++ b/packages/app-tests/openTabsPersistence.test.ts
@@ -45,6 +45,7 @@ test("serializes object source query tabs with save context", () => {
const saved = serializeOpenTabs([
queryTab({
title: "fn_add",
+ customTitle: true,
objectSource: {
schema: "public",
name: "fn_add",
@@ -58,6 +59,7 @@ test("serializes object source query tabs with save context", () => {
name: "fn_add",
objectType: "FUNCTION",
});
+ assert.equal(saved[0]?.customTitle, true);
});
test("restores unsaved query tabs and active tab after restart", () => {
@@ -81,6 +83,7 @@ test("restores unsaved query tabs and active tab after restart", () => {
test("restores object source save context", () => {
const raw = JSON.stringify([
queryTab({
+ customTitle: true,
objectSource: {
schema: "public",
name: "fn_add",
@@ -96,6 +99,7 @@ test("restores object source save context", () => {
name: "fn_add",
objectType: "FUNCTION",
});
+ assert.equal(restored.tabs[0]?.customTitle, true);
});
test("desktop restore keeps legacy query tabs without a mode", () => {
diff --git a/packages/app-tests/queryStore.test.ts b/packages/app-tests/queryStore.test.ts
index 85494ca9c0..f0e3ae504a 100644
--- a/packages/app-tests/queryStore.test.ts
+++ b/packages/app-tests/queryStore.test.ts
@@ -52,6 +52,18 @@ test("setErrorResult stops loading and shows the error result", () => {
assert.deepEqual(tab?.result?.rows, [["metadata failed"]]);
});
+test("renames query tab titles", () => {
+ setActivePinia(createPinia());
+ const store = useQueryStore();
+ const tabId = store.createTab("conn-1", "db");
+
+ assert.equal(store.renameTab(tabId, " Revenue checks "), true);
+
+ const tab = store.tabs.find((item) => item.id === tabId);
+ assert.equal(tab?.title, "Revenue checks");
+ assert.equal(tab?.customTitle, true);
+});
+
test("evicting cached tab results releases multi-result payloads and sessions", async () => {
const restoreStorage = installMemoryStorage();
setActivePinia(createPinia());
diff --git a/packages/app-tests/tabPresentation.test.ts b/packages/app-tests/tabPresentation.test.ts
index 26910e8877..2d49244a2c 100644
--- a/packages/app-tests/tabPresentation.test.ts
+++ b/packages/app-tests/tabPresentation.test.ts
@@ -1,6 +1,52 @@
import { strict as assert } from "node:assert";
import test from "node:test";
-import { shouldShowTabOverflowControls } from "../../apps/desktop/src/lib/tabPresentation.ts";
+import { createPinia, setActivePinia } from "pinia";
+import { shouldShowTabOverflowControls, tabDisplayTitle } from "../../apps/desktop/src/lib/tabPresentation.ts";
+import { useConnectionStore } from "../../apps/desktop/src/stores/connectionStore.ts";
+import type { ConnectionConfig, QueryTab } from "../../apps/desktop/src/types/database.ts";
+
+function installMemoryStorage() {
+ const values = new Map<string, string>();
+ const original = Object.getOwnPropertyDescriptor(globalThis, "localStorage");
+ Object.defineProperty(globalThis, "localStorage", {
+ configurable: true,
+ value: {
+ getItem: (key: string) => values.get(key) ?? null,
+ setItem: (key: string, value: string) => values.set(key, value),
+ removeItem: (key: string) => values.delete(key),
+ clear: () => values.clear(),
+ },
+ });
+ return () => {
+ if (original) Object.defineProperty(globalThis, "localStorage", original);
+ else Reflect.deleteProperty(globalThis, "localStorage");
+ };
+}
+
+function conn(id: string): ConnectionConfig {
+ return {
+ id,
+ name: "Prod",
+ db_type: "postgres",
+ host: "localhost",
+ port: 5432,
+ username: "postgres",
+ password: "",
+ };
+}
+
+function queryTab(overrides: Partial<QueryTab> = {}): QueryTab {
+ return {
+ id: "tab-1",
+ title: "Query 1",
+ connectionId: "conn-1",
+ database: "app",
+ sql: "",
+ isExecuting: false,
+ mode: "query",
+ ...overrides,
+ };
+}
test("tab overflow controls only show when there are hidden tabs to reach", () => {
assert.equal(shouldShowTabOverflowControls(0, true, true, true), false);
@@ -9,3 +55,17 @@ test("tab overflow controls only show when there are hidden tabs to reach", () =
assert.equal(shouldShowTabOverflowControls(3, false, true, false), true);
assert.equal(shouldShowTabOverflowControls(3, false, false, true), true);
});
+
+test("query tab display title uses custom title when present", () => {
+ const restoreStorage = installMemoryStorage();
+ setActivePinia(createPinia());
+ useConnectionStore().addEphemeralConnection(conn("conn-1"));
+ const t = (key: string) => key;
+
+ try {
+ assert.equal(tabDisplayTitle(queryTab(), t), "Prod@app");
+ assert.equal(tabDisplayTitle(queryTab({ title: "Revenue checks", customTitle: true }), t), "Revenue checks");
+ } finally {
+ restoreStorage();
+ }
+});