feat(sidebar): locate column in data grid on sidebar column click
This commit is contained in:
1 parent
9419e18b79
commit
f951983914
14 files changed
+549
-5
No files matched your search
@@ -605,6 +605,7 @@ interface DataGridProps {
|
|||||||
showCancel?: boolean;
|
showCancel?: boolean;
|
||||||
cancelling?: boolean;
|
cancelling?: boolean;
|
||||||
cancelDisabled?: boolean;
|
cancelDisabled?: boolean;
|
||||||
|
revealColumnRequest?: { id: number; columnName: string };
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = withDefaults(defineProps<DataGridProps>(), {
|
const props = withDefaults(defineProps<DataGridProps>(), {
|
||||||
@@ -2522,6 +2523,52 @@ function scrollToColumnIndex(columnIndex: number) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let lastHandledRevealColumnRequestId: number | null = null;
|
||||||
|
|
||||||
|
function handleRevealColumnRequest(request?: { id: number; columnName: string }) {
|
||||||
|
if (!request?.columnName || request.id === lastHandledRevealColumnRequestId) return;
|
||||||
|
if (!props.result.columns || props.result.columns.length === 0) return;
|
||||||
|
const columnIndex = props.result.columns.findIndex((column, index) => matchesTableInfoColumn(column, props.sourceColumns?.[index], request.columnName));
|
||||||
|
if (columnIndex < 0) return;
|
||||||
|
lastHandledRevealColumnRequestId = request.id;
|
||||||
|
scrollToColumnIndex(columnIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.revealColumnRequest,
|
||||||
|
(request) => {
|
||||||
|
handleRevealColumnRequest(request);
|
||||||
|
},
|
||||||
|
{ immediate: true, deep: true },
|
||||||
|
);
|
||||||
|
|
||||||
|
watch(
|
||||||
|
() => props.result.columns,
|
||||||
|
() => {
|
||||||
|
if (props.revealColumnRequest && props.revealColumnRequest.id !== lastHandledRevealColumnRequestId) {
|
||||||
|
void nextTick(() => {
|
||||||
|
handleRevealColumnRequest(props.revealColumnRequest);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
if (props.revealColumnRequest && props.revealColumnRequest.id !== lastHandledRevealColumnRequestId) {
|
||||||
|
void nextTick(() => {
|
||||||
|
handleRevealColumnRequest(props.revealColumnRequest);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
onActivated(() => {
|
||||||
|
if (props.revealColumnRequest && props.revealColumnRequest.id !== lastHandledRevealColumnRequestId) {
|
||||||
|
void nextTick(() => {
|
||||||
|
handleRevealColumnRequest(props.revealColumnRequest);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// --- Column resize composable ---
|
// --- Column resize composable ---
|
||||||
const columnWidthDensity = computed(() => settingsStore.editorSettings.columnWidthDensity);
|
const columnWidthDensity = computed(() => settingsStore.editorSettings.columnWidthDensity);
|
||||||
const columnWidthMode = computed(() => settingsStore.editorSettings.dataGridColumnWidthMode ?? "content");
|
const columnWidthMode = computed(() => settingsStore.editorSettings.dataGridColumnWidthMode ?? "content");
|
||||||
|
|||||||
@@ -0,0 +1,175 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
|
||||||
|
import { createApp, defineComponent, h, markRaw, nextTick, ref, type App, type PropType } from "vue";
|
||||||
|
import { createPinia, setActivePinia } from "pinia";
|
||||||
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import i18n from "@/i18n";
|
||||||
|
import type { QueryResult } from "@/types/database";
|
||||||
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
|
vi.mock("@/composables/useDataGridColumnResize", async (importOriginal) => {
|
||||||
|
const actual = await importOriginal<typeof import("@/composables/useDataGridColumnResize")>();
|
||||||
|
const { ref } = await import("vue");
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
useDataGridColumnResize: () => ({
|
||||||
|
initColumnWidths: vi.fn(),
|
||||||
|
onResizeStart: vi.fn(),
|
||||||
|
autoFitColumn: vi.fn(),
|
||||||
|
renderedColumnWidths: ref([100, 100, 100, 100]),
|
||||||
|
totalWidth: ref(400),
|
||||||
|
columnVars: ref({ "--total-w": "400px" }),
|
||||||
|
getIsResizing: () => false,
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
import DataGrid from "../DataGrid.vue";
|
||||||
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
|
|
||||||
|
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
||||||
|
|
||||||
|
const RecycleScroller = defineComponent({
|
||||||
|
props: {
|
||||||
|
items: {
|
||||||
|
type: Array as PropType<unknown[]>,
|
||||||
|
default: () => [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
setup(props, { attrs, slots }) {
|
||||||
|
return () =>
|
||||||
|
h(
|
||||||
|
"div",
|
||||||
|
attrs,
|
||||||
|
props.items.map((item) => slots.default?.({ item })),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const { app, host } of mountedApps.splice(0)) {
|
||||||
|
app.unmount();
|
||||||
|
host.remove();
|
||||||
|
}
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("DataGrid revealColumnRequest", () => {
|
||||||
|
it("reveals and highlights column matching revealColumnRequest", async () => {
|
||||||
|
const pinia = createPinia();
|
||||||
|
setActivePinia(pinia);
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
settingsStore.updateEditorSettings({
|
||||||
|
dataGridRenderMode: "canvas",
|
||||||
|
});
|
||||||
|
|
||||||
|
const columns = ["id", "username", "email", "created_at"];
|
||||||
|
const result = markRaw<QueryResult>({
|
||||||
|
columns,
|
||||||
|
rows: [[1, "alice", "alice@example.com", "2026-01-01"]],
|
||||||
|
affected_rows: 0,
|
||||||
|
execution_time_ms: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const revealRequest = ref<{ id: number; columnName: string } | undefined>({
|
||||||
|
id: 1,
|
||||||
|
columnName: "email",
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = document.createElement("div");
|
||||||
|
document.body.append(host);
|
||||||
|
|
||||||
|
const Root = defineComponent({
|
||||||
|
setup() {
|
||||||
|
return () =>
|
||||||
|
h(
|
||||||
|
TooltipProvider,
|
||||||
|
{ delayDuration: 0 },
|
||||||
|
{
|
||||||
|
default: () =>
|
||||||
|
h(DataGrid, {
|
||||||
|
result,
|
||||||
|
databaseType: "mysql",
|
||||||
|
context: "table-data",
|
||||||
|
revealColumnRequest: revealRequest.value,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = createApp(Root);
|
||||||
|
app.use(pinia);
|
||||||
|
app.use(i18n);
|
||||||
|
app.component("RecycleScroller", RecycleScroller);
|
||||||
|
app.mount(host);
|
||||||
|
mountedApps.push({ app, host });
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
const emailHeader = host.querySelector('[data-grid-column-index="2"]');
|
||||||
|
expect(emailHeader).toBeTruthy();
|
||||||
|
expect(emailHeader?.classList.contains("data-grid-header-cell--selected")).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates reveal when revealColumnRequest prop changes with new id", async () => {
|
||||||
|
const pinia = createPinia();
|
||||||
|
setActivePinia(pinia);
|
||||||
|
const settingsStore = useSettingsStore();
|
||||||
|
settingsStore.updateEditorSettings({
|
||||||
|
dataGridRenderMode: "canvas",
|
||||||
|
});
|
||||||
|
|
||||||
|
const columns = ["id", "username", "email", "created_at"];
|
||||||
|
const result = markRaw<QueryResult>({
|
||||||
|
columns,
|
||||||
|
rows: [[1, "alice", "alice@example.com", "2026-01-01"]],
|
||||||
|
affected_rows: 0,
|
||||||
|
execution_time_ms: 0,
|
||||||
|
});
|
||||||
|
|
||||||
|
const revealRequest = ref<{ id: number; columnName: string } | undefined>(undefined);
|
||||||
|
|
||||||
|
const host = document.createElement("div");
|
||||||
|
document.body.append(host);
|
||||||
|
|
||||||
|
const Root = defineComponent({
|
||||||
|
setup() {
|
||||||
|
return () =>
|
||||||
|
h(
|
||||||
|
TooltipProvider,
|
||||||
|
{ delayDuration: 0 },
|
||||||
|
{
|
||||||
|
default: () =>
|
||||||
|
h(DataGrid, {
|
||||||
|
result,
|
||||||
|
databaseType: "mysql",
|
||||||
|
context: "table-data",
|
||||||
|
revealColumnRequest: revealRequest.value,
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const app = createApp(Root);
|
||||||
|
app.use(pinia);
|
||||||
|
app.use(i18n);
|
||||||
|
app.component("RecycleScroller", RecycleScroller);
|
||||||
|
app.mount(host);
|
||||||
|
mountedApps.push({ app, host });
|
||||||
|
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
// Trigger reveal request
|
||||||
|
revealRequest.value = { id: 2, columnName: "created_at" };
|
||||||
|
await nextTick();
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
const createdAtHeader = host.querySelector('[data-grid-column-index="3"]');
|
||||||
|
expect(createdAtHeader).toBeTruthy();
|
||||||
|
expect(createdAtHeader?.classList.contains("data-grid-header-cell--selected")).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2518,6 +2518,7 @@ defineExpose({
|
|||||||
:allow-insert-rows="activeTab.queryAnalysis?.allowInsert ?? activeTab.queryAnalysis?.allowInsertDelete !== false"
|
:allow-insert-rows="activeTab.queryAnalysis?.allowInsert ?? activeTab.queryAnalysis?.allowInsertDelete !== false"
|
||||||
:allow-delete-rows="activeTab.queryAnalysis?.allowDelete ?? activeTab.queryAnalysis?.allowInsertDelete !== false"
|
:allow-delete-rows="activeTab.queryAnalysis?.allowDelete ?? activeTab.queryAnalysis?.allowInsertDelete !== false"
|
||||||
context="results"
|
context="results"
|
||||||
|
:reveal-column-request="activeTab.gridRevealColumnRequest"
|
||||||
:auto-transpose-single-row="settingsStore.editorSettings.dataGridAutoTransposeSingleRow"
|
:auto-transpose-single-row="settingsStore.editorSettings.dataGridAutoTransposeSingleRow"
|
||||||
:database-type="activeEffectiveDatabaseType"
|
:database-type="activeEffectiveDatabaseType"
|
||||||
:connection-id="activeResultConnectionId"
|
:connection-id="activeResultConnectionId"
|
||||||
@@ -3014,6 +3015,7 @@ defineExpose({
|
|||||||
:show-cancel="shouldShowCancelAction(activeTab)"
|
:show-cancel="shouldShowCancelAction(activeTab)"
|
||||||
:cancelling="activeTab.isCancelling"
|
:cancelling="activeTab.isCancelling"
|
||||||
:cancel-disabled="!canCancelQueryExecution(activeTab)"
|
:cancel-disabled="!canCancelQueryExecution(activeTab)"
|
||||||
|
:reveal-column-request="activeTab.gridRevealColumnRequest"
|
||||||
@cancel="emit('cancel', activeTab.id)"
|
@cancel="emit('cancel', activeTab.id)"
|
||||||
@update:where-input="(v: string) => (activeTab.whereInput = v)"
|
@update:where-input="(v: string) => (activeTab.whereInput = v)"
|
||||||
@update:order-by-input="(v: string) => (activeTab.orderByInput = v)"
|
@update:order-by-input="(v: string) => (activeTab.orderByInput = v)"
|
||||||
|
|||||||
@@ -1190,6 +1190,8 @@ function runRowClickAction(clickDetail: number) {
|
|||||||
const requestId = beginNavigationRequest();
|
const requestId = beginNavigationRequest();
|
||||||
if (action === "open-data") {
|
if (action === "open-data") {
|
||||||
scheduleOpenData(node);
|
scheduleOpenData(node);
|
||||||
|
} else if (action === "locate-column") {
|
||||||
|
locateColumnInDataGrid(node);
|
||||||
} else if (action === "open-object-browser") {
|
} else if (action === "open-object-browser") {
|
||||||
void openObjectBrowser(false, false, true);
|
void openObjectBrowser(false, false, true);
|
||||||
} else if (action === "open-object-browser-and-expand") {
|
} else if (action === "open-object-browser-and-expand") {
|
||||||
@@ -1631,6 +1633,8 @@ function onDoubleClick(event: MouseEvent) {
|
|||||||
openDataImmediately(activeNode.value);
|
openDataImmediately(activeNode.value);
|
||||||
} else if (action === "activate-data") {
|
} else if (action === "activate-data") {
|
||||||
activateDataTableFromDoubleClick();
|
activateDataTableFromDoubleClick();
|
||||||
|
} else if (action === "locate-column") {
|
||||||
|
locateColumnInDataGrid(activeNode.value);
|
||||||
} else if (action === "open-source") {
|
} else if (action === "open-source") {
|
||||||
openObjectSourceDialog(false);
|
openObjectSourceDialog(false);
|
||||||
} else if (action === "open-extension-details") {
|
} else if (action === "open-extension-details") {
|
||||||
@@ -1671,6 +1675,57 @@ function findExistingSameTableDataTab() {
|
|||||||
return queryStore.tabs.find((tab) => tab.mode === "data" && tab.connectionId === node.connectionId && tab.database === node.database && (tab.tableMeta?.catalog || "") === (node.catalog || "") && (tab.schema || "") === (tableSchema || "") && (tab.tableMeta?.tableName || tab.title) === node.label);
|
return queryStore.tabs.find((tab) => tab.mode === "data" && tab.connectionId === node.connectionId && tab.database === node.database && (tab.tableMeta?.catalog || "") === (node.catalog || "") && (tab.schema || "") === (tableSchema || "") && (tab.tableMeta?.tableName || tab.title) === node.label);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractColumnNameFromTreeNode(node: TreeNode): string {
|
||||||
|
if (node.meta && typeof node.meta === "object" && "name" in node.meta && typeof (node.meta as any).name === "string") {
|
||||||
|
return (node.meta as any).name;
|
||||||
|
}
|
||||||
|
return node.label.replace(/\s+\(.+\)$/, "").trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findTableNodeForColumn(columnNode: TreeNode): TreeNode | undefined {
|
||||||
|
if (!columnNode.tableName) return undefined;
|
||||||
|
const match = (n: TreeNode): boolean => {
|
||||||
|
return (
|
||||||
|
(n.type === "table" || n.type === "view" || n.type === "materialized_view") &&
|
||||||
|
n.connectionId === columnNode.connectionId &&
|
||||||
|
n.database === columnNode.database &&
|
||||||
|
(n.schema || "") === (columnNode.schema || "") &&
|
||||||
|
(n.catalog || "") === (columnNode.catalog || "") &&
|
||||||
|
(n.label === columnNode.tableName || n.tableName === columnNode.tableName)
|
||||||
|
);
|
||||||
|
};
|
||||||
|
const search = (nodes: TreeNode[]): TreeNode | undefined => {
|
||||||
|
for (const n of nodes) {
|
||||||
|
if (match(n)) return n;
|
||||||
|
if (n.children?.length) {
|
||||||
|
const found = search(n.children);
|
||||||
|
if (found) return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
return search(connectionStore.treeNodes);
|
||||||
|
}
|
||||||
|
|
||||||
|
function locateColumnInDataGrid(columnNode: TreeNode) {
|
||||||
|
if (!columnNode.tableName || !hasNodeDatabaseContext(columnNode)) return;
|
||||||
|
const columnName = extractColumnNameFromTreeNode(columnNode);
|
||||||
|
if (!columnName) return;
|
||||||
|
|
||||||
|
const tableNode = findTableNodeForColumn(columnNode) ?? {
|
||||||
|
id: columnNode.schema ? `${columnNode.connectionId}:${columnNode.database}:${columnNode.schema}:${columnNode.tableName}` : `${columnNode.connectionId}:${columnNode.database}:${columnNode.tableName}`,
|
||||||
|
label: columnNode.tableName,
|
||||||
|
type: "table" as const,
|
||||||
|
connectionId: columnNode.connectionId,
|
||||||
|
database: columnNode.database,
|
||||||
|
schema: columnNode.schema,
|
||||||
|
catalog: columnNode.catalog,
|
||||||
|
tableName: columnNode.tableName,
|
||||||
|
};
|
||||||
|
|
||||||
|
emit("open-data", tableNode, false, "default", (target, request) => openData(target, request, "default", { revealColumn: columnName }));
|
||||||
|
}
|
||||||
|
|
||||||
function openMongoTreeData(node: TreeNode) {
|
function openMongoTreeData(node: TreeNode) {
|
||||||
if (!node.connectionId || !node.database) return;
|
if (!node.connectionId || !node.database) return;
|
||||||
if (node.type === "mongo-gridfs") {
|
if (node.type === "mongo-gridfs") {
|
||||||
|
|||||||
+172
@@ -0,0 +1,172 @@
|
|||||||
|
// @vitest-environment happy-dom
|
||||||
|
|
||||||
|
import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";
|
||||||
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
|
import i18n from "@/i18n";
|
||||||
|
import type { TreeNode } from "@/types/database";
|
||||||
|
import SidebarTreeRuntimeHost from "@/components/sidebar/SidebarTreeRuntimeHost.vue";
|
||||||
|
|
||||||
|
const connectionStore = {
|
||||||
|
treeNodes: [] as TreeNode[],
|
||||||
|
sidebarSearchQuery: "",
|
||||||
|
activeConnectionId: null as string | null,
|
||||||
|
connectedIds: new Set<string>(),
|
||||||
|
selectedTreeNodeId: null as string | null,
|
||||||
|
selectedTreeNodeIds: [] as string[],
|
||||||
|
treeSelectionAnchorId: null as string | null,
|
||||||
|
connectionMultiSelectActive: false,
|
||||||
|
get selectedTreeNodeIdsSet(): Set<string> {
|
||||||
|
return new Set(this.selectedTreeNodeIds);
|
||||||
|
},
|
||||||
|
canUseLoadedTreeNodeToggle: vi.fn(() => true),
|
||||||
|
releaseCollapsedTreeNodeChildren: vi.fn(),
|
||||||
|
getConfig: vi.fn(() => ({ db_type: "mysql", name: "connection" })),
|
||||||
|
ensureConnected: vi.fn(async () => undefined),
|
||||||
|
};
|
||||||
|
|
||||||
|
const queryStore = {
|
||||||
|
tabs: [] as any[],
|
||||||
|
switchTab: vi.fn(),
|
||||||
|
createTab: vi.fn(),
|
||||||
|
};
|
||||||
|
|
||||||
|
const settings = {
|
||||||
|
sidebarActivation: "single",
|
||||||
|
sidebarBrowseObjectsOnDatabaseActivation: false,
|
||||||
|
dataTabReuseMode: "same-table",
|
||||||
|
shortcuts: { openDataInNewTab: "" },
|
||||||
|
};
|
||||||
|
|
||||||
|
const openDataMock = vi.fn();
|
||||||
|
|
||||||
|
vi.mock("@/stores/connectionStore", () => ({
|
||||||
|
CONNECTION_ATTEMPT_CANCELLED_MESSAGE: "connection attempt cancelled",
|
||||||
|
useConnectionStore: () => connectionStore,
|
||||||
|
}));
|
||||||
|
|
||||||
|
vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => queryStore }));
|
||||||
|
vi.mock("@/stores/settingsStore", () => ({ useSettingsStore: () => ({ editorSettings: settings }) }));
|
||||||
|
vi.mock("@/stores/savedSqlStore", () => ({ useSavedSqlStore: () => ({}) }));
|
||||||
|
vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));
|
||||||
|
vi.mock("@/composables/useSqlHighlighter", () => ({ useSqlHighlighter: () => ({ highlight: vi.fn() }) }));
|
||||||
|
vi.mock("@/composables/useSidebarDataOpenRuntime", () => ({ useSidebarDataOpenRuntime: () => ({ openData: openDataMock }) }));
|
||||||
|
vi.mock("@/composables/useDatabaseOptions", () => ({ useDatabaseOptions: () => ({ getDatabaseOptions: vi.fn() }) }));
|
||||||
|
vi.mock("@/composables/useSidebarConnectionMutationRuntime", () => ({ useSidebarConnectionMutationRuntime: () => ({}) }));
|
||||||
|
vi.mock("@/composables/useSidebarDatabaseSpecificMutationRuntime", () => ({ useSidebarDatabaseSpecificMutationRuntime: () => ({}) }));
|
||||||
|
vi.mock("@/composables/useSidebarTableMutationRuntime", () => ({ useSidebarTableMutationRuntime: () => ({}) }));
|
||||||
|
vi.mock("@/composables/useSidebarTreeExportRuntime", () => ({ useSidebarTreeExportRuntime: () => ({}) }));
|
||||||
|
vi.mock("@/composables/useSidebarTreeToolRuntime", () => ({ useSidebarTreeToolRuntime: () => ({}) }));
|
||||||
|
|
||||||
|
const mountedApps: App[] = [];
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
for (const app of mountedApps.splice(0)) app.unmount();
|
||||||
|
document.body.innerHTML = "";
|
||||||
|
connectionStore.treeNodes = [];
|
||||||
|
openDataMock.mockReset();
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("SidebarTreeRuntimeHost column locate", () => {
|
||||||
|
it("locates column in data grid on single click in single-activation mode", async () => {
|
||||||
|
settings.sidebarActivation = "single";
|
||||||
|
|
||||||
|
const tableNode: TreeNode = {
|
||||||
|
id: "mysql:app:users",
|
||||||
|
label: "users",
|
||||||
|
type: "table",
|
||||||
|
connectionId: "mysql",
|
||||||
|
database: "app",
|
||||||
|
isExpanded: true,
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
const columnNode: TreeNode = {
|
||||||
|
id: "mysql:app:users:__columns:email",
|
||||||
|
label: "email (varchar(255))",
|
||||||
|
type: "column",
|
||||||
|
connectionId: "mysql",
|
||||||
|
database: "app",
|
||||||
|
tableName: "users",
|
||||||
|
meta: { name: "email", data_type: "varchar(255)" },
|
||||||
|
};
|
||||||
|
tableNode.children = [columnNode];
|
||||||
|
connectionStore.treeNodes = [tableNode];
|
||||||
|
|
||||||
|
const onOpenData = vi.fn(async (target, requireSelection, openMode, runner) => {
|
||||||
|
await runner(target, { isCurrent: () => true, signal: new AbortController().signal, registerCancel: vi.fn() });
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = ref<InstanceType<typeof SidebarTreeRuntimeHost> | null>(null);
|
||||||
|
const container = document.createElement("div");
|
||||||
|
document.body.appendChild(container);
|
||||||
|
|
||||||
|
const app = createApp(
|
||||||
|
defineComponent({
|
||||||
|
setup() {
|
||||||
|
return () => h(SidebarTreeRuntimeHost, { ref: host, node: columnNode, depth: 1, onOpenData });
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
app.use(i18n);
|
||||||
|
mountedApps.push(app);
|
||||||
|
app.mount(container);
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
host.value?.handleRowClick(columnNode, 1);
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onOpenData).toHaveBeenCalledWith(expect.objectContaining({ label: "users", connectionId: "mysql", database: "app" }), false, "default", expect.any(Function));
|
||||||
|
expect(openDataMock).toHaveBeenCalledWith(expect.objectContaining({ label: "users" }), expect.anything(), "default", { revealColumn: "email" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("locates column in data grid on double click in double-activation mode", async () => {
|
||||||
|
settings.sidebarActivation = "double";
|
||||||
|
|
||||||
|
const tableNode: TreeNode = {
|
||||||
|
id: "mysql:app:users",
|
||||||
|
label: "users",
|
||||||
|
type: "table",
|
||||||
|
connectionId: "mysql",
|
||||||
|
database: "app",
|
||||||
|
isExpanded: true,
|
||||||
|
children: [],
|
||||||
|
};
|
||||||
|
const columnNode: TreeNode = {
|
||||||
|
id: "mysql:app:users:__columns:age",
|
||||||
|
label: "age (int)",
|
||||||
|
type: "column",
|
||||||
|
connectionId: "mysql",
|
||||||
|
database: "app",
|
||||||
|
tableName: "users",
|
||||||
|
meta: { name: "age", data_type: "int" },
|
||||||
|
};
|
||||||
|
tableNode.children = [columnNode];
|
||||||
|
connectionStore.treeNodes = [tableNode];
|
||||||
|
|
||||||
|
const onOpenData = vi.fn(async (target, requireSelection, openMode, runner) => {
|
||||||
|
await runner(target, { isCurrent: () => true, signal: new AbortController().signal, registerCancel: vi.fn() });
|
||||||
|
});
|
||||||
|
|
||||||
|
const host = ref<InstanceType<typeof SidebarTreeRuntimeHost> | null>(null);
|
||||||
|
const container = document.createElement("div");
|
||||||
|
document.body.appendChild(container);
|
||||||
|
|
||||||
|
const app = createApp(
|
||||||
|
defineComponent({
|
||||||
|
setup() {
|
||||||
|
return () => h(SidebarTreeRuntimeHost, { ref: host, node: columnNode, depth: 1, onOpenData });
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
app.use(i18n);
|
||||||
|
mountedApps.push(app);
|
||||||
|
app.mount(container);
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
host.value?.handleRowDoubleClick(columnNode, new MouseEvent("dblclick"));
|
||||||
|
await nextTick();
|
||||||
|
|
||||||
|
expect(onOpenData).toHaveBeenCalledWith(expect.objectContaining({ label: "users", connectionId: "mysql", database: "app" }), false, "default", expect.any(Function));
|
||||||
|
expect(openDataMock).toHaveBeenCalledWith(expect.objectContaining({ label: "users" }), expect.anything(), "default", { revealColumn: "age" });
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -96,6 +96,12 @@ vi.mock("@/stores/queryStore", () => ({
|
|||||||
executeTabSql: mocks.executeTabSql,
|
executeTabSql: mocks.executeTabSql,
|
||||||
sortTabResultLocally: mocks.sortTabResultLocally,
|
sortTabResultLocally: mocks.sortTabResultLocally,
|
||||||
setErrorResult: mocks.setErrorResult,
|
setErrorResult: mocks.setErrorResult,
|
||||||
|
requestGridRevealColumn: vi.fn((tabId: string, columnName: string) => {
|
||||||
|
const tab = mocks.tabs.find((item) => item.id === tabId);
|
||||||
|
if (tab) {
|
||||||
|
tab.gridRevealColumnRequest = { id: 1, columnName };
|
||||||
|
}
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@@ -856,4 +862,19 @@ describe("useSidebarDataOpenRuntime", () => {
|
|||||||
expect(mocks.tabs[0]?.tableMeta?.columns).toEqual([]);
|
expect(mocks.tabs[0]?.tableMeta?.columns).toEqual([]);
|
||||||
expect(mocks.tabs[0]?.tableMetaGeneration).toBe(0);
|
expect(mocks.tabs[0]?.tableMetaGeneration).toBe(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("requests grid column reveal when opening a table with revealColumn option", async () => {
|
||||||
|
await useSidebarDataOpenRuntime().openData(tableNode, undefined, "default", { revealColumn: "email" });
|
||||||
|
|
||||||
|
expect(mocks.tabs[0]?.gridRevealColumnRequest).toEqual({ id: 1, columnName: "email" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("requests grid column reveal when activating an existing same-table tab with revealColumn option", async () => {
|
||||||
|
mocks.dataTabReuseMode = "same-table";
|
||||||
|
await useSidebarDataOpenRuntime().openData(tableNode);
|
||||||
|
expect(mocks.tabs[0]?.gridRevealColumnRequest).toBeUndefined();
|
||||||
|
|
||||||
|
await useSidebarDataOpenRuntime().openData(tableNode, undefined, "default", { revealColumn: "created_at" });
|
||||||
|
expect(mocks.tabs[0]?.gridRevealColumnRequest).toEqual({ id: 1, columnName: "created_at" });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -30,7 +30,7 @@ export function useSidebarDataOpenRuntime() {
|
|||||||
const queryStore = useQueryStore();
|
const queryStore = useQueryStore();
|
||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
|
|
||||||
async function openData(node: TreeNode, request?: SidebarDataOpenRequest, openMode: DataTabOpenMode = "default", options: { reuseMode?: DataTabReuseMode } = {}) {
|
async function openData(node: TreeNode, request?: SidebarDataOpenRequest, openMode: DataTabOpenMode = "default", options: { reuseMode?: DataTabReuseMode; revealColumn?: string } = {}) {
|
||||||
if (!(node.type === "table" || node.type === "view" || node.type === "materialized_view") || !hasNodeDatabaseContext(node)) return;
|
if (!(node.type === "table" || node.type === "view" || node.type === "materialized_view") || !hasNodeDatabaseContext(node)) return;
|
||||||
const config = connectionStore.getConfig(node.connectionId);
|
const config = connectionStore.getConfig(node.connectionId);
|
||||||
const reuseMode = options.reuseMode ?? settingsStore.editorSettings.dataTabReuseMode;
|
const reuseMode = options.reuseMode ?? settingsStore.editorSettings.dataTabReuseMode;
|
||||||
@@ -200,6 +200,9 @@ export function useSidebarDataOpenRuntime() {
|
|||||||
tableType,
|
tableType,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (options.revealColumn) {
|
||||||
|
queryStore.requestGridRevealColumn(existingSameTableTab.id, options.revealColumn);
|
||||||
|
}
|
||||||
queryStore.switchTab(existingSameTableTab.id);
|
queryStore.switchTab(existingSameTableTab.id);
|
||||||
logPhase("existing-tab-activated", { table: node.label });
|
logPhase("existing-tab-activated", { table: node.label });
|
||||||
// 代次失配视同冷缓存(即使位于 30s TTL 窗口内也要重建):disconnect /
|
// 代次失配视同冷缓存(即使位于 30s TTL 窗口内也要重建):disconnect /
|
||||||
@@ -220,6 +223,9 @@ export function useSidebarDataOpenRuntime() {
|
|||||||
queryStore.switchTab(existingDataTabCandidate.tab.id);
|
queryStore.switchTab(existingDataTabCandidate.tab.id);
|
||||||
resetReusedDataTabState(existingDataTabCandidate.tab);
|
resetReusedDataTabState(existingDataTabCandidate.tab);
|
||||||
existingDataTabCandidate.tab.tableComment = node.comment;
|
existingDataTabCandidate.tab.tableComment = node.comment;
|
||||||
|
if (options.revealColumn) {
|
||||||
|
queryStore.requestGridRevealColumn(existingDataTabCandidate.tab.id, options.revealColumn);
|
||||||
|
}
|
||||||
return existingDataTabCandidate.tab.id;
|
return existingDataTabCandidate.tab.id;
|
||||||
}
|
}
|
||||||
const createdTabId = queryStore.createTab(node.connectionId, node.database, node.label, "data", tableSchema, undefined, node.catalog, {
|
const createdTabId = queryStore.createTab(node.connectionId, node.database, node.label, "data", tableSchema, undefined, node.catalog, {
|
||||||
@@ -227,7 +233,12 @@ export function useSidebarDataOpenRuntime() {
|
|||||||
insertAfterActive: settingsStore.editorSettings.openDataTabsNextToActive,
|
insertAfterActive: settingsStore.editorSettings.openDataTabsNextToActive,
|
||||||
});
|
});
|
||||||
const createdTab = queryStore.tabs.find((tab) => tab.id === createdTabId);
|
const createdTab = queryStore.tabs.find((tab) => tab.id === createdTabId);
|
||||||
if (createdTab) createdTab.tableComment = node.comment;
|
if (createdTab) {
|
||||||
|
createdTab.tableComment = node.comment;
|
||||||
|
if (options.revealColumn) {
|
||||||
|
queryStore.requestGridRevealColumn(createdTab.id, options.revealColumn);
|
||||||
|
}
|
||||||
|
}
|
||||||
return createdTabId;
|
return createdTabId;
|
||||||
})();
|
})();
|
||||||
openDataLog("info", "tab-created", { traceId, tabId, elapsed: elapsed() });
|
openDataLog("info", "tab-created", { traceId, tabId, elapsed: elapsed() });
|
||||||
|
|||||||
@@ -218,4 +218,11 @@ describe("treeNodeClick", () => {
|
|||||||
signature: undefined,
|
signature: undefined,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("locates column in data grid on single click in single-activation mode and double click in double-activation mode", () => {
|
||||||
|
expect(treeNodeRowAction("column", false, "single")).toBe("locate-column");
|
||||||
|
expect(treeNodeRowAction("column", false, "double")).toBe("none");
|
||||||
|
expect(treeNodeRowDoubleClickAction("column", false, "single")).toBe("none");
|
||||||
|
expect(treeNodeRowDoubleClickAction("column", false, "double")).toBe("locate-column");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -2,8 +2,8 @@ import type { DatabaseType, ObjectSourceKind, TreeNode, TreeNodeType } from "@/t
|
|||||||
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
|
||||||
import { matchesShortcut, type ShortcutLikeEvent } from "@/lib/editor/keyboardShortcuts";
|
import { matchesShortcut, type ShortcutLikeEvent } from "@/lib/editor/keyboardShortcuts";
|
||||||
|
|
||||||
export type TreeNodeRowAction = "open-data" | "open-source" | "open-extension-details" | "open-event-trigger-details" | "open-saved-sql" | "open-object-browser" | "open-object-browser-and-expand" | "toggle" | "none";
|
export type TreeNodeRowAction = "open-data" | "open-source" | "open-extension-details" | "open-event-trigger-details" | "open-saved-sql" | "open-object-browser" | "open-object-browser-and-expand" | "locate-column" | "toggle" | "none";
|
||||||
export type TreeNodeRowDoubleClickAction = "open-data" | "activate-data" | "open-database-browser" | "open-object-browser" | "open-object-browser-and-expand" | "open-source" | "open-extension-details" | "open-event-trigger-details" | "open-saved-sql" | "toggle" | "none";
|
export type TreeNodeRowDoubleClickAction = "open-data" | "activate-data" | "open-database-browser" | "open-object-browser" | "open-object-browser-and-expand" | "open-source" | "open-extension-details" | "open-event-trigger-details" | "open-saved-sql" | "locate-column" | "toggle" | "none";
|
||||||
export type SidebarSelectionCopyAction = "copy-name" | "none";
|
export type SidebarSelectionCopyAction = "copy-name" | "none";
|
||||||
export type SidebarActivation = "single" | "double";
|
export type SidebarActivation = "single" | "double";
|
||||||
|
|
||||||
@@ -140,6 +140,7 @@ export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean, activa
|
|||||||
if (type === "event-trigger") return "open-event-trigger-details";
|
if (type === "event-trigger") return "open-event-trigger-details";
|
||||||
if (savedSqlNodeTypes.has(type)) return "open-saved-sql";
|
if (savedSqlNodeTypes.has(type)) return "open-saved-sql";
|
||||||
if (dataNodeTypes.has(type)) return "open-data";
|
if (dataNodeTypes.has(type)) return "open-data";
|
||||||
|
if (type === "column") return "locate-column";
|
||||||
// PostgreSQL-family custom types: open read-only details (toggle when expandable).
|
// PostgreSQL-family custom types: open read-only details (toggle when expandable).
|
||||||
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
||||||
// Xugu and other databases: expandable package/type nodes toggle their members.
|
// Xugu and other databases: expandable package/type nodes toggle their members.
|
||||||
@@ -172,6 +173,7 @@ export function treeNodeRowDoubleClickAction(type: TreeNodeType, canOpenObjectBr
|
|||||||
if (type === "extension") return "open-extension-details";
|
if (type === "extension") return "open-extension-details";
|
||||||
if (type === "event-trigger") return "open-event-trigger-details";
|
if (type === "event-trigger") return "open-event-trigger-details";
|
||||||
if (dataNodeTypes.has(type)) return "open-data";
|
if (dataNodeTypes.has(type)) return "open-data";
|
||||||
|
if (type === "column") return "locate-column";
|
||||||
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
if (type === "type" && customTypeCapabilities(dbType).details) return canExpand ? "toggle" : "none";
|
||||||
if (sourceNodeTypes.has(type) && canOpenTreeNodeSource(type, dbType)) return "open-source";
|
if (sourceNodeTypes.has(type) && canOpenTreeNodeSource(type, dbType)) return "open-source";
|
||||||
if (savedSqlNodeTypes.has(type)) return "open-saved-sql";
|
if (savedSqlNodeTypes.has(type)) return "open-saved-sql";
|
||||||
|
|||||||
@@ -270,4 +270,30 @@ describe("queryStore switchTab", () => {
|
|||||||
scrollLeft: 0,
|
scrollLeft: 0,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("stores and increments grid column reveal request", () => {
|
||||||
|
const queryStore = useQueryStore();
|
||||||
|
const tabId = queryStore.createTab("pg-1", "app", "users", "data", "public");
|
||||||
|
|
||||||
|
queryStore.requestGridRevealColumn(tabId, "email");
|
||||||
|
const tab = queryStore.tabs.find((candidate) => candidate.id === tabId);
|
||||||
|
expect(tab?.gridRevealColumnRequest).toEqual({ id: expect.any(Number), columnName: "email" });
|
||||||
|
const firstId = tab?.gridRevealColumnRequest?.id;
|
||||||
|
|
||||||
|
queryStore.requestGridRevealColumn(tabId, "email");
|
||||||
|
expect(tab?.gridRevealColumnRequest?.id).toBeGreaterThan(firstId!);
|
||||||
|
expect(tab?.gridRevealColumnRequest?.columnName).toBe("email");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reveals column in data grid and switches to that tab", () => {
|
||||||
|
const queryStore = useQueryStore();
|
||||||
|
const tab1Id = queryStore.createTab("pg-1", "app", "users", "data", "public");
|
||||||
|
const tab2Id = queryStore.createTab("pg-1", "app", "orders", "data", "public");
|
||||||
|
queryStore.activeTabId = tab2Id;
|
||||||
|
|
||||||
|
queryStore.revealColumnInDataGrid(tab1Id, "created_at");
|
||||||
|
expect(queryStore.activeTabId).toBe(tab1Id);
|
||||||
|
const tab1 = queryStore.tabs.find((candidate) => candidate.id === tab1Id);
|
||||||
|
expect(tab1?.gridRevealColumnRequest).toEqual({ id: expect.any(Number), columnName: "created_at" });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -7401,6 +7401,7 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
connectionId,
|
connectionId,
|
||||||
database,
|
database,
|
||||||
schema,
|
schema,
|
||||||
|
catalog: catalog || targetNode.catalog,
|
||||||
tableName: table,
|
tableName: table,
|
||||||
meta: col,
|
meta: col,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -945,6 +945,8 @@ let persistTimer: ReturnType<typeof setTimeout> | null = null;
|
|||||||
let persistGeneration = 0;
|
let persistGeneration = 0;
|
||||||
/** Monotonic id for content-search jump requests; lets repeated clicks on the same result re-trigger the editor reveal. */
|
/** Monotonic id for content-search jump requests; lets repeated clicks on the same result re-trigger the editor reveal. */
|
||||||
let contentRevealSeq = 0;
|
let contentRevealSeq = 0;
|
||||||
|
/** Monotonic id for data-grid column reveal requests; lets repeated clicks on the same column re-trigger grid scroll and highlight. */
|
||||||
|
let gridRevealColumnSeq = 0;
|
||||||
|
|
||||||
function saveTabs(tabs: QueryTab[], activeTabId: string | null, workspace?: EditorWorkspacePersistState): Promise<void> {
|
function saveTabs(tabs: QueryTab[], activeTabId: string | null, workspace?: EditorWorkspacePersistState): Promise<void> {
|
||||||
if (isDetachedWindow()) return Promise.resolve();
|
if (isDetachedWindow()) return Promise.resolve();
|
||||||
@@ -3416,6 +3418,17 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
if (typeof window !== "undefined") window.dispatchEvent(new Event(QUERY_SURFACE_ACTIVATION_EVENT));
|
if (typeof window !== "undefined") window.dispatchEvent(new Event(QUERY_SURFACE_ACTIVATION_EVENT));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestGridRevealColumn(tabId: string, columnName: string) {
|
||||||
|
const tab = tabs.value.find((t) => t.id === tabId);
|
||||||
|
if (!tab) return;
|
||||||
|
tab.gridRevealColumnRequest = { id: ++gridRevealColumnSeq, columnName };
|
||||||
|
}
|
||||||
|
|
||||||
|
function revealColumnInDataGrid(tabId: string, columnName: string) {
|
||||||
|
requestGridRevealColumn(tabId, columnName);
|
||||||
|
switchTab(tabId);
|
||||||
|
}
|
||||||
|
|
||||||
function openUserAdmin(connectionId: string) {
|
function openUserAdmin(connectionId: string) {
|
||||||
const existing = tabs.value.find((tab) => tab.mode === "users" && tab.connectionId === connectionId);
|
const existing = tabs.value.find((tab) => tab.mode === "users" && tab.connectionId === connectionId);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
@@ -9587,6 +9600,8 @@ export const useQueryStore = defineStore("query", () => {
|
|||||||
moveTabToGroup,
|
moveTabToGroup,
|
||||||
unsplitTab,
|
unsplitTab,
|
||||||
switchTab,
|
switchTab,
|
||||||
|
requestGridRevealColumn,
|
||||||
|
revealColumnInDataGrid,
|
||||||
closeTab,
|
closeTab,
|
||||||
forceClosePendingTab,
|
forceClosePendingTab,
|
||||||
forceCloseAllPendingTabs,
|
forceCloseAllPendingTabs,
|
||||||
|
|||||||
@@ -2057,6 +2057,11 @@ export interface QueryTab {
|
|||||||
line: number;
|
line: number;
|
||||||
column?: number;
|
column?: number;
|
||||||
};
|
};
|
||||||
|
/** Ephemeral request to reveal/scroll to a specific column in the data grid. */
|
||||||
|
gridRevealColumnRequest?: {
|
||||||
|
id: number;
|
||||||
|
columnName: string;
|
||||||
|
};
|
||||||
executionId?: string;
|
executionId?: string;
|
||||||
/** Ephemeral result run targeted by the current execution; null means a new run is being produced. */
|
/** Ephemeral result run targeted by the current execution; null means a new run is being produced. */
|
||||||
executingResultRunId?: string | null;
|
executingResultRunId?: string | null;
|
||||||
|
|||||||
+6
-1
@@ -99,10 +99,15 @@ test("double-click follow-up clicks do not repeat side-effecting row actions", (
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("plain metadata leaf rows do nothing on row clicks", () => {
|
test("plain metadata leaf rows do nothing on row clicks", () => {
|
||||||
assert.equal(treeNodeRowAction("column", false), "none");
|
|
||||||
assert.equal(treeNodeRowAction("index", false), "none");
|
assert.equal(treeNodeRowAction("index", false), "none");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("column rows locate column in data grid", () => {
|
||||||
|
assert.equal(treeNodeRowAction("column", false, "single"), "locate-column");
|
||||||
|
assert.equal(treeNodeRowAction("column", false, "double"), "none");
|
||||||
|
assert.equal(treeNodeRowDoubleClickAction("column", false, "double"), "locate-column");
|
||||||
|
});
|
||||||
|
|
||||||
test("maps source-capable sidebar nodes to object source kinds", () => {
|
test("maps source-capable sidebar nodes to object source kinds", () => {
|
||||||
assert.equal(objectSourceKindForTreeNode("view"), "VIEW");
|
assert.equal(objectSourceKindForTreeNode("view"), "VIEW");
|
||||||
assert.equal(objectSourceKindForTreeNode("procedure"), "PROCEDURE");
|
assert.equal(objectSourceKindForTreeNode("procedure"), "PROCEDURE");
|
||||||
|
|||||||
Reference in new issue
Block a user