@@ -21,10 +21,15 @@ import type { StorageController } from './storage';
2121import type { StatusView } from './views' ;
2222import type TelemetryService from './telemetry/telemetryService' ;
2323import { openLink } from './utils/linkHelper' ;
24- import type { LoadedConnection } from './storage/connectionStorage' ;
24+ import type {
25+ ConnectionSource ,
26+ LoadedConnection ,
27+ } from './storage/connectionStorage' ;
2528import { ConnectionStorage } from './storage/connectionStorage' ;
2629import LINKS from './utils/links' ;
2730import { isAtlasStream } from 'mongodb-build-info' ;
31+ import { DocumentSource } from './documentSource' ;
32+ import type { ConnectionTreeItem } from './explorer' ;
2833
2934// eslint-disable-next-line @typescript-eslint/no-var-requires
3035const packageJSON = require ( '../package.json' ) ;
@@ -161,6 +166,46 @@ export default class ConnectionController {
161166 } ) ;
162167 }
163168
169+ async openPresetConnectionsSettings (
170+ originTreeItem : ConnectionTreeItem | undefined
171+ ) : Promise < void > {
172+ this . _telemetryService . trackPresetConnectionEdited ( {
173+ source : DocumentSource . DOCUMENT_SOURCE_TREEVIEW ,
174+ source_details : originTreeItem ? 'tree_item' : 'header' ,
175+ } ) ;
176+ let source : ConnectionSource | undefined = originTreeItem ?. source ;
177+ if ( ! source ) {
178+ const mdbConfiguration = vscode . workspace . getConfiguration ( 'mdb' ) ;
179+
180+ const presetConnections = mdbConfiguration ?. inspect (
181+ 'presetSavedConnections'
182+ ) ;
183+
184+ if ( presetConnections ?. workspaceValue ) {
185+ source = 'workspaceSettings' ;
186+ } else if ( presetConnections ?. globalValue ) {
187+ source = 'globalSettings' ;
188+ } else {
189+ // If no preset settings exist in workspace and global scope,
190+ // set a default one inside the workspace and open it.
191+ source = 'workspaceSettings' ;
192+ await mdbConfiguration . update ( 'presetSavedConnections' , [
193+ {
194+ name : 'Preset Database' ,
195+ connectionString : 'mongodb://localhost:27017' ,
196+ } ,
197+ ] ) ;
198+ }
199+ }
200+ if ( originTreeItem ?. source === 'globalSettings' ) {
201+ await vscode . commands . executeCommand ( 'workbench.action.openSettingsJson' ) ;
202+ } else {
203+ await vscode . commands . executeCommand (
204+ 'workbench.action.openWorkspaceSettingsFile'
205+ ) ;
206+ }
207+ }
208+
164209 async loadSavedConnections ( ) : Promise < void > {
165210 this . _connections = Object . create ( null ) ;
166211
0 commit comments