Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@
"command": "mdb.refreshSchema",
"title": "Refresh"
},
{
"command": "mdb.copySchemaFieldName",
"title": "Copy Field Name"
},
{
"command": "mdb.startStreamLanguageServerLogs",
"title": "LSP Inspector: Start Stream LSP Logs"
Expand Down Expand Up @@ -434,6 +438,10 @@
{
"command": "mdb.refreshSchema",
"when": "view == mongoDB && viewItem == schemaTreeItem"
},
{
"command": "mdb.copySchemaFieldName",
"when": "view == mongoDB && viewItem == fieldTreeItem"
}
],
"editor/title": [
Expand Down Expand Up @@ -535,6 +543,10 @@
{
"command": "mdb.runPlayground",
"when": "false"
},
{
"command": "mdb.copySchemaFieldName",
"when": "false"
}
]
},
Expand Down
10 changes: 8 additions & 2 deletions src/explorer/fieldTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export enum FieldType {
regex = 'Regular Expression',
string = 'String',
timestamp = 'Timestamp',
undefined = 'Undefined'
undefined = 'Undefined',
}

export type SchemaFieldType = {
Expand Down Expand Up @@ -120,6 +120,8 @@ export const getIconFileNameForField = (
return null;
};

export const FIELD_TREE_ITEM_CONTEXT_VALUE = 'fieldTreeItem';

export default class FieldTreeItem extends vscode.TreeItem
implements vscode.TreeDataProvider<FieldTreeItem>, TreeItemParent {
// This is a flag which notes that when this tree element is updated,
Expand All @@ -133,7 +135,7 @@ export default class FieldTreeItem extends vscode.TreeItem
field: SchemaFieldType;
fieldName: string;

contextValue = 'fieldTreeItem';
contextValue = FIELD_TREE_ITEM_CONTEXT_VALUE;

isExpanded: boolean;

Expand Down Expand Up @@ -240,6 +242,10 @@ export default class FieldTreeItem extends vscode.TreeItem
return this._childrenCache;
}

getFieldName(): string {
return this.fieldName;
}

get iconPath():
| string
| vscode.Uri
Expand Down
183 changes: 86 additions & 97 deletions src/mdbExtensionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ import TelemetryController from './telemetry/telemetryController';
import { StatusView } from './views';
import { createLogger } from './logging';
import { StorageController } from './storage';
import DatabaseTreeItem from './explorer/databaseTreeItem';
import ConnectionTreeItem from './explorer/connectionTreeItem';
import DatabaseTreeItem from './explorer/databaseTreeItem';
import SchemaTreeItem from './explorer/schemaTreeItem';
import DocumentListTreeItem from './explorer/documentListTreeItem';
import DocumentTreeItem from './explorer/documentTreeItem';
import WebviewController from './views/webviewController';
import DocumentListTreeItem from './explorer/documentListTreeItem';
import FieldTreeItem from './explorer/fieldTreeItem';

const log = createLogger('commands');

Expand Down Expand Up @@ -200,19 +201,15 @@ export default class MDBExtensionController implements vscode.Disposable {
);
this.registerCommand(
'mdb.copyConnectionString',
(element: ConnectionTreeItem) => {
// TODO: Password obfuscation.
async (element: ConnectionTreeItem): Promise<boolean> => {
const connectionString = this._connectionController.getConnectionStringFromConnectionId(
element.connectionId
);

return new Promise((resolve, reject) => {
vscode.env.clipboard.writeText(connectionString).then(() => {
vscode.window.showInformationMessage('Copied to clipboard.');
await vscode.env.clipboard.writeText(connectionString);
vscode.window.showInformationMessage('Copied to clipboard.');

return resolve(true);
}, reject);
});
return true;
}
);
this.registerCommand(
Expand All @@ -232,7 +229,7 @@ export default class MDBExtensionController implements vscode.Disposable {
vscode.window.showErrorMessage(
'Please wait for the connection to finish loading before adding a database.'
);
return Promise.resolve(false);
return false;
}

if (
Expand All @@ -242,72 +239,63 @@ export default class MDBExtensionController implements vscode.Disposable {
vscode.window.showErrorMessage(
'Please connect to this connection before adding a database.'
);
return Promise.resolve(false);
return false;
}

if (this._connectionController.isDisconnecting()) {
vscode.window.showErrorMessage(
'Unable to add database: currently disconnecting.'
);
return Promise.resolve(false);
return false;
}

if (this._connectionController.isConnecting()) {
vscode.window.showErrorMessage(
'Unable to add database: currently connecting.'
);
return Promise.resolve(false);
return false;
}

return new Promise((resolve, reject) => {
element
.onAddDatabaseClicked(this._context)
.then((successfullyAddedDatabase) => {
if (successfullyAddedDatabase) {
vscode.window.showInformationMessage(
'Database and collection successfully created.'
);

// When we successfully added a database & collection, we need
// to update the explorer view.
this._explorerController.refresh();
}
resolve(successfullyAddedDatabase);
}, reject);
});
const successfullyAddedDatabase = await element.onAddDatabaseClicked(
this._context
);

if (successfullyAddedDatabase) {
vscode.window.showInformationMessage(
'Database and collection successfully created.'
);

// When we successfully added a database & collection, we need
// to update the explorer view.
this._explorerController.refresh();
}
return successfullyAddedDatabase;
}
);
this.registerCommand(
'mdb.copyDatabaseName',
(element: DatabaseTreeItem) => {
return new Promise((resolve, reject) => {
vscode.env.clipboard.writeText(element.databaseName).then(() => {
vscode.window.showInformationMessage('Copied to clipboard.');
return resolve(true);
}, reject);
});
async (element: DatabaseTreeItem) => {
await vscode.env.clipboard.writeText(element.databaseName);
vscode.window.showInformationMessage('Copied to clipboard.');
return true;
}
);
this.registerCommand(
'mdb.dropDatabase',
(element: DatabaseTreeItem): Promise<boolean> => {
return new Promise((resolve, reject) => {
element
.onDropDatabaseClicked()
.then((successfullyDroppedDatabase) => {
if (successfullyDroppedDatabase) {
vscode.window.showInformationMessage(
'Database successfully dropped.'
);

// When we successfully drop a database, we need
// to update the explorer view.
this._explorerController.refresh();
}

resolve(successfullyDroppedDatabase);
}, reject);
});
async (element: DatabaseTreeItem): Promise<boolean> => {
const successfullyDroppedDatabase = await element.onDropDatabaseClicked();

if (successfullyDroppedDatabase) {
vscode.window.showInformationMessage(
'Database successfully dropped.'
);

// When we successfully drop a database, we need
// to update the explorer view.
this._explorerController.refresh();
}

return successfullyDroppedDatabase;
}
);
this.registerCommand(
Expand All @@ -324,58 +312,48 @@ export default class MDBExtensionController implements vscode.Disposable {
vscode.window.showErrorMessage(
'Unable to add collection: currently disconnecting.'
);
return Promise.resolve(false);
return false;
}

return new Promise((resolve, reject) => {
element
.onAddCollectionClicked(this._context)
.then((successfullyAddedCollection) => {
if (successfullyAddedCollection) {
vscode.window.showInformationMessage(
'Collection successfully created.'
);

// When we successfully added a collection, we need
// to update the explorer view.
this._explorerController.refresh();
}
resolve(true);
}, reject);
});
const successfullyAddedCollection = await element
.onAddCollectionClicked(this._context);
if (successfullyAddedCollection) {
vscode.window.showInformationMessage(
'Collection successfully created.'
);

// When we successfully added a collection, we need
// to update the explorer view.
this._explorerController.refresh();
}
return true;
}
);
this.registerCommand(
'mdb.copyCollectionName',
(element: CollectionTreeItem): Promise<boolean> => {
return new Promise((resolve, reject) => {
vscode.env.clipboard.writeText(element.collectionName).then(() => {
vscode.window.showInformationMessage('Copied to clipboard.');
return resolve(true);
}, reject);
});
async (element: CollectionTreeItem): Promise<boolean> => {
await vscode.env.clipboard.writeText(element.collectionName);
vscode.window.showInformationMessage('Copied to clipboard.');

return true;
}
);
this.registerCommand(
'mdb.dropCollection',
(element: CollectionTreeItem): Promise<boolean> => {
return new Promise((resolve, reject) => {
element
.onDropCollectionClicked()
.then((successfullyDroppedCollection) => {
if (successfullyDroppedCollection) {
vscode.window.showInformationMessage(
'Collection successfully dropped.'
);

// When we successfully drop a collection, we need
// to update the explorer view.
this._explorerController.refresh();
}

resolve(successfullyDroppedCollection);
}, reject);
});
async (element: CollectionTreeItem): Promise<boolean> => {
const successfullyDroppedCollection = await element.onDropCollectionClicked();

if (successfullyDroppedCollection) {
vscode.window.showInformationMessage(
'Collection successfully dropped.'
);

// When we successfully drop a collection, we need
// to update the explorer view.
this._explorerController.refresh();
}

return successfullyDroppedCollection;
}
);
this.registerCommand(
Expand Down Expand Up @@ -417,6 +395,17 @@ export default class MDBExtensionController implements vscode.Disposable {
return this._explorerController.refresh();
}
);
this.registerCommand(
'mdb.copySchemaFieldName',
async (fieldTreeItem: FieldTreeItem): Promise<boolean> => {
await vscode.env.clipboard.writeText(
fieldTreeItem.getFieldName()
);
vscode.window.showInformationMessage('Copied to clipboard.');

return true;
}
);
}

dispose(): void {
Expand Down
10 changes: 5 additions & 5 deletions src/test/suite/explorer/explorerController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const sinon = require('sinon');

import {
DefaultSavingLocations,
StorageScope,
StorageScope
} from '../../../storage/storageController';
import { TEST_DATABASE_URI } from '../dbTestHelper';
import { mdbTestExtension } from '../stubbableMdbExtension';
Expand Down Expand Up @@ -84,8 +84,8 @@ suite('Explorer Controller Test Suite', function () {
connectionModel: new Connection(),
name: 'testConnectionName',
driverUrl: 'url',
storageLocation: StorageScope.NONE,
},
storageLocation: StorageScope.NONE
}
};
testConnectionController.setConnnectingConnectionId(mockConnectionId);
testConnectionController.setConnnecting(true);
Expand Down Expand Up @@ -247,7 +247,7 @@ suite('Explorer Controller Test Suite', function () {
driverUrl: '',
name: 'aaa',
id: 'aaa',
storageLocation: StorageScope.WORKSPACE,
storageLocation: StorageScope.WORKSPACE
};

testConnectionController._connections.zzz = {
Expand All @@ -256,7 +256,7 @@ suite('Explorer Controller Test Suite', function () {
driverUrl: '',
name: 'zzz',
id: 'zzz',
storageLocation: StorageScope.WORKSPACE,
storageLocation: StorageScope.WORKSPACE
};

const treeControllerChildren = await treeController.getChildren();
Expand Down
Loading