Skip to content

Commit

Permalink
VSCODE-505: stream support in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
shaketbaby committed Jan 3, 2024
1 parent eb490f0 commit 1f77f6b
Show file tree
Hide file tree
Showing 18 changed files with 873 additions and 58 deletions.
11 changes: 11 additions & 0 deletions images/dark/stream-processor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions images/light/stream-processor.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 67 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,26 @@
{
"command": "mdb.deleteDocumentFromTreeView",
"title": "Delete Document..."
},
{
"command": "mdb.addStreamProcessor",
"title": "Add StreamProcessor...",
"icon": {
"light": "images/light/plus-circle.svg",
"dark": "images/dark/plus-circle.svg"
}
},
{
"command": "mdb.startStreamProcessor",
"title": "Start Stream Processor"
},
{
"command": "mdb.stopStreamProcessor",
"title": "Stop Stream Processor"
},
{
"command": "mdb.dropStreamProcessor",
"title": "Drop Stream Processor..."
}
],
"menus": {
Expand Down Expand Up @@ -428,12 +448,22 @@
"view/item/context": [
{
"command": "mdb.addDatabase",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == false",
"group": "inline"
},
{
"command": "mdb.addDatabase",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == false",
"group": "1@1"
},
{
"command": "mdb.addStreamProcessor",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == true",
"group": "inline"
},
{
"command": "mdb.addStreamProcessor",
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == true",
"group": "1@1"
},
{
Expand Down Expand Up @@ -611,6 +641,18 @@
"command": "mdb.deleteDocumentFromTreeView",
"when": "view == mongoDBConnectionExplorer && viewItem == documentTreeItem",
"group": "3@1"
},
{
"command": "mdb.startStreamProcessor",
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
},
{
"command": "mdb.stopStreamProcessor",
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
},
{
"command": "mdb.dropStreamProcessor",
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
}
],
"editor/title": [
Expand Down Expand Up @@ -639,27 +681,27 @@
},
{
"command": "mdb.exportToRuby",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.exportToPython",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.exportToJava",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.exportToCsharp",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.exportToNode",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.exportToGo",
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
},
{
"command": "mdb.refreshPlaygroundsFromTreeView",
Expand Down Expand Up @@ -804,6 +846,22 @@
{
"command": "mdb.deleteDocumentFromTreeView",
"when": "false"
},
{
"command": "mdb.addStreamProcessor",
"when": "false"
},
{
"command": "mdb.startStreamProcessor",
"when": "false"
},
{
"command": "mdb.stopStreamProcessor",
"when": "false"
},
{
"command": "mdb.dropStreamProcessor",
"when": "false"
}
]
},
Expand Down Expand Up @@ -996,7 +1054,7 @@
"mongodb-build-info": "^1.6.2",
"mongodb-cloud-info": "^2.1.0",
"mongodb-connection-string-url": "^2.6.0",
"mongodb-data-service": "^22.17.0",
"mongodb-data-service": "^22.17.1",
"mongodb-data-service-legacy": "npm:[email protected]",
"mongodb-log-writer": "^1.4.0",
"mongodb-query-parser": "^3.1.3",
Expand Down
4 changes: 4 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ enum EXTENSION_COMMANDS {
MDB_COPY_DOCUMENT_CONTENTS_FROM_TREE_VIEW = 'mdb.copyDocumentContentsFromTreeView',
MDB_CLONE_DOCUMENT_FROM_TREE_VIEW = 'mdb.cloneDocumentFromTreeView',
MDB_DELETE_DOCUMENT_FROM_TREE_VIEW = 'mdb.deleteDocumentFromTreeView',
MDB_ADD_STREAM_PROCESSOR = 'mdb.addStreamProcessor',
MDB_START_STREAM_PROCESSOR = 'mdb.startStreamProcessor',
MDB_STOP_STREAM_PROCESSOR = 'mdb.stopStreamProcessor',
MDB_DROP_STREAM_PROCESSOR = 'mdb.dropStreamProcessor',
}

export default EXTENSION_COMMANDS;
19 changes: 19 additions & 0 deletions src/connectionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import type TelemetryService from './telemetry/telemetryService';
import type { LoadedConnection } from './storage/connectionStorage';
import { ConnectionStorage } from './storage/connectionStorage';
import LINKS from './utils/links';
import { isAtlasStream } from 'mongodb-build-info';

export function launderConnectionOptionTypeFromLegacyToCurrent(
opts: ConnectionOptionsFromLegacyDS
Expand Down Expand Up @@ -346,6 +347,12 @@ export default class ConnectionController {
true
);

void vscode.commands.executeCommand(
'setContext',
'mdb.isAtlasStreams',
this.isConnectedToAtlasStreams()
);

return {
successfullyConnected: true,
connectionErrorMessage: '',
Expand Down Expand Up @@ -408,6 +415,11 @@ export default class ConnectionController {
'mdb.connectedToMongoDB',
false
);
void vscode.commands.executeCommand(
'setContext',
'mdb.isAtlasStreams',
false
);
} catch (error) {
// Show an error, however we still reset the active connection to free up the extension.
void vscode.window.showErrorMessage(
Expand Down Expand Up @@ -635,6 +647,13 @@ export default class ConnectionController {
return connectionStringData.toString();
}

isConnectedToAtlasStreams() {
return (
this.isCurrentlyConnected() &&
isAtlasStream(this.getActiveConnectionString())
);
}

getActiveConnectionString(): string {
const mongoClientConnectionOptions = this.getMongoClientConnectionOptions();
const connectionString = mongoClientConnectionOptions?.url;
Expand Down
18 changes: 17 additions & 1 deletion src/editors/playgroundController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import playgroundCreateIndexTemplate from '../templates/playgroundCreateIndexTem
import playgroundCreateCollectionTemplate from '../templates/playgroundCreateCollectionTemplate';
import playgroundCloneDocumentTemplate from '../templates/playgroundCloneDocumentTemplate';
import playgroundInsertDocumentTemplate from '../templates/playgroundInsertDocumentTemplate';
import playgroundStreamsTemplate from '../templates/playgroundStreamsTemplate';
import playgroundCreateStreamProcessorTemplate from '../templates/playgroundCreateStreamProcessorTemplate';
import type {
PlaygroundResult,
ShellEvaluateResult,
Expand Down Expand Up @@ -391,11 +393,25 @@ export default class PlaygroundController {
return this._createPlaygroundFileWithContent(content);
}

async createPlaygroundForCreateStreamProcessor(
element: ConnectionTreeItem
): Promise<boolean> {
const content = playgroundCreateStreamProcessorTemplate;

element.cacheIsUpToDate = false;

this._telemetryService.trackPlaygroundCreated('createStreamProcessor');

return this._createPlaygroundFileWithContent(content);
}

async createPlayground(): Promise<boolean> {
const useDefaultTemplate = !!vscode.workspace
.getConfiguration('mdb')
.get('useDefaultTemplateForPlayground');
const content = useDefaultTemplate ? playgroundTemplate : '';
const isStreams = this._connectionController.isConnectedToAtlasStreams();
const template = isStreams ? playgroundStreamsTemplate : playgroundTemplate;
const content = useDefaultTemplate ? template : '';

this._telemetryService.trackPlaygroundCreated('crud');
return this._createPlaygroundFileWithContent(content);
Expand Down
Loading

0 comments on commit 1f77f6b

Please sign in to comment.