diff --git a/src/extension.ts b/src/extension.ts index aa313fa4..2cc2539d 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -7,7 +7,7 @@ import { DbConnectionNode } from './treeview/DbConnectionNode'; import { FieldsViewProvider } from './webview/FieldsViewProvider'; import { IndexesViewProvider } from './webview/IndexesViewProvider'; import { GroupListProvider } from './treeview/GroupListProvider'; -import { TableNode } from './treeview/TableNode'; +import { TableNode, TableNodeSourceEnum } from './treeview/TableNode'; import { TablesListProvider } from './treeview/TablesListProvider'; import { DbConnectionUpdater } from './treeview/DbConnectionUpdater'; import { IPort, IConfig } from './view/app/model'; @@ -357,6 +357,58 @@ export async function activate(context: vscode.ExtensionContext) { } }; + const queryEditorDblClick = async ( + node: TableNode, + reloadFull = false + ): Promise => { + let key; + let cachedQueryEditor; + let nodeList; + + switch (node.source) { + case TableNodeSourceEnum.Tables: + nodeList = tablesListProvider.tableNodes; + break; + case TableNodeSourceEnum.Favorites: + nodeList = await favoritesProvider.getChildren(undefined); + break; + case TableNodeSourceEnum.Custom: + nodeList = await customViewsProvider.getChildren(undefined); + break; + default: + nodeList = tablesListProvider.tableNodes; + } + + const newNode = nodeList.find( + (correctNode) => node.tableName === correctNode.tableName + ); + + if (newNode) { + node = newNode; + key = node.getFullName(true) ?? ''; + cachedQueryEditor = queryEditorCache.getQueryEditor(key); + } + + if (!cachedQueryEditor) { + switch (node.source) { + case TableNodeSourceEnum.Tables: + tablesListProvider.selectDbConfig(node); + tablesListProvider.displayData(node, false); + break; + case TableNodeSourceEnum.Favorites: + favoritesProvider.selectDbConfig(node); + favoritesProvider.displayData(node, false); + break; + case TableNodeSourceEnum.Custom: + customViewsProvider.selectDbConfig(node); + customViewsProvider.displayData(node, false); + break; + } + } + + loadQueryEditor(node, reloadFull); + }; + context.subscriptions.push( vscode.commands.registerCommand( `${Constants.globalExtensionKey}.saveCustomView`, @@ -569,7 +621,7 @@ export async function activate(context: vscode.ExtensionContext) { customViewsProvider.countClick(); if (customViewsProvider.tableClicked.count === 2) { - loadQueryEditor(customViewsProvider.node); + queryEditorDblClick(customViewsProvider.node); loadCustomView(customViewsProvider.node); } } @@ -584,7 +636,7 @@ export async function activate(context: vscode.ExtensionContext) { favoritesProvider.countClick(); if (favoritesProvider.tableClicked.count === 2) { - loadQueryEditor(favoritesProvider.node, true); + queryEditorDblClick(favoritesProvider.node, true); } } ); @@ -598,7 +650,7 @@ export async function activate(context: vscode.ExtensionContext) { tablesListProvider.countClick(); if (tablesListProvider.tableClicked.count === 2) { - loadQueryEditor(tablesListProvider.node, true); + queryEditorDblClick(tablesListProvider.node, true); } } ); diff --git a/src/treeview/CustomViewProvider.ts b/src/treeview/CustomViewProvider.ts index 76d2c025..519406f3 100644 --- a/src/treeview/CustomViewProvider.ts +++ b/src/treeview/CustomViewProvider.ts @@ -115,7 +115,7 @@ export class CustomViewProvider extends TablesListProvider { data.tableType, data.connectionName, data.connectionLabel, - TableNodeSourceEnum.Favorites + TableNodeSourceEnum.Custom ), data.name, data.customViewParams diff --git a/src/treeview/TableNode.ts b/src/treeview/TableNode.ts index 9a944f4a..f6850742 100644 --- a/src/treeview/TableNode.ts +++ b/src/treeview/TableNode.ts @@ -5,6 +5,7 @@ import { INode } from './INode'; export enum TableNodeSourceEnum { Tables = 'tables', Favorites = 'favorites', + Custom = 'custom', } export class TableNode implements INode { diff --git a/src/view/app/Query/query.tsx b/src/view/app/Query/query.tsx index df3ff134..c9d555f6 100644 --- a/src/view/app/Query/query.tsx +++ b/src/view/app/Query/query.tsx @@ -158,7 +158,13 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) { } else { setSelectedRows(new Set()); setOpen(false); - reloadData(loaded + (action === ProcessAction.Insert || action === ProcessAction.Copy ? 1 : 0)); + reloadData( + loaded + + (action === ProcessAction.Insert || + action === ProcessAction.Copy + ? 1 + : 0) + ); } }; @@ -186,7 +192,6 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) { }); setIsDataRetrieved(false); return; - } else if (message.data.columns.length !== columns.length) { const fontSize = +window .getComputedStyle( @@ -472,10 +477,9 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) { function handleCopy({ sourceRow, sourceColumnKey }: CopyEvent): void { if (window.isSecureContext) { navigator.clipboard.writeText(sourceRow[sourceColumnKey]); - } + } } - const getCellHeight = () => { if (configuration.gridTextSize === 'Large') { return 40; @@ -535,11 +539,12 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) { readRow={readRow} isReadOnly={isReadOnly} /> - {selectedColumns.length === 0 && -

- No Fields are selected from the tab "Fields Explorer"... -

- } + {selectedColumns.length === 0 && ( +

+ No Fields are selected from the tab "Fields + Explorer"... +

+ )}