feat(sidebar): refresh data tables on double click
This commit is contained in:
7 files changed
+342
-23
No files matched your search
@@ -107,7 +107,7 @@ import { isCopySidebarSelectionShortcut, isEditSidebarConnectionShortcut, isPast
|
||||
import { formatSqlInsert } from "@/lib/export/exportFormats";
|
||||
import { joinExportedDdls } from "@/lib/export/ddlExport";
|
||||
import { fetchTableDataForExport } from "@/lib/table/tableDataExport";
|
||||
import { canActivateExistingDataTableTab } from "@/lib/tabs/dataTabActivation";
|
||||
import { canActivateExistingDataTableTab, canRefreshDataTableFromSingleActivationDoubleClick, dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";
|
||||
import { buildCreateDatabaseSql, buildDuckDbAttachDatabaseSql, duckDbAttachedDatabaseNameFromPath, supportsCreateDatabaseCharset, uniqueDuckDbAttachedDatabaseName } from "@/lib/database/createDatabaseSql";
|
||||
import {
|
||||
buildCreateSchemaSql,
|
||||
@@ -838,6 +838,9 @@ function runRowClickAction(clickDetail: number) {
|
||||
const action = treeNodeRowAction(node.type, canExpand.value, settingsStore.editorSettings.sidebarActivation);
|
||||
if (!shouldRunTreeNodeRowAction(action, clickDetail)) return;
|
||||
if (action === "open-data") {
|
||||
if (node.type === "table") {
|
||||
singleActivationDoubleClickRefreshAllowed = canRefreshDataTableFromSingleActivationDoubleClick(findExistingSameTableDataTab());
|
||||
}
|
||||
scheduleOpenData(node);
|
||||
} else if (isDocumentBrowserTreeNode(node.type)) {
|
||||
openMongoTreeData(node);
|
||||
@@ -848,6 +851,8 @@ function runRowClickAction(clickDetail: number) {
|
||||
}
|
||||
}
|
||||
|
||||
let singleActivationDoubleClickRefreshAllowed = false;
|
||||
|
||||
function refreshActiveKvBrowserAfterOpen(mode: "etcd" | "zookeeper", connectionId: string) {
|
||||
void nextTick(() => {
|
||||
window.dispatchEvent(new CustomEvent("dbx-refresh-active-kv-browser", { detail: { mode, connectionId } }));
|
||||
@@ -972,6 +977,7 @@ function toggleConnectionMultiSelection(event: MouseEvent) {
|
||||
}
|
||||
|
||||
function onClick(event: MouseEvent) {
|
||||
if (props.node.type === "table" && event.detail <= 1) singleActivationDoubleClickRefreshAllowed = false;
|
||||
if (suppressNextTableReferenceClick) {
|
||||
suppressNextTableReferenceClick = false;
|
||||
event.preventDefault();
|
||||
@@ -1193,6 +1199,8 @@ function onDoubleClick() {
|
||||
if (!props.node.isExpanded) void toggle();
|
||||
} else if (action === "open-data") {
|
||||
openDataImmediately(props.node);
|
||||
} else if (action === "refresh-data") {
|
||||
void refreshData();
|
||||
} else if (action === "open-source") {
|
||||
openObjectSourceDialog(false);
|
||||
} else if (action === "open-saved-sql") {
|
||||
@@ -1204,6 +1212,34 @@ function onDoubleClick() {
|
||||
}
|
||||
}
|
||||
|
||||
async function refreshData() {
|
||||
const node = props.node;
|
||||
if (node.type !== "table" || !hasNodeDatabaseContext(node)) return;
|
||||
const singleActivationRefreshAllowed = singleActivationDoubleClickRefreshAllowed;
|
||||
singleActivationDoubleClickRefreshAllowed = false;
|
||||
const activation = settingsStore.editorSettings.sidebarActivation;
|
||||
if (activation === "single" && !singleActivationRefreshAllowed) return;
|
||||
const existingSameTableTab = findExistingSameTableDataTab();
|
||||
const action = dataTableDoubleClickAction(existingSameTableTab, activation, singleActivationRefreshAllowed);
|
||||
if (action === "none") return;
|
||||
if (action === "open") {
|
||||
openDataImmediately(node);
|
||||
return;
|
||||
}
|
||||
if (!existingSameTableTab) return;
|
||||
queryStore.switchTab(existingSameTableTab.id);
|
||||
if (action === "activate") return;
|
||||
await queryStore.refreshDataTab(existingSameTableTab.id);
|
||||
}
|
||||
|
||||
function findExistingSameTableDataTab() {
|
||||
const node = props.node;
|
||||
if (node.type !== "table" || !hasNodeDatabaseContext(node)) return undefined;
|
||||
const config = connectionStore.getConfig(node.connectionId);
|
||||
const tableSchema = connectionObjectTreeNodeSchema(config, node.database, node.schema);
|
||||
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 openMongoTreeData(node: TreeNode) {
|
||||
if (!node.connectionId || !node.database) return;
|
||||
if (node.type === "mongo-gridfs") {
|
||||
|
||||
Reference in new issue
Block a user