feat(tabs): locate tab objects in sidebar

Closes #6681
This commit is contained in:
t8y2 committed 2026-08-22 10:31:17 +00:00
1 parent 53b7be3c6f
commit 906ea8ba26
8 files changed
+104 -16

No files matched your search

@@ -12,7 +12,7 @@ import ConnectionTree from "@/components/sidebar/ConnectionTree.vue";
import { applyConnectionMultiSelection, emptyConnectionMultiSelection, isExitConnectionMultiSelectionShortcut } from "@/lib/sidebar/sidebarConnectionMultiSelect";
import { useConnectionStore } from "@/stores/connectionStore";
import { useToast } from "@/composables/useToast";
import type { TreeNode } from "@/types/database";
import type { QueryTab, TreeNode } from "@/types/database";
defineProps<{
sidebarWidth: number;
@@ -88,6 +88,10 @@ function focusSearch(): boolean {
return connectionTreeRef.value?.focusSearch() ?? false;
}
function locateTabInSidebar(tab: QueryTab) {
return connectionTreeRef.value?.locateTabInSidebar(tab);
}
function clearConnectionMultiSelection() {
applyConnectionMultiSelection(connectionStore, emptyConnectionMultiSelection());
}
@@ -163,7 +167,7 @@ function confirmCreateSelectedGroup() {
showCreateSelectedGroupDialog.value = false;
}
defineExpose({ focusSearch });
defineExpose({ focusSearch, locateTabInSidebar });
</script>
<template>
@@ -2,7 +2,7 @@
import { computed, ref, watch, nextTick, onUnmounted } from "vue";
import type { CSSProperties } from "vue";
import { useI18n } from "vue-i18n";
import { X, Pin, ChevronDown, Search, Table2, Code2, TableProperties, PencilRuler, KeyRound, Pencil, Package, Lock, Copy, AlertTriangle, Network, Minimize2, Maximize2, Settings, CalendarClock, Activity, Gauge, ShieldCheck, Database, GitBranch } from "@lucide/vue";
import { X, Pin, ChevronDown, Search, Table2, Code2, TableProperties, PencilRuler, KeyRound, Pencil, Package, Lock, Copy, AlertTriangle, Network, Minimize2, Maximize2, Settings, CalendarClock, Activity, Gauge, ShieldCheck, Database, GitBranch, Crosshair } from "@lucide/vue";
import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";
import { Tooltip, TooltipTrigger, TooltipContent } from "@/components/ui/tooltip";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
@@ -19,6 +19,7 @@ import { connectionColor, isConnectionReadonly, tabDisplayTitle, tabTooltipLines
import { hexToRgba } from "@/lib/common/color";
import { copyToClipboard } from "@/lib/common/clipboard";
import { useToast } from "@/composables/useToast";
import { activeTabSidebarTarget } from "@/lib/sidebar/sidebarActiveTabTarget";
import type { QueryTab } from "@/types/database";
const props = defineProps<{
@@ -31,6 +32,7 @@ const props = defineProps<{
const emit = defineEmits<{
"activate-tab": [];
"locate-tab": [tab: QueryTab];
"activate-driver-store": [];
"close-driver-store": [];
"activate-settings-page": [];
@@ -318,6 +320,12 @@ function getTabMenuItems(tab: QueryTab): ContextMenuItem[] {
},
icon: Copy,
},
{
label: t("sidebar.locateActiveTab"),
action: () => emit("locate-tab", tab),
icon: Crosshair,
visible: !!activeTabSidebarTarget(tab),
},
{ label: "", separator: true },
{
label: tab.pinned ? t("contextMenu.unfixTab") : t("contextMenu.fixTab"),
@@ -3,6 +3,14 @@ import { describe, expect, it } from "vitest";
const tabBarSource = readFileSync(new URL("../AppTabBar.vue", import.meta.url), "utf8");
function sourceBetween(start: string, end: string): string {
const startIndex = tabBarSource.indexOf(start);
const endIndex = tabBarSource.indexOf(end, startIndex + start.length);
expect(startIndex).toBeGreaterThanOrEqual(0);
expect(endIndex).toBeGreaterThan(startIndex);
return tabBarSource.slice(startIndex, endIndex);
}
describe("AppTabBar close confirmation layout", () => {
it("allows long unbroken tab titles to shrink and wrap inside the dialog", () => {
expect(tabBarSource).toMatch(/<DialogContent class="[^"]*\bmin-w-0\b[^"]*\bsm:max-w-md\b/);
@@ -38,6 +46,26 @@ describe("AppTabBar object browser presentation", () => {
});
});
describe("AppTabBar locate-in-sidebar action", () => {
it("emits the exact right-clicked tab only when it has a sidebar target", () => {
const menu = sourceBetween("function getTabMenuItems", "function handleSaveAndClose");
expect(tabBarSource).toContain('"locate-tab": [tab: QueryTab];');
expect(menu).toMatch(/label: t\("sidebar\.locateActiveTab"\),\s*action: \(\) => emit\("locate-tab", tab\),\s*icon: Crosshair,\s*visible: !!activeTabSidebarTarget\(tab\)/);
expect(menu).not.toContain("activateTab(tab.id)");
});
it("leaves settings, driver, and existing regular-tab menu actions unchanged", () => {
const specialMenu = sourceBetween("function getSpecialRegularTabMenuItems", "function getTabMenuItems");
const regularMenu = sourceBetween("function getTabMenuItems", "function handleSaveAndClose");
expect(specialMenu).not.toContain('t("sidebar.locateActiveTab")');
expect(regularMenu).toContain('label: t("contextMenu.copyName")');
expect(regularMenu).toContain("action: () => queryStore.togglePinnedTab(tab.id)");
expect(regularMenu).toContain("action: () => queryStore.closeTab(tab.id)");
});
});
describe("AppTabBar right-side close action", () => {
it("places the action after close-other and disables it when the target has no tabs to its right", () => {
expect(tabBarSource).toContain('label: t("contextMenu.closeRightTabs")');