Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for document field labels #719

Merged
merged 3 commits into from
Jun 27, 2018
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
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,21 @@
"default": true,
"description": "Show or hide the Cosmos DB Explorer"
},
"cosmosDB.documentLabelFields": {
"type": "array",
"default": [
"name",
"Name",
"NAME",
"ID",
"UUID",
"Id",
"id",
"_id",
"uuid"
],
"description": "The field values to display as labels in the treeview for Cosmos DB and MongoDB documents, in priority order"
},
"cosmosDB.showSavePrompt": {
"type": "boolean",
"default": true,
Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,3 @@ export const defaultStoredProcedure =
};` ;

export const emptyPartitionKeyValue = {};

export const documentLabelFields = ["name", "Name", "NAME", "ID", "UUID", "Id", "id", "_id", "uuid"];
2 changes: 0 additions & 2 deletions src/docdb/tree/DocDBDocumentsTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import { IAzureTreeItem, UserCancelledError, IAzureNode } from 'vscode-azureexte
import { DocDBDocumentTreeItem } from './DocDBDocumentTreeItem';
import { DocDBCollectionTreeItem } from './DocDBCollectionTreeItem';

// NOTE: This node not used until viewing/editor stored procedures is implemented

/**
* This class provides logic for DocumentDB collections
*/
Expand Down
18 changes: 16 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { DocDBAccountTreeItemBase } from './docdb/tree/DocDBAccountTreeItemBase'
import { GraphAccountTreeItem } from './graph/tree/GraphAccountTreeItem';
import { DocDBAccountTreeItem } from './docdb/tree/DocDBAccountTreeItem';
import { TableAccountTreeItem } from './table/tree/TableAccountTreeItem';
import { ext } from './extensionVariables';

export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(new Reporter(context));
Expand Down Expand Up @@ -114,8 +115,21 @@ export function activate(context: vscode.ExtensionContext) {
});
actionHandler.registerCommand('cosmosDB.update', (filePath: vscode.Uri) => editorManager.updateMatchingNode(filePath, tree));
actionHandler.registerCommand('cosmosDB.loadMore', (node?: IAzureNode) => tree.loadMore(node));
actionHandler.registerEvent('cosmosDB.CosmosEditorManager.onDidSaveTextDocument', vscode.workspace.onDidSaveTextDocument, async function
(this: IActionContext, doc: vscode.TextDocument): Promise<void> { await editorManager.onDidSaveTextDocument(this, doc, tree); });
actionHandler.registerEvent('cosmosDB.CosmosEditorManager.onDidSaveTextDocument', vscode.workspace.onDidSaveTextDocument, async function (
this: IActionContext, doc: vscode.TextDocument): Promise<void> {
await editorManager.onDidSaveTextDocument(this, doc, tree);
});
actionHandler.registerEvent(
'cosmosDB.onDidChangeConfiguration',
vscode.workspace.onDidChangeConfiguration,
async function
(this: IActionContext, event: vscode.ConfigurationChangeEvent): Promise<void> {
this.properties.isActivationEvent = "true";
this.suppressErrorDisplay = true;
if (event.affectsConfiguration(ext.settingsKeys.documentLabelFields)) {
await vscode.commands.executeCommand("cosmosDB.refresh");
}
});
}

async function getAttachedNode(tree: AzureTreeDataProvider): Promise<IAzureParentNode<AttachedAccountsTreeItem>> {
Expand Down
1 change: 1 addition & 0 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export namespace ext {

export namespace settingsKeys {
export const mongoShellPath = 'mongo.shell.path';
export const documentLabelFields = 'cosmosDB.documentLabelFields';

export namespace vsCode {
export const proxyStrictSSL = "http.proxyStrictSSL";
Expand Down
10 changes: 8 additions & 2 deletions src/utils/vscodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { MongoAccountTreeItem } from '../mongo/tree/MongoAccountTreeItem';
import { DocDBAccountTreeItemBase } from '../docdb/tree/DocDBAccountTreeItemBase';
import { IMongoDocument } from '../mongo/tree/MongoDocumentTreeItem';
import { RetrievedDocument } from 'documentdb';
import { documentLabelFields } from '../constants';
import { ext } from '../extensionVariables';

const outputChannel = vscode.window.createOutputChannel("Azure CosmosDB");

Expand Down Expand Up @@ -107,7 +107,7 @@ function isAccountTreeItem(treeItem: IAzureTreeItem): boolean {
}

export function getDocumentTreeItemLabel(document: IMongoDocument | RetrievedDocument): string {
for (let field of documentLabelFields) {
for (let field of getDocumentLabelFields()) {
if (document.hasOwnProperty(field)) {
let value = document[field];
if (value !== undefined && typeof value !== 'object') {
Expand All @@ -117,3 +117,9 @@ export function getDocumentTreeItemLabel(document: IMongoDocument | RetrievedDoc
}
return String(document["_id"]);
}

function getDocumentLabelFields(): string[] {
const settingKey: string = ext.settingsKeys.documentLabelFields;
let documentLabelFields: string[] | undefined = vscode.workspace.getConfiguration().get(settingKey) || [];
return documentLabelFields;
}