Skip to content

Commit 6f2017f

Browse files
authored
VSCODE-505: stream support in UI (#643)
* VSCODE-505: stream support in UI * address feedbacks
1 parent b366fb3 commit 6f2017f

18 files changed

+871
-62
lines changed

images/dark/stream-processor.svg

Lines changed: 11 additions & 0 deletions
Loading

images/light/stream-processor.svg

Lines changed: 11 additions & 0 deletions
Loading

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,26 @@
397397
{
398398
"command": "mdb.deleteDocumentFromTreeView",
399399
"title": "Delete Document..."
400+
},
401+
{
402+
"command": "mdb.addStreamProcessor",
403+
"title": "Add StreamProcessor...",
404+
"icon": {
405+
"light": "images/light/plus-circle.svg",
406+
"dark": "images/dark/plus-circle.svg"
407+
}
408+
},
409+
{
410+
"command": "mdb.startStreamProcessor",
411+
"title": "Start Stream Processor"
412+
},
413+
{
414+
"command": "mdb.stopStreamProcessor",
415+
"title": "Stop Stream Processor"
416+
},
417+
{
418+
"command": "mdb.dropStreamProcessor",
419+
"title": "Drop Stream Processor..."
400420
}
401421
],
402422
"menus": {
@@ -428,12 +448,22 @@
428448
"view/item/context": [
429449
{
430450
"command": "mdb.addDatabase",
431-
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem",
451+
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == false",
432452
"group": "inline"
433453
},
434454
{
435455
"command": "mdb.addDatabase",
436-
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem",
456+
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == false",
457+
"group": "1@1"
458+
},
459+
{
460+
"command": "mdb.addStreamProcessor",
461+
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == true",
462+
"group": "inline"
463+
},
464+
{
465+
"command": "mdb.addStreamProcessor",
466+
"when": "view == mongoDBConnectionExplorer && viewItem == connectedConnectionTreeItem && mdb.isAtlasStreams == true",
437467
"group": "1@1"
438468
},
439469
{
@@ -611,6 +641,18 @@
611641
"command": "mdb.deleteDocumentFromTreeView",
612642
"when": "view == mongoDBConnectionExplorer && viewItem == documentTreeItem",
613643
"group": "3@1"
644+
},
645+
{
646+
"command": "mdb.startStreamProcessor",
647+
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
648+
},
649+
{
650+
"command": "mdb.stopStreamProcessor",
651+
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
652+
},
653+
{
654+
"command": "mdb.dropStreamProcessor",
655+
"when": "view == mongoDBConnectionExplorer && viewItem == streamProcessorTreeItem"
614656
}
615657
],
616658
"editor/title": [
@@ -639,27 +681,27 @@
639681
},
640682
{
641683
"command": "mdb.exportToRuby",
642-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
684+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
643685
},
644686
{
645687
"command": "mdb.exportToPython",
646-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
688+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
647689
},
648690
{
649691
"command": "mdb.exportToJava",
650-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
692+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
651693
},
652694
{
653695
"command": "mdb.exportToCsharp",
654-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
696+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
655697
},
656698
{
657699
"command": "mdb.exportToNode",
658-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
700+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
659701
},
660702
{
661703
"command": "mdb.exportToGo",
662-
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true"
704+
"when": "mdb.isPlayground == true && mdb.connectedToMongoDB == true && mdb.isAtlasStreams == false"
663705
},
664706
{
665707
"command": "mdb.refreshPlaygroundsFromTreeView",
@@ -804,6 +846,22 @@
804846
{
805847
"command": "mdb.deleteDocumentFromTreeView",
806848
"when": "false"
849+
},
850+
{
851+
"command": "mdb.addStreamProcessor",
852+
"when": "false"
853+
},
854+
{
855+
"command": "mdb.startStreamProcessor",
856+
"when": "false"
857+
},
858+
{
859+
"command": "mdb.stopStreamProcessor",
860+
"when": "false"
861+
},
862+
{
863+
"command": "mdb.dropStreamProcessor",
864+
"when": "false"
807865
}
808866
]
809867
},
@@ -1002,7 +1060,7 @@
10021060
"mongodb-build-info": "^1.6.2",
10031061
"mongodb-cloud-info": "^2.1.0",
10041062
"mongodb-connection-string-url": "^2.6.0",
1005-
"mongodb-data-service": "^22.17.0",
1063+
"mongodb-data-service": "^22.17.1",
10061064
"mongodb-data-service-legacy": "npm:[email protected]",
10071065
"mongodb-log-writer": "^1.4.0",
10081066
"mongodb-query-parser": "^3.1.3",

