feat(toolbar): add backup and MCP shortcuts

This commit is contained in:
t8y2 committed 2026-09-28 03:08:00 +08:00
1 parent b49e288dde
commit 0c61f045c1
14 files changed
+81 -60

No files matched your search

@@ -2,10 +2,10 @@
import { computed, ref, onMounted, onBeforeUnmount, h, nextTick, watch } from "vue";
import { useI18n } from "vue-i18n";
import { invoke } from "@tauri-apps/api/core";
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff } from "@lucide/vue";
import { ChevronsRight, DatabaseZap, FilePlus2, Moon, Sun, SunMoon, History, Bot, ArrowLeftRight, FileCode, BookMarked, GitCompareArrows, TableProperties, Settings, CloudDownload, Package, PlugZap, FileDown, FolderTree, Pin, PinOff, CalendarClock, Waypoints } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import LightDropdown from "@/components/ui/LightDropdown.vue";
import LightDropdown, { type LightDropdownItem } from "@/components/ui/LightDropdown.vue";
import WindowControls from "@/components/layout/WindowControls.vue";
import ExportProgressPopover from "@/components/export/ExportProgressPopover.vue";
import ToolbarUpdateIcon from "@/components/layout/ToolbarUpdateIcon.vue";
@@ -73,6 +73,8 @@ const emit = defineEmits<{
"open-sql-file": [];
"open-schema-diff": [];
"open-data-compare": [];
"open-backups": [];
"open-mcp-settings": [];
}>();
const { t } = useI18n();
@@ -429,11 +431,12 @@ onBeforeUnmount(() => {
// ──────────── Left-side "More" items ────────────
const moreItems = computed(() => {
const items: Array<{ value: string; label: string; icon: any; action: () => void; disabled: boolean }> = [];
type ToolbarMenuItem = LightDropdownItem & { action: () => void };
// Hidden left-side items go into "More"
if (!toolbarItems.value.dataTransfer) {
function buildToolbarMenuItems(includeVisiblePrimaryItems: boolean): ToolbarMenuItem[] {
const items: ToolbarMenuItem[] = [];
if (includeVisiblePrimaryItems || !toolbarItems.value.dataTransfer) {
items.push({
value: "transfer",
label: t("transfer.dataTransfer"),
@@ -442,20 +445,18 @@ const moreItems = computed(() => {
disabled: !props.hasConnections,
});
}
if (!toolbarItems.value.driverManager) {
if (includeVisiblePrimaryItems || !toolbarItems.value.driverManager) {
items.push({
value: "driver-store",
label: t("toolbar.driverManager"),
label: props.agentDriverUpdateCount > 0 ? `${t("toolbar.driverManager")} (${props.agentDriverUpdateCount})` : t("toolbar.driverManager"),
icon: Package,
action: () => emit("open-driver-store"),
disabled: false,
});
}
if (!toolbarItems.value.pluginCenter) {
if (includeVisiblePrimaryItems || !toolbarItems.value.pluginCenter) {
items.push({ value: "plugin-center", label: t("toolbar.pluginCenter"), icon: PlugZap, action: () => emit("open-plugin-center"), disabled: false });
}
// "More" menu items (individually toggleable)
if (toolbarItems.value.sqlFile) {
items.push({
value: "sql-file",
@@ -483,52 +484,39 @@ const moreItems = computed(() => {
disabled: !props.hasConnections,
});
}
items.push({
value: "database-backups",
label: t("databaseBackup.title"),
icon: CalendarClock,
action: () => emit("open-backups"),
disabled: false,
});
items.push({
value: "mcp-settings",
label: t("settings.openMcpSettings"),
icon: Waypoints,
action: () => emit("open-mcp-settings"),
disabled: false,
});
// Append overflowed right-side items at the end
for (const ri of overflowRightMenuItems.value) {
for (const item of overflowRightMenuItems.value) {
items.push({
value: `right-${ri.value}`,
label: ri.label,
icon: ri.icon,
action: ri.action,
disabled: ri.disabled,
value: `right-${item.value}`,
label: item.label,
icon: item.icon,
action: item.action,
disabled: item.disabled,
});
}
return items;
});
}
const moreItems = computed(() => buildToolbarMenuItems(false));
const showMoreDropdown = computed(() => moreItems.value.length > 0);
const collapsedItems = computed(() => {
const items: Array<{ value: string; label: string; icon: any; action: () => void; disabled: boolean }> = [];
if (toolbarItems.value.dataTransfer) {
items.push({
value: "transfer",
label: t("transfer.dataTransfer"),
icon: ArrowLeftRight,
action: () => emit("open-transfer"),
disabled: !props.hasConnections,
});
}
if (toolbarItems.value.driverManager) {
items.push({
value: "driver-store",
label: props.agentDriverUpdateCount > 0 ? `${t("toolbar.driverManager")} (${props.agentDriverUpdateCount})` : t("toolbar.driverManager"),
icon: Package,
action: () => emit("open-driver-store"),
disabled: false,
});
}
if (toolbarItems.value.pluginCenter) {
items.push({ value: "plugin-center", label: t("toolbar.pluginCenter"), icon: PlugZap, action: () => emit("open-plugin-center"), disabled: false });
}
// Always include moreItems (may contain hidden left-side items + overflowed right items)
if (moreItems.value.length > 0) {
items.push(...moreItems.value);
}
return items;
});
const collapsedItems = computed(() => buildToolbarMenuItems(true));
function runMoreItem(value: string) {
const item = moreItems.value.find((i) => i.value === value);
@@ -50,7 +50,12 @@ vi.mock("@/components/ui/tooltip", () => ({
TooltipContent: { name: "TooltipContentStub", template: `<span><slot /></span>` },
}));
vi.mock("@/components/ui/LightDropdown.vue", () => ({
default: { name: "LightDropdownStub", template: `<div />` },
default: {
name: "LightDropdownStub",
props: ["items"],
emits: ["update:modelValue"],
template: `<div data-light-dropdown><button v-for="item in items" :key="item.value" :data-toolbar-menu-item="item.value" :disabled="item.disabled" @click="$emit('update:modelValue', item.value)">{{ item.label }}</button></div>`,
},
}));
vi.mock("@/components/layout/WindowControls.vue", () => ({
default: { name: "WindowControlsStub", template: `<div />` },
@@ -215,4 +220,30 @@ describe("always-on-top button visibility", () => {
unmount();
});
it("exposes backup and MCP shortcuts from the more menu", async () => {
const openBackups = vi.fn();
const openMcpSettings = vi.fn();
const { host, unmount } = mount(AppToolbar, {
...toolbarProps,
onOpenBackups: openBackups,
onOpenMcpSettings: openMcpSettings,
});
await settled();
await nextTick();
const backupButton = host.querySelector<HTMLButtonElement>('[data-toolbar-menu-item="database-backups"]');
const mcpButton = host.querySelector<HTMLButtonElement>('[data-toolbar-menu-item="mcp-settings"]');
expect(backupButton).not.toBeNull();
expect(mcpButton).not.toBeNull();
backupButton?.click();
mcpButton?.click();
expect(openBackups).toHaveBeenCalledOnce();
expect(openMcpSettings).toHaveBeenCalledOnce();
unmount();
});
});