-
Notifications
You must be signed in to change notification settings - Fork 90
feat(tree-explorer): add ability to set preset connections in settings.json VSCODE-665 #909
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
Conversation
package.json
Outdated
| "group": "3@2" | ||
| }, | ||
| { | ||
| "command": "mdb.openWorkspaceSettingsFile", |
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.
I think it'd be nice to include ability to quickly open workspace settings here when the item is preset (piggybacking on an existing VSCode action).
We can't easily detect where this preset comes from (i.e. it could also come from user settings) so we could also include a shortcut to open user settings, but maybe we don't want to encourage that and assume they know what they're doing by that point?
If someone that defined this in their user settings (as opposed to workspace) and clicks the Open Workspace Settings, it'd open or create a .vscode/settings.json file in the workspace, and setting things there would override user settings, which seems reasonable.
src/explorer/connectionTreeItem.ts
Outdated
| !connectionController.isConnecting(); | ||
|
|
||
| this.contextValue = `${isConnected ? 'connected' : 'disconnected'}${ | ||
| isMutable ? '' : 'Immutable' |
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.
naming here I'm not so sure about. Immutable could also be "Preset", I just thought of making this more generic. The idea is that it's not a connection that can be removed/edited/etc.
|
It looks like we use 2 different setting.json files (see the flow described below). Also, have some thoughts about UX for this feature. Let me know what you think!
|
| void this._connectionController.loadSavedConnections(); | ||
| } | ||
| }); | ||
| this._context.subscriptions.push(subscription); |
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 I understand correctly, if I add this subscription to the context, it'll auto-dispose right so no further manual handling needed? @alenakhineika
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 is how I understand this as well.
Now when one clicks edit preset connections, we'll automatically redirect to the correct settings.json (workspace or global).
915a69d to
181f801
Compare
|
@alenakhineika the new changes with reactivity of settings and automatically deriving where the |
…eader Running from header will automatically determine which scope to open and create a preset to edit if none are defined
181f801 to
0128835
Compare
…and workspace settings
0850375 to
ef9fa97
Compare
nirinchev
left a comment
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.
Looks good - I mostly have style comments and a few minor suggestions.
.vscode/settings.json
Outdated
| // Turn off tsc task auto detection since we have the necessary tasks as npm scripts | ||
| "typescript.tsc.autoDetect": "off" | ||
| "typescript.tsc.autoDetect": "off", | ||
| "mdb.presetSavedConnections": [ |
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.
I think preset and saved are a bit redundant here. Probably best to shorten it to presetConnections.
src/connectionController.ts
Outdated
| // If no preset settings exist in workspace and global scope, | ||
| // set a default one inside the workspace and open it. | ||
| source = 'workspaceSettings'; | ||
| await mdbConfiguration.update('presetSavedConnections', [ |
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.
Can we extract this string literal to a constant somewhere?
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.
I wanted to but we don't have much precedent of this the way with do with EXTENSION_COMMANDS where we also keep the mdb. suffix which is a bit awkward
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.
I could create a follow-up PR to migrate all our settings into EXTENSION_SETTINGS constants for example. or introduce it here and move them later
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.
I think we can introduce it here for this particular case and create a follow-up PR to move others in there.
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.
Was meant to follow up on this but ended up losing this discussion; didn't seem to have a quick obvious location to introduce it here so will create a follow-up PR with everything instead
| } | ||
|
|
||
| async loadSavedConnections(): Promise<void> { | ||
| this._connections = Object.create(null); |
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 this fixing a bug where deleted saved connections would show up because they're not overridden in the for loop? Couldn't spot a test that verifies the behavior before was incorrect - am I just blind or should we add one?
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.
Yeah, this hasn't been an issue because we'd only run loadSavedConnections at startup / when this._connections would be not yet defined. Now with the reloading on save this becomes more obvious. I'll add a test.
| connected = 'connectedConnectionTreeItem', | ||
| } | ||
| export type ConnectionItemContextValue = `${'disconnected' | 'connected'}${ | ||
| | '' |
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.
[extreme nit] The leading | makes the formatting really awkard - is it even worse without it?
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 gets automatically added by the linter 🤷
src/storage/connectionStorage.ts
Outdated
| ]; | ||
|
|
||
| return combinedPresetSavedConnections.map((presetConnection) => ({ | ||
| id: uuidv4(), |
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.
Why do we generate different ids here as opposed to using the name? Is it because we want to allow multiple connections with the same name as presets?
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.
That may be a good enough reason, It is also because storage saved connections use UUIDs and we end up combining the two, so was kind of thinking of it as a stricter way to stick to a "type" where IDs are arbitrary and not tied to the connection's contents.
| const connection = loadedConnections[i]; | ||
| const expected = expectedConnectionValues[i]; | ||
| expect(connection.name).equals(expected.name); | ||
| expect(connection.connectionOptions.connectionString).contains( |
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.
q: why are we checking for contains here rather than equals?
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.
ah actually it was because the connectionString ends up losing the trailing /, will still adjust it to be stricter and more defined
ef9fa97 to
bf39230
Compare
alenakhineika
left a comment
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.
Looks good! I created a ticket to address a remaining issue with collapsing an active connection VSCODE-671.
|
@alenakhineika I see the issue now, 63c719d fixes it. Going to merge and we can verify again during release. |
Adds option to specify
mdb.presetConfigurationsinsidesettings.json(likely for a workspace) which will load a preset list of connections based on that. This setting defines preset connections. It can be used to share connection configurations in a workspace or global scope.It is important that users do not store sensitive credentials here as it is just saved as a plaintext file and is easily accessible. The common usecase where this setting is useful is if for example some project has a local mongodb instance associated with it for tests and the repository owner wants to share different preset connection settings for when one loads this.
The setting format is an array of preset connections defined with this kind of schema:
Users can discover this by clicking the ... in the Tree View next to the Plus icon and selecting Edit Preset Connections... which will open the relevant file as it is detected (or create a preset connection in the workspace to modify if one doesn't exist already).
Preset connections can only be edited through the settings.json file they originate from which can also be accessed when right clicking the a preset connection and choosing "Edit Preset Connections..."
Motivation and Context
Addresses #368.