Skip to content

VSCODE-66: Add connection renaming #34

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

Merged
merged 10 commits into from
Mar 16, 2020
Merged

Conversation

Anemy
Copy link
Member

@Anemy Anemy commented Mar 12, 2020

https://jira.mongodb.org/browse/VSCODE-66

This PR adds the ability to rename connections. It also improves our connection controller's saved connection implementation so we don't require a dns fetch to add a connection and adding two connections with the same driver url aren't blocked anymore. It also makes it so when a user copies a connection string from a connection in the connection tree view we no longer attach the appname parameter to the uri.

@alenakhineika 's suggestion we also now expand the connections tree element if it's collapsed when a connection is added.

When a connection is first added, its name is its derived instance id.

Here's the new type for connections in the connection controller:

export type SavedConnection = {
  id: string; // uuidv4
  name: string; // Possibly user given name, not unique.
  driverUrl: string;
  storageLocation: StorageScope;
};

Screenshots


renaming a connection

@@ -98,7 +99,10 @@ export default class ConnectionTreeItem extends vscode.TreeItem
}

return new Promise((resolve, reject) => {
const dataService = this._connectionController.getActiveConnection();
const dataService = this._connectionController.getActiveDataService();
Copy link
Contributor

Choose a reason for hiding this comment

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

So there is no more getActiveConnection only getActiveDataService? How can I get the active connection now to read all connection properties from it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Which connection properties are you looking for? Maybe I need to keep storing the connection model as well (this pr currently removes it and just keeps the basic connection and data service). We're storing the driver url on the SavedConnection now.

Copy link
Contributor

Choose a reason for hiding this comment

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

  1. For example, I am connected, and I want to know which host and port I am currently connected to. Or which database is the default for the current connection. How can I do it?

  2. I want to check if I am currently connected or not. Is it the right way to do it?

const dataservice = this._connectionController.getActiveDataService();
if (dataservice === null) {
  vscode.window.showErrorMessage(
    `Unable to list documents: no longer connected to ${connectionId}`
  );
}

In Compass we use DataService more like API to the driver, when ConnectionModel is more about connection properties. If the getActiveDataService returns the connection model, then maybe it would be more descriptive to call it as before getActiveConnection.

Or maybe I just got something wrong, pls help to understand :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah k - I'll add a call for getActiveConnectionModel for connection details. Correct on checking data service, I'll add a helper for that in connection controller so we can just get a boolean. Dataservice is like the api for the driver yup

// When the connections change, like a connection is added or removed,
// we want to open the connections dropdown if it's collapsed.
if (!this.isExpanded) {
this.needsToRefreshExpansionState = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thx for adding it! ✨

@@ -18,6 +19,13 @@ export enum DefaultSavingLocations {
'Session Only' = 'Session Only'
}

export type SavedConnection = {
id: string; // uuidv4
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@alenakhineika
Copy link
Contributor

Like how you did renaming! And I believe this is very nice to be able to save connections with the same URI. It is better to delete redundant connections later than throw error messages which might be confusing for users. Great job! 🚀

@Anemy
Copy link
Member Author

Anemy commented Mar 13, 2020

Ah one more thing I noticed I should add before we merge this pr is we want to show the prompt for where to save the connection right after the user inputs the connection string, right now it prompts after the connection is established.

@Anemy Anemy force-pushed the VSCODE-66/add-connection-renaming branch from f303346 to 8917749 Compare March 16, 2020 12:30
@Anemy
Copy link
Member Author

Anemy commented Mar 16, 2020

@alenakhineika Added two functions to ConnectionController that'll probably be helpful - getActiveConnectionModel and isCurrentlyConnected. Also updated adding connections to prompt right when the connection is added instead of after the connection is established.

I've been noticing the tests sometimes crash on mac with this error:
Screen Shot 2020-03-16 at 1 26 12 PM
Looking into it... not sure if it's from this pr or if we should wait to merge these changes on fixing it. Ah - looks like it's something related to data service and chai: mongodb-js/data-service#166 So we can go ahead and merge this if it's good to go.

@Anemy Anemy merged commit b1f7d90 into master Mar 16, 2020
@Anemy Anemy deleted the VSCODE-66/add-connection-renaming branch March 16, 2020 14:37
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