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(ui): align production markers and simplify the data header (#12998)

HARRISONef8724b6c8ab
diff --git a/apps/desktop/src/components/common/ProductionContextBadge.vue b/apps/desktop/src/components/common/ProductionContextBadge.vue
index b8b693b7e5..c1d5675ddf 100644
--- a/apps/desktop/src/components/common/ProductionContextBadge.vue
+++ b/apps/desktop/src/components/common/ProductionContextBadge.vue
@@ -7,13 +7,18 @@ const { t } = useI18n();
withDefaults(
defineProps<{
compact?: boolean;
+ /** Icon-only marker for dense rows: same shape in every row, no text. */
+ marker?: boolean;
}>(),
- { compact: false },
+ { compact: false, marker: false },
);
</script>
<template>
- <span class="inline-flex h-5 shrink-0 items-center gap-1 rounded-[4px] border border-red-500/40 bg-red-500/10 px-1.5 font-mono text-[10px] font-semibold leading-none text-red-700 dark:text-red-300" :class="compact ? 'px-1' : ''" :title="t('production.title')">
+ <span v-if="marker" data-production-marker class="inline-flex h-4 w-4 shrink-0 items-center justify-center text-red-600 dark:text-red-300" role="img" :aria-label="t('production.title')" :title="t('production.title')">
+ <ShieldAlert class="h-3 w-3" aria-hidden="true" />
+ </span>
+ <span v-else class="inline-flex h-5 shrink-0 items-center gap-1 rounded-[4px] border border-red-500/40 bg-red-500/10 px-1.5 font-mono text-[10px] font-semibold leading-none text-red-700 dark:text-red-300" :class="compact ? 'px-1' : ''" :title="t('production.title')">
<ShieldAlert class="h-3 w-3" aria-hidden="true" />
<span>PROD</span>
</span>
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vue
index 1fd2bb466b..20ad9a15d4 100644
--- a/apps/desktop/src/components/layout/ContentArea.vue
+++ b/apps/desktop/src/components/layout/ContentArea.vue
@@ -30,6 +30,7 @@ import {
Search,
TableProperties,
ChevronDown,
+ ChevronRight,
ChevronUp,
Inbox,
RefreshCcw,
@@ -367,7 +368,14 @@ const dataGridViewOptionsOpen = ref(false);
// real overflow; tiers then drop button labels and move secondary actions
// into the overflow menu instead of crushing the chips away.
const dataToolbarRef = ref<HTMLElement | null>(null);
-const { tier: dataToolbarTier } = useToolbarOverflow(dataToolbarRef, [() => props.activeTab.id, () => !!props.activeTab.result]);
+const { tier: dataToolbarTier } = useToolbarOverflow(dataToolbarRef, [
+ () => props.activeTab.id,
+ () => !!props.activeTab.result,
+ // The grid exposes these only after the table result mounts; the toolbar's
+ // action set grows at that point, so the row must be re-measured.
+ () => !!dataGridRef.value?.canOpenTableStructureEditor,
+ () => !!dataGridRef.value?.goToColumnToolbarCapability?.visible,
+]);
const dataToolbarCompact = computed(() => dataToolbarTier.value >= 1);
const showDataColumnsChip = computed(() => dataToolbarTier.value < 2);
const dataGridRenderMode = computed(() => settingsStore.editorSettings.dataGridRenderMode);
@@ -2966,37 +2974,44 @@ defineExpose({
<template v-else-if="activeTab.mode === 'data'">
<div class="flex-1 min-h-0 flex flex-col">
<div ref="dataToolbarRef" class="h-9 shrink-0 border-b bg-background/80 px-3 flex items-center gap-2 text-xs overflow-hidden">
- <!-- No fixed max-w cap on these chips: they must flex (truncate)
- so long names only clip when the header row itself runs out
- (#7880). The min-w floor keeps scrollWidth reporting real
- overflow so the measured tiers condense the row before the
- chips collapse. -->
- <button
- v-if="activeConnection?.name?.trim()"
- type="button"
- data-data-header-connection
- class="inline-flex min-w-12 items-center truncate rounded border border-border bg-muted/30 px-2 py-0.5 text-muted-foreground cursor-pointer hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none"
- :title="activeConnection.name"
- :disabled="!activeTab.connectionId"
- @click="queryStore.openDatabaseBrowser(activeTab.connectionId)"
- >
- {{ activeConnection.name }}
- </button>
- <span class="inline-flex min-w-12 items-center truncate rounded border border-border bg-muted/50 px-2 py-0.5 font-medium" :title="activeDataTabTableMeta?.tableName || activeTab.title">
- {{ activeDataTabTableMeta?.tableName || activeTab.title }}
- </span>
- <button
- type="button"
- data-data-header-database
- class="inline-flex min-w-12 items-center truncate rounded border border-border bg-muted/30 px-2 py-0.5 text-muted-foreground cursor-pointer hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none"
- :title="[activeDataTabTableMeta?.schema, databaseDisplayNameForTab(activeTab.connectionId, activeTab.database, t)].filter(Boolean).join('@')"
- :disabled="!activeTab.connectionId || !activeTab.database"
- @click="queryStore.openObjectBrowser(activeTab.connectionId, activeTab.database, activeDataTabTableMeta?.schema, activeDataTabTableMeta?.catalog)"
- >
- <template v-if="activeDataTabTableMeta?.schema">{{ activeDataTabTableMeta.schema }}@</template>{{ databaseDisplayNameForTab(activeTab.connectionId, activeTab.database, t) }}
- </button>
- <span v-if="showDataColumnsChip && activeDataTabTableMeta" class="inline-flex shrink-0 items-center rounded border border-border bg-muted/30 px-2 py-0.5 font-medium text-muted-foreground tabular-nums"> {{ activeDataTabTableMeta.columns.length }} {{ t("tree.columns") }} </span>
- <span class="ml-auto" />
+ <!-- Context breadcrumb. The connection and database segments are
+ capped so a long connection name can never eat half the row;
+ the table name gets the remaining room and is the only filled
+ segment, which keeps the hierarchy obvious at a glance. -->
+ <div class="flex min-w-[18rem] flex-1 items-center gap-1 overflow-hidden">
+ <button
+ v-if="activeConnection?.name?.trim()"
+ type="button"
+ data-data-header-connection
+ class="inline-flex max-w-[13rem] shrink items-center gap-1 rounded text-muted-foreground cursor-pointer hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none"
+ :class="dataToolbarCompact ? 'w-5 justify-center px-0.5' : 'min-w-[3.5rem] px-1 py-0.5'"
+ :title="activeConnection.name"
+ :aria-label="activeConnection.name"
+ :disabled="!activeTab.connectionId"
+ @click="queryStore.openDatabaseBrowser(activeTab.connectionId)"
+ >
+ <Database class="h-3 w-3 shrink-0 opacity-70" aria-hidden="true" />
+ <span v-if="!dataToolbarCompact" class="truncate">{{ activeConnection.name }}</span>
+ </button>
+ <span v-if="activeConnection?.name?.trim()" class="shrink-0 text-muted-foreground/40" aria-hidden="true">/</span>
+ <button
+ type="button"
+ data-data-header-database
+ class="inline-flex min-w-[2.5rem] max-w-[12rem] shrink items-center rounded px-1 py-0.5 text-muted-foreground cursor-pointer hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none"
+ :title="[activeDataTabTableMeta?.schema, databaseDisplayNameForTab(activeTab.connectionId, activeTab.database, t)].filter(Boolean).join('@')"
+ :disabled="!activeTab.connectionId || !activeTab.database"
+ @click="queryStore.openObjectBrowser(activeTab.connectionId, activeTab.database, activeDataTabTableMeta?.schema, activeDataTabTableMeta?.catalog)"
+ >
+ <span class="truncate"
+ ><template v-if="activeDataTabTableMeta?.schema">{{ activeDataTabTableMeta.schema }}@</template>{{ databaseDisplayNameForTab(activeTab.connectionId, activeTab.database, t) }}</span
+ >
+ </button>
+ <ChevronRight class="h-3 w-3 shrink-0 text-muted-foreground/40" aria-hidden="true" />
+ <span class="inline-flex min-w-[6rem] items-center rounded-md bg-muted/60 px-2 py-0.5 font-medium text-foreground" :title="activeDataTabTableMeta?.tableName || activeTab.title">
+ <span class="truncate">{{ activeDataTabTableMeta?.tableName || activeTab.title }}</span>
+ </span>
+ <span v-if="showDataColumnsChip && activeDataTabTableMeta" class="shrink-0 whitespace-nowrap text-muted-foreground tabular-nums">{{ activeDataTabTableMeta.columns.length }} {{ t("tree.columns") }}</span>
+ </div>
<LightTooltip v-if="dataGridRef?.canOpenTableStructureEditor" :text="t('contextMenu.editStructure')" side="bottom" nowrap>
<Button data-edit-table-structure variant="ghost" size="sm" class="h-5 text-xs px-1.5 shrink-0" :aria-label="t('contextMenu.editStructure')" @click="dataGridRef?.openTableStructureEditor('columns')">
<PencilRuler class="h-3.5 w-3.5" />
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue
index de2748dae7..3e099972aa 100644
--- a/apps/desktop/src/components/sidebar/TreeItem.vue
+++ b/apps/desktop/src/components/sidebar/TreeItem.vue
@@ -97,7 +97,7 @@ import { supportsSidebarObjectNameFilter } from "@/lib/sidebar/sidebarObjectName
import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";
import { isWindows } from "@/lib/backend/platform";
import { flattenTree } from "@/composables/useFlatTree";
-import { showSidebarRowProductionBadge } from "@/lib/sidebar/sidebarProductionBadge";
+import { isSidebarProductionContainer, showSidebarRowProductionBadge } from "@/lib/sidebar/sidebarProductionBadge";
import { focusSidebarRenameInput } from "@/lib/sidebar/sidebarRenameFocus";
import { ensureSqlExtension, stripSqlExtension } from "@/lib/savedSql/savedSqlFileName";
import { savedSqlErrorMessage } from "@/lib/savedSql/savedSqlErrors";
@@ -242,6 +242,11 @@ const showProductionBadge = computed(() => {
return showSidebarRowProductionBadge(node, node.connectionId ? connectionStore.getConfig(node.connectionId) : undefined, props.isStickyContext);
});
+// Object rows use an icon-only marker pinned to the row's trailing edge, so
+// every production table lines up in one column instead of pushing the name
+// aside at a different x per name length. Container rows keep the text badge.
+const showProductionRowMarker = computed(() => showProductionBadge.value && !isSidebarProductionContainer(activeNode.value));
+
function currentDatabaseType(): DatabaseType | undefined {
return activeNode.value.connectionId ? effectiveDatabaseTypeForConnection(connectionStore.getConfig(activeNode.value.connectionId)) : undefined;
}
@@ -1040,7 +1045,7 @@ const rowStyle = computed(() => {
const backgroundColor = hexToRgba(color, isActiveConnectionScope.value ? 0.14 : 0.08);
return {
paddingLeft: paddingLeft.value,
- paddingRight: props.isStickyContext && !showProductionBadge.value ? "72px" : trailingComment.value ? "12px" : undefined,
+ paddingRight: props.isStickyContext && !showProductionBadge.value ? "72px" : showProductionRowMarker.value ? "8px" : trailingComment.value ? "12px" : undefined,
"--tree-connection-row-bg": backgroundColor,
"--tree-connection-row-hover-bg": hexToRgba(color, isActiveConnectionScope.value ? 0.2 : 0.16),
"--tree-connection-active-bg": hexToRgba(color, 0.18),
@@ -1790,7 +1795,7 @@ function onKeydown(event: KeyboardEvent) {
<Pin class="h-3 w-3 fill-current" aria-hidden="true" />
</button>
<Pin v-else-if="isPinned" class="h-3 w-3 shrink-0 fill-current text-primary" aria-hidden="true" />
- <ProductionContextBadge v-if="showProductionBadge" compact />
+ <ProductionContextBadge v-if="showProductionBadge && !showProductionRowMarker" compact />
<span
v-if="
(node.type === 'group-tables' ||
@@ -1844,6 +1849,9 @@ function onKeydown(event: KeyboardEvent) {
<ReadOnlySessionControl v-if="isConnectionReadonly && activeNode.connectionId" :connection-id="activeNode.connectionId" show-label />
<ConnectionErrorIndicator v-if="node.type === 'connection'" :connection-id="node.connectionId" trigger-class="h-4 w-4" />
<span v-if="formattedObjectStorage()" class="ml-auto shrink-0 text-right text-xs tabular-nums text-muted-foreground">{{ formattedObjectStorage() }}</span>
+ <span v-if="showProductionRowMarker" class="flex w-4 shrink-0 items-center justify-center" :class="{ 'ml-auto': !formattedObjectStorage() }">
+ <ProductionContextBadge marker />
+ </span>
<button
v-if="isConnecting"
type="button"
diff --git a/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts b/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts
index 20ce2e8f51..d3c311ce1a 100644
--- a/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts
+++ b/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts
@@ -179,6 +179,26 @@ describe("TreeItem production badge scope", () => {
expect(container.querySelector<HTMLElement>('[data-node-id="scope-inline"]')?.style.paddingRight).toBe("");
});
+ it("marks object rows with one aligned marker in table scope", async () => {
+ connection = { ...productionConnection, production_badge_scope: "table" };
+
+ const container = mountTreeItem({ id: "table-1", label: "orders", type: "table", connectionId: productionConnection.id, database: "analytics" });
+ await nextTick();
+
+ expect(container.querySelector('[data-node-id="table-1"] [data-production-marker]')).not.toBeNull();
+ expect(rowText(container, "table-1")).not.toContain("PROD");
+ });
+
+ it("keeps the text badge on container rows in table scope", async () => {
+ connection = { ...productionConnection, production_badge_scope: "table" };
+
+ const container = mountTreeItem({ id: "schema-1", label: "analytics", type: "schema", connectionId: productionConnection.id, database: "analytics" });
+ await nextTick();
+
+ expect(container.querySelector('[data-node-id="schema-1"] [data-production-marker]')).toBeNull();
+ expect(rowText(container, "schema-1")).toContain("PROD");
+ });
+
it("leaves ordinary object rows unmarked inside a production connection", async () => {
const container = mountTreeItem({ id: "table-1", label: "orders", type: "table", connectionId: productionConnection.id, database: "shop" });
await nextTick();
diff --git a/apps/desktop/src/lib/sidebar/__tests__/sidebarProductionBadge.spec.ts b/apps/desktop/src/lib/sidebar/__tests__/sidebarProductionBadge.spec.ts
index 4c666fc248..aede26f143 100644
--- a/apps/desktop/src/lib/sidebar/__tests__/sidebarProductionBadge.spec.ts
+++ b/apps/desktop/src/lib/sidebar/__tests__/sidebarProductionBadge.spec.ts
@@ -1,5 +1,5 @@
import { describe, expect, it } from "vitest";
-import { sidebarProductionBadgeScope, showSidebarRowProductionBadge, showSidebarStickyProductionBadge } from "../sidebarProductionBadge";
+import { isSidebarProductionContainer, sidebarProductionBadgeScope, showSidebarRowProductionBadge, showSidebarStickyProductionBadge } from "../sidebarProductionBadge";
import { assessProductionSql } from "@/lib/database/productionSafety";
import type { ConnectionConfig, ProductionBadgeScope, TreeNodeType } from "@/types/database";
@@ -49,6 +49,15 @@ describe("production badge display scope", () => {
expect(showSidebarStickyProductionBadge(node("schema"), { ...config, production_databases: [] })).toBe(false);
});
+ it("splits container rows from object rows for badge placement", () => {
+ for (const type of ["connection", "database", "schema", "redis-db", "mongo-db", "nacos-namespace"] as const) {
+ expect(isSidebarProductionContainer(node(type))).toBe(true);
+ }
+ for (const type of ["table", "view", "materialized_view", "procedure", "mongo-collection", "column", "group-tables"] as const) {
+ expect(isSidebarProductionContainer(node(type))).toBe(false);
+ }
+ });
+
it("warns on the connection for selected production databases in connection-only mode", () => {
const config = { ...connection, is_production: false, production_databases: ["app"], production_badge_scope: "connection" as const };
expect(showSidebarRowProductionBadge(node("connection", ""), config)).toBe(true);
diff --git a/apps/desktop/src/lib/sidebar/sidebarProductionBadge.ts b/apps/desktop/src/lib/sidebar/sidebarProductionBadge.ts
index bb1e4a2a6f..319a021a88 100644
--- a/apps/desktop/src/lib/sidebar/sidebarProductionBadge.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarProductionBadge.ts
@@ -46,6 +46,10 @@ export function showSidebarRowProductionBadge(node: Pick<TreeNode, "type" | "dat
return active && ((scope === "database" && productionContainerTypes.has(node.type)) || (scope === "table" && productionObjectTypes.has(node.type)));
}
+export function isSidebarProductionContainer(node: Pick<TreeNode, "type">): boolean {
+ return node.type === "connection" || productionContainerTypes.has(node.type);
+}
+
export function showSidebarStickyProductionBadge(node: Pick<TreeNode, "database"> | undefined, connection: ConnectionConfig | undefined): boolean {
// Only connection scope needs a separate fixed badge. Database/schema and
// table/object scopes render the badge on the fixed row itself.