mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-30 08:20:33 +00:00
fix(sidebar): require double click to open object browser
This commit is contained in:
@@ -80,7 +80,7 @@ import {
|
||||
isSchemaAware,
|
||||
usesFetchFirst,
|
||||
} from "@/lib/databaseCapabilities";
|
||||
import { treeNodeRowAction } from "@/lib/treeNodeClick";
|
||||
import { treeNodeRowAction, treeNodeRowDoubleClickAction } from "@/lib/treeNodeClick";
|
||||
import { formatCsv, formatJson, formatSqlInsert } from "@/lib/exportFormats";
|
||||
import { hexToRgba } from "@/lib/color";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
@@ -279,14 +279,8 @@ async function toggle() {
|
||||
}
|
||||
}
|
||||
|
||||
function onClick() {
|
||||
function runRowClickAction() {
|
||||
const node = props.node;
|
||||
if (canOpenObjectBrowser.value) {
|
||||
const shouldOpenObjectBrowser = !canExpand.value || !node.isExpanded;
|
||||
if (canExpand.value) void toggle();
|
||||
if (shouldOpenObjectBrowser) void openObjectBrowser();
|
||||
return;
|
||||
}
|
||||
if (node.type === "object-browser") {
|
||||
void openObjectBrowser();
|
||||
return;
|
||||
@@ -301,6 +295,18 @@ function onClick() {
|
||||
}
|
||||
}
|
||||
|
||||
function onClick(event: MouseEvent) {
|
||||
if (event.detail > 1) return;
|
||||
runRowClickAction();
|
||||
}
|
||||
|
||||
function onDoubleClick() {
|
||||
const action = treeNodeRowDoubleClickAction(props.node.type, canOpenObjectBrowser.value);
|
||||
if (action === "open-object-browser") {
|
||||
void openObjectBrowser();
|
||||
}
|
||||
}
|
||||
|
||||
async function openObjectBrowser() {
|
||||
const node = props.node;
|
||||
if (!node.connectionId) return;
|
||||
@@ -1380,6 +1386,7 @@ const isDragging = computed(() => dragState.active && dragState.draggedId === pr
|
||||
}"
|
||||
:style="rowStyle"
|
||||
@click="onClick"
|
||||
@dblclick="onDoubleClick"
|
||||
@mousedown="isDraggable ? startDrag($event, node.id, node.type) : undefined"
|
||||
@mousemove="isDropTarget ? updateTarget($event, node.id, node.type) : undefined"
|
||||
@mouseleave="clearTarget(node.id)"
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import type { TreeNodeType } from "@/types/database";
|
||||
|
||||
export type TreeNodeRowAction = "open-data" | "toggle" | "none";
|
||||
export type TreeNodeRowDoubleClickAction = "open-object-browser" | "none";
|
||||
|
||||
const dataNodeTypes = new Set<TreeNodeType>(["table", "view"]);
|
||||
const toggleLeafNodeTypes = new Set<TreeNodeType>(["redis-db", "mongo-collection"]);
|
||||
const objectBrowserNodeTypes = new Set<TreeNodeType>(["database", "schema", "object-browser"]);
|
||||
|
||||
export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean): TreeNodeRowAction {
|
||||
if (dataNodeTypes.has(type)) return "open-data";
|
||||
@@ -11,3 +13,11 @@ export function treeNodeRowAction(type: TreeNodeType, canExpand: boolean): TreeN
|
||||
if (canExpand) return "toggle";
|
||||
return "none";
|
||||
}
|
||||
|
||||
export function treeNodeRowDoubleClickAction(
|
||||
type: TreeNodeType,
|
||||
canOpenObjectBrowser: boolean,
|
||||
): TreeNodeRowDoubleClickAction {
|
||||
if (canOpenObjectBrowser && objectBrowserNodeTypes.has(type)) return "open-object-browser";
|
||||
return "none";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user