Skip to content

Conversation

jbpoulsen
Copy link
Contributor

You can now edit a database connection, regardless if you right click it in the Tree or run the command "Edit Connection". If you run the command from the Command Palette, the user will have to select which MySQL connection he wants to edit. The same has been added for the "Delete Connection" command.

connectionNode.editConnection(context, mysqlTreeDataProvider);
} else {
// No connection has been selected, let the user pick one
const connections = context.globalState.get<{ [key: string]: IConnection }>(Constants.GlobalStateMySQLConectionsKey);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pick connection logic is similar in deleteConnection and editConnection. Please merge them

public async editConnection(context?: vscode.ExtensionContext, mysqlTreeDataProvider?: MySQLTreeDataProvider) {
AppInsightsClient.sendEvent("editConncetion");

const host = await vscode.window.showInputBox({ prompt: "The hostname of the database", placeHolder: "host", ignoreFocusOut: true, value: this.host });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is similar to addConnection. Please meege them

mysqlTreeDataProvider.refresh();
}

public async editConnection(context?: vscode.ExtensionContext, mysqlTreeDataProvider?: MySQLTreeDataProvider) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

context??

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mysqlTreeDataProvider??

const selectedConnection = connections[selectedConnectionId];

if (selectedConnection !== undefined) {
const dummyNode = new ConnectionNode(selectedConnectionId, selectedConnection.host, selectedConnection.user, selectedConnection.password,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it good practice to do this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe not.. but should we move the edit/delete methods away from the connectionNode and onto the connection object instead?
We could change the IConnection to an abstract class instead, and implement the methods in here instead?

@jbpoulsen
Copy link
Contributor Author

@formulahendry Can you look into merging the changes? I also added the ability to "Drop table" from the Tablenode

"group": "mysql@1"
},
{
"command": "mysql.editConnection",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put this before mysql.deleteConnection

return;
}

AppInsightsClient.sendEvent("drop table");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dropTable

};
Global.activeConnection = connection;

Utility.runQuery(sql, connection);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about refreshing the table list after deletion is successful?

Copy link
Contributor Author

@jbpoulsen jbpoulsen Dec 22, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do i refresh the databaseNode from inside the tableNode class? I want to call:

mysqlTreeDataProvider.refresh(databaseNode);

How can i get the "parent" databaseNode for a tableNode?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could pass databaseNode to constructor of tableNode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright ill look into that

};
const editConnection = await Utility.createConnectionFromInput(context, copyFrom);

if (editConnection !== undefined) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This logic is similar to addConnection. Please help merge them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merge them into a addOrEditConnection method?
Should the metod(s) be placed on the connectionNode or the mysqlTreeDataProvider class?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could wrap these similar code snippet into a method into https://github.com/formulahendry/vscode-mysql/blob/master/src/common/utility.ts

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(We still keep editConnection in connectionNode and addConnection in mysqlTreeDataProvider, and call shared method in utility)

}
}

await vscode.window.showQuickPick(items).then(async (selection) => {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use: const selection = await vscode.window.showQuickPick(items)

await vscode.window.showQuickPick(items).then(async (selection) => {
// the user canceled the selection
if (!selection) {
return selectedConnection;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be just return

return selectedConnection;
}

const selectedConnectionId = Object.keys(connections)[items.indexOf(selection)];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there are two connections have the same host and user?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would still get the correct selection from the pick menu.. but you wont be able to differ from the two when the menu is shown.. how would you enable anyone to see the difference between two connections with the same host and user? showing the internal id of the connection wont be to much use for the user.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we could still get the correct selection from the pick menu, then it will be OK. No extra change needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants