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。

fix(chart): show check indicator for selected y-axis columns

lxk9551d3ee9e09b4a
diff --git a/apps/desktop/src/components/chart/QueryChart.vue b/apps/desktop/src/components/chart/QueryChart.vue
index 53c14a6f80..f6e75ff8fc 100644
--- a/apps/desktop/src/components/chart/QueryChart.vue
+++ b/apps/desktop/src/components/chart/QueryChart.vue
@@ -6,9 +6,9 @@ import { CanvasRenderer } from "echarts/renderers";
import { LineChart, BarChart, PieChart } from "echarts/charts";
import { GridComponent, TooltipComponent, LegendComponent } from "echarts/components";
import VChart from "vue-echarts";
-import { BarChart3, ChevronDown } from "@lucide/vue";
+import { BarChart3, Check, ChevronDown } from "@lucide/vue";
import { Button } from "@/components/ui/button";
-import { DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
+import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import type { QueryResult } from "@/types/database";
import { useTheme } from "@/composables/useTheme";
@@ -78,12 +78,12 @@ watch(
{ immediate: true },
);
-function setYColumn(index: number, selected: boolean | "indeterminate") {
+function toggleYColumn(index: number) {
const isSelected = yColumnIndexes.value.includes(index);
- if (selected === true && !isSelected) {
- yColumnIndexes.value = [...yColumnIndexes.value, index];
- } else if (selected !== true && isSelected) {
+ if (isSelected) {
yColumnIndexes.value = yColumnIndexes.value.filter((selected) => selected !== index);
+ } else {
+ yColumnIndexes.value = [...yColumnIndexes.value, index];
}
}
@@ -139,9 +139,20 @@ const hasData = computed(() => props.result.rows.length > 0 && numericColumnInde
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent class="w-56" align="start" @close-auto-focus.prevent>
- <DropdownMenuCheckboxItem v-for="col in numericColumnOptions" :key="col.index" :model-value="yColumnIndexes.includes(col.index)" :class="['text-xs', yColumnIndexes.includes(col.index) ? 'bg-primary/10' : '']" @select.prevent @update:model-value="setYColumn(col.index, $event)">
+ <DropdownMenuItem
+ v-for="col in numericColumnOptions"
+ :key="col.index"
+ role="menuitemcheckbox"
+ :aria-checked="yColumnIndexes.includes(col.index)"
+ class="text-xs flex items-center gap-2 cursor-pointer"
+ :class="yColumnIndexes.includes(col.index) ? 'bg-primary/10' : ''"
+ @select.prevent="toggleYColumn(col.index)"
+ >
+ <span class="flex h-3.5 w-3.5 shrink-0 items-center justify-center rounded border" :class="yColumnIndexes.includes(col.index) ? 'border-primary bg-primary text-primary-foreground' : 'border-input'">
+ <Check v-if="yColumnIndexes.includes(col.index)" class="h-2.5 w-2.5" />
+ </span>
<span class="truncate">{{ col.label }}</span>
- </DropdownMenuCheckboxItem>
+ </DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
diff --git a/apps/desktop/src/components/chart/__tests__/QueryChart.spec.ts b/apps/desktop/src/components/chart/__tests__/QueryChart.spec.ts
index 7288f6c58f..90d93dd9c5 100644
--- a/apps/desktop/src/components/chart/__tests__/QueryChart.spec.ts
+++ b/apps/desktop/src/components/chart/__tests__/QueryChart.spec.ts
@@ -103,4 +103,61 @@ describe("QueryChart", () => {
const option = JSON.parse(vchart.getAttribute("data-chart-option") || "{}");
expect(option.series[0].label.show).toBe(true);
});
+
+ it("renders check indicators for selected y columns and updates chart option on toggle", async () => {
+ const multiResult: QueryResult = {
+ columns: ["item", "val1", "val2"],
+ rows: [
+ ["A", 10, 20],
+ ["B", 30, 40],
+ ],
+ affected_rows: 2,
+ execution_time_ms: 1,
+ };
+ app = createApp(QueryChart, { result: multiResult });
+ app.mount(container!);
+ await nextTick();
+
+ const trigger = container!.querySelector(".max-w-48") as HTMLButtonElement;
+ expect(trigger).not.toBeNull();
+ trigger.click();
+ await nextTick();
+
+ const items = document.querySelectorAll('[role="menuitemcheckbox"]');
+ expect(items.length).toBe(2);
+
+ // Initial state: first numeric column (val1) is selected, second (val2) is not
+ expect(items[0].getAttribute("aria-checked")).toBe("true");
+ expect(items[0].querySelector("svg")).not.toBeNull();
+ expect(items[1].getAttribute("aria-checked")).toBe("false");
+ expect(items[1].querySelector("svg")).toBeNull();
+
+ const vchart = container!.querySelector("[data-chart-option]") as HTMLDivElement;
+ let option = JSON.parse(vchart.getAttribute("data-chart-option") || "{}");
+ expect(option.series.map((s: { name: string }) => s.name)).toEqual(["val1"]);
+
+ // Click on item 1 (val2) to select it
+ (items[1] as HTMLElement).click();
+ await nextTick();
+
+ expect(items[0].getAttribute("aria-checked")).toBe("true");
+ expect(items[0].querySelector("svg")).not.toBeNull();
+ expect(items[1].getAttribute("aria-checked")).toBe("true");
+ expect(items[1].querySelector("svg")).not.toBeNull();
+
+ option = JSON.parse(vchart.getAttribute("data-chart-option") || "{}");
+ expect(option.series.map((s: { name: string }) => s.name)).toEqual(["val1", "val2"]);
+
+ // Click on item 0 (val1) to deselect it
+ (items[0] as HTMLElement).click();
+ await nextTick();
+
+ expect(items[0].getAttribute("aria-checked")).toBe("false");
+ expect(items[0].querySelector("svg")).toBeNull();
+ expect(items[1].getAttribute("aria-checked")).toBe("true");
+ expect(items[1].querySelector("svg")).not.toBeNull();
+
+ option = JSON.parse(vchart.getAttribute("data-chart-option") || "{}");
+ expect(option.series.map((s: { name: string }) => s.name)).toEqual(["val2"]);
+ });
});