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 4, 2024
1 parent d3da9c7 commit 0c315aa
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 @@ -1002,7 +1060,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 @@ -32,6 +32,7 @@ import { openLink } from './utils/linkHelper';
import type { LoadedConnection } from './storage/connectionStorage';
import { ConnectionStorage } from './storage/connectionStorage';
import LINKS from './utils/links';
import { isAtlasStream } from 'mongodb-build-info';

// eslint-disable-next-line @typescript-eslint/no-var-requires
const packageJSON = require('../package.json');
Expand Down Expand Up @@ -397,6 +398,12 @@ export default class ConnectionController {
true
);

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

void this.onConnectSuccess({
connectionInfo,
dataService,
Expand Down Expand Up @@ -542,6 +549,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 @@ -769,6 +781,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 0c315aa

Please sign in to comment.