-
Notifications
You must be signed in to change notification settings - Fork 60
Edit database connections #8
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
base: master
Are you sure you want to change the base?
Edit database connections #8
Conversation
…the user select af connection from a quick pick list
…hed correctly when retrieveing the value for editing
…et the user pick a connection from a quick pick menu
src/common/utility.ts
Outdated
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); |
There was a problem hiding this comment.
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
src/model/connectionNode.ts
Outdated
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 }); |
There was a problem hiding this comment.
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
src/model/connectionNode.ts
Outdated
mysqlTreeDataProvider.refresh(); | ||
} | ||
|
||
public async editConnection(context?: vscode.ExtensionContext, mysqlTreeDataProvider?: MySQLTreeDataProvider) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context?
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mysqlTreeDataProvider?
?
src/common/utility.ts
Outdated
const selectedConnection = connections[selectedConnectionId]; | ||
|
||
if (selectedConnection !== undefined) { | ||
const dummyNode = new ConnectionNode(selectedConnectionId, selectedConnection.host, selectedConnection.user, selectedConnection.password, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
@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", |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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)]; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.