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
11 changes: 11 additions & 0 deletions images/dark/help/atlas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/dark/help/book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/dark/help/leaf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/dark/help/lightbulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/dark/help/megaphone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/dark/help/report.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/help/atlas.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/help/book.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions images/light/help/leaf.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/help/lightbulb.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/help/megaphone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions images/light/help/report.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@
"id": "mongoDBPlaygroundsExplorer",
"name": "Playgrounds",
"when": "config.mdb.showMongoDBPlaygrounds == true"
},
{
"id": "mongoDBHelpExplorer",
"name": "Help and Feedback",
"when": "config.mdb.showMongoDBHelpExplorer == true"
}
]
},
Expand Down Expand Up @@ -702,6 +707,11 @@
"default": true,
"description": "Show or hide the MongoDB playgrounds view."
},
"mdb.showMongoDBHelpExplorer": {
"type": "boolean",
"default": true,
"description": "Show or hide the help and feedback view."
},
"mdb.excludeFromPlaygroundsSearch": {
"type": "array",
"items": {
Expand Down
35 changes: 35 additions & 0 deletions src/explorer/helpExplorer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import * as vscode from 'vscode';
import HelpTree from './helpTree';
import { createLogger } from '../logging';
import { TelemetryController } from '../telemetry';

const log = createLogger('help and info explorer controller');

export default class HelpExplorer {
_treeController: HelpTree;
_treeView?: vscode.TreeView<vscode.TreeItem>;

constructor() {
log.info('activate help explorer');
this._treeController = new HelpTree();
}

activateHelpTreeView(telemetryController: TelemetryController): void {
if (!this._treeView) {
this._treeView = vscode.window.createTreeView('mongoDBHelpExplorer', {
treeDataProvider: this._treeController
});
this._treeController.activateTreeViewEventHandlers(
this._treeView,
telemetryController
);
}
}

deactivate(): void {
if (this._treeView) {
this._treeView.dispose();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wonder what will happen if we do not dispose when deactivate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, disposing cleans up the listeners we create in activateTreeViewEventHandlers (treeView.onDidChangeSelection)
https://vscode-docs.readthedocs.io/en/stable/extensions/patterns-and-principles/#disposables
I think it's something we want to keep, just to make sure we clean up a bit.

delete this._treeView;
}
}
}
133 changes: 133 additions & 0 deletions src/explorer/helpTree.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import * as vscode from 'vscode';
const path = require('path');

import { getImagesPath } from '../extensionConstants';
import { TelemetryController } from '../telemetry';

const HELP_LINK_CONTEXT_VALUE = 'HELP_LINK';

export class HelpLinkTreeItem extends vscode.TreeItem {
iconName?: string;
contextValue = HELP_LINK_CONTEXT_VALUE;
linkId: string;
url: string;

constructor(title: string, url: string, linkId: string, iconName?: string) {
super(title, vscode.TreeItemCollapsibleState.None);

this.linkId = linkId;
this.iconName = iconName;
this.url = url;
}

get iconPath():
| string
| vscode.Uri
| { light: string | vscode.Uri; dark: string | vscode.Uri } {
if (!this.iconName || this.iconName === '') {
return '';
}

const LIGHT = path.join(getImagesPath(), 'light');
const DARK = path.join(getImagesPath(), 'dark');

return {
light: path.join(LIGHT, 'help', `${this.iconName}.svg`),
dark: path.join(DARK, 'help', `${this.iconName}.svg`)
};
}
}

export default class HelpTree
implements vscode.TreeDataProvider<vscode.TreeItem> {
contextValue = 'helpTree';

getTreeItem(element: vscode.TreeItem): vscode.TreeItem {
return element;
}

activateTreeViewEventHandlers = (
treeView: vscode.TreeView<vscode.TreeItem>,
telemetryController: TelemetryController
): void => {
treeView.onDidChangeSelection(async (event: any) => {
if (event.selection && event.selection.length === 1) {
const selectedItem = event.selection[0];

await this.onClickHelpItem(selectedItem, telemetryController);
}
});
};

async getChildren(element?: any): Promise<any[]> {
// When no element is present we are at the root.
if (!element) {
const whatsNew = new HelpLinkTreeItem(
'What\'s New',
'https://github.com/mongodb-js/vscode/blob/master/CHANGELOG.md',
'whatsNew',
'megaphone'
);

const extensionDocs = new HelpLinkTreeItem(
'Extension Documentation',
'https://docs.mongodb.com/mongodb-vscode/',
'extensionDocumentation',
'book'
);

const mdbDocs = new HelpLinkTreeItem(
'MongoDB Documentation',
'https://docs.mongodb.com/manual/',
'mongoDBDocumentation',
'leaf'
);

const feedback = new HelpLinkTreeItem(
'Suggest a Feature',
'https://feedback.mongodb.com/forums/929236-mongodb-for-vs-code/',
'feedback',
'lightbulb'
);

const reportBug = new HelpLinkTreeItem(
'Report a Bug',
'https://github.com/mongodb-js/vscode/issues',
'reportABug',
'report'
);

const atlas = new HelpLinkTreeItem(
'Create Free Atlas Cluster',
'https://www.mongodb.com/cloud/atlas/register?utm_source=vscode&utm_medium=product&utm_campaign=VS%20code%20extension',
'freeClusterCTA',
'atlas'
);

return Promise.resolve([
whatsNew,
extensionDocs,
mdbDocs,
feedback,
reportBug,
atlas
]);
}

return element.getChildren();
}

async onClickHelpItem(helpItem: HelpLinkTreeItem, telemetryController: TelemetryController): Promise<void> {
if (helpItem.contextValue === HELP_LINK_CONTEXT_VALUE) {
telemetryController.trackLinkClicked(
'helpPanel',
helpItem.linkId
);

await vscode.commands.executeCommand(
'vscode.open',
vscode.Uri.parse(helpItem.url)
);
}
}
}
8 changes: 5 additions & 3 deletions src/explorer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ConnectionTreeItem from './connectionTreeItem';
import DatabaseTreeItem from './databaseTreeItem';
import { CollectionTypes } from './documentListTreeItem';
import DocumentTreeItem from './documentTreeItem';
import HelpExplorer from './helpExplorer';
import SchemaTreeItem from './schemaTreeItem';
import PlaygroundsExplorer from './playgroundsExplorer';

Expand All @@ -12,8 +13,9 @@ export {
CollectionTypes,
ConnectionTreeItem,
DatabaseTreeItem,
ExplorerController,
DocumentTreeItem,
SchemaTreeItem,
PlaygroundsExplorer
ExplorerController,
HelpExplorer,
PlaygroundsExplorer,
SchemaTreeItem
};
2 changes: 1 addition & 1 deletion src/explorer/playgroundsExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class PlaygroundsExplorer {
}
};

public async activatePlaygroundsTreeView(): Promise<void> {
public activatePlaygroundsTreeView(): void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

this.createPlaygroundsTreeView();
}

Expand Down
Loading