Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

535 switching between same named databases doesnt change the tables #639

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 56 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -357,6 +357,58 @@ export async function activate(context: vscode.ExtensionContext) {
}
};

const queryEditorDblClick = async (
node: TableNode,
reloadFull = false
): Promise<void> => {
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`,
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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);
}
}
);
Expand All @@ -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);
}
}
);
Expand Down
2 changes: 1 addition & 1 deletion src/treeview/CustomViewProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class CustomViewProvider extends TablesListProvider {
data.tableType,
data.connectionName,
data.connectionLabel,
TableNodeSourceEnum.Favorites
TableNodeSourceEnum.Custom
),
data.name,
data.customViewParams
Expand Down
1 change: 1 addition & 0 deletions src/treeview/TableNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { INode } from './INode';
export enum TableNodeSourceEnum {
Tables = 'tables',
Favorites = 'favorites',
Custom = 'custom',
}

export class TableNode implements INode {
Expand Down
23 changes: 14 additions & 9 deletions src/view/app/Query/query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
}
};

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -472,10 +477,9 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) {
function handleCopy({ sourceRow, sourceColumnKey }: CopyEvent<any>): void {
if (window.isSecureContext) {
navigator.clipboard.writeText(sourceRow[sourceColumnKey]);
}
}
}


const getCellHeight = () => {
if (configuration.gridTextSize === 'Large') {
return 40;
Expand Down Expand Up @@ -535,11 +539,12 @@ function QueryForm({ tableData, tableName, isReadOnly }: IConfigProps) {
readRow={readRow}
isReadOnly={isReadOnly}
/>
{selectedColumns.length === 0 &&
<p style={{ textAlign: 'center', marginTop: '0px' }}>
No Fields are selected from the tab &quot;Fields Explorer&quot;...
</p>
}
{selectedColumns.length === 0 && (
<p style={{ textAlign: 'center', marginTop: '0px' }}>
No Fields are selected from the tab &quot;Fields
Explorer&quot;...
</p>
)}
<QueryFormTable
queryGridRef={queryGridRef}
selected={selected}
Expand Down
4 changes: 3 additions & 1 deletion src/webview/QueryEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ export class QueryEditor {
case TableNodeSourceEnum.Favorites:
config = this.favoritesProvider.config;
break;
case TableNodeSourceEnum.Custom:
config = this.customViewProvider.config;
break;
default:
return;
}

if (tableNode instanceof CustomViewNode) {
config = this.customViewProvider.config;
this.customViewData = tableNode.customViewParams;
}

Expand Down