src/commands/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ enum EXTENSION_COMMANDS {
6666
MDB_COPY_DOCUMENT_CONTENTS_FROM_TREE_VIEW = 'mdb.copyDocumentContentsFromTreeView',
6767
MDB_CLONE_DOCUMENT_FROM_TREE_VIEW = 'mdb.cloneDocumentFromTreeView',
6868
MDB_DELETE_DOCUMENT_FROM_TREE_VIEW = 'mdb.deleteDocumentFromTreeView',
69+
MDB_ADD_STREAM_PROCESSOR = 'mdb.addStreamProcessor',
70+
MDB_START_STREAM_PROCESSOR = 'mdb.startStreamProcessor',
71+
MDB_STOP_STREAM_PROCESSOR = 'mdb.stopStreamProcessor',
72+
MDB_DROP_STREAM_PROCESSOR = 'mdb.dropStreamProcessor',
6973
}
7074

7175
export default EXTENSION_COMMANDS;

src/connectionController.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { openLink } from './utils/linkHelper';
3232
import type { LoadedConnection } from './storage/connectionStorage';
3333
import { ConnectionStorage } from './storage/connectionStorage';
3434
import LINKS from './utils/links';
35+
import { isAtlasStream } from 'mongodb-build-info';
3536

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

401+
void vscode.commands.executeCommand(
402+
'setContext',
403+
'mdb.isAtlasStreams',
404+
this.isConnectedToAtlasStreams()
405+
);
406+
400407
void this.onConnectSuccess({
401408
connectionInfo,
402409
dataService,
@@ -542,6 +549,11 @@ export default class ConnectionController {
542549
'mdb.connectedToMongoDB',
543550
false
544551
);
552+
void vscode.commands.executeCommand(
553+
'setContext',
554+
'mdb.isAtlasStreams',
555+
false
556+
);
545557
} catch (error) {
546558
// Show an error, however we still reset the active connection to free up the extension.
547559
void vscode.window.showErrorMessage(
@@ -769,6 +781,13 @@ export default class ConnectionController {
769781
return connectionStringData.toString();
770782
}
771783

784+
isConnectedToAtlasStreams() {
785+
return (
786+
this.isCurrentlyConnected() &&
787+
isAtlasStream(this.getActiveConnectionString())
788+
);
789+
}
790+
772791
getActiveConnectionString(): string {
773792
const mongoClientConnectionOptions = this.getMongoClientConnectionOptions();
774793
const connectionString = mongoClientConnectionOptions?.url;

src/editors/playgroundController.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ import playgroundCreateIndexTemplate from '../templates/playgroundCreateIndexTem
2020
import playgroundCreateCollectionTemplate from '../templates/playgroundCreateCollectionTemplate';
2121
import playgroundCloneDocumentTemplate from '../templates/playgroundCloneDocumentTemplate';
2222
import playgroundInsertDocumentTemplate from '../templates/playgroundInsertDocumentTemplate';
23+
import playgroundStreamsTemplate from '../templates/playgroundStreamsTemplate';
24+
import playgroundCreateStreamProcessorTemplate from '../templates/playgroundCreateStreamProcessorTemplate';
2325
import type {
2426
PlaygroundResult,
2527
ShellEvaluateResult,
@@ -391,11 +393,25 @@ export default class PlaygroundController {
391393
return this._createPlaygroundFileWithContent(content);
392394
}
393395

396+
async createPlaygroundForCreateStreamProcessor(
397+
element: ConnectionTreeItem
398+
): Promise<boolean> {
399+
const content = playgroundCreateStreamProcessorTemplate;
400+
401+
element.cacheIsUpToDate = false;
402+
403+
this._telemetryService.trackPlaygroundCreated('createStreamProcessor');
404+
405+
return this._createPlaygroundFileWithContent(content);
406+
}
407+
394408
async createPlayground(): Promise<boolean> {
395409
const useDefaultTemplate = !!vscode.workspace
396410
.getConfiguration('mdb')
397411
.get('useDefaultTemplateForPlayground');
398-
const content = useDefaultTemplate ? playgroundTemplate : '';
412+
const isStreams = this._connectionController.isConnectedToAtlasStreams();
413+
const template = isStreams ? playgroundStreamsTemplate : playgroundTemplate;
414+
const content = useDefaultTemplate ? template : '';
399415

400416
this._telemetryService.trackPlaygroundCreated('crud');
401417
return this._createPlaygroundFileWithContent(content);

0 commit comments

Comments
 (0)