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

Use updated AzExtTreeFileSystem #2094

Merged
merged 1 commit into from
Jan 17, 2023
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
44 changes: 37 additions & 7 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@
"@azure/arm-postgresql-flexible": "^5.0.0",
"@azure/cosmos": "^3.6.3",
"@microsoft/vscode-azext-azureutils": "^0.3.4",
"@microsoft/vscode-azext-utils": "^0.3.15",
"@microsoft/vscode-azext-utils": "^0.4.0",
"antlr4ts": "^0.4.1-alpha.0",
"bson": "^1.1.3",
"fs-extra": "^8.0.0",
Expand Down
72 changes: 2 additions & 70 deletions src/DatabasesFileSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtItemQuery, AzExtItemUriParts, AzExtTreeFileSystem, AzExtTreeItem, DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { Collection, Db } from "mongodb";
import { basename, dirname } from 'path';
import { AzExtTreeFileSystem, AzExtTreeItem, DialogResponses, IActionContext, UserCancelledError } from '@microsoft/vscode-azext-utils';
import { FileStat, FileType, MessageItem, Uri, workspace } from "vscode";
import { FileChangeType } from "vscode-languageclient";
import { ext } from "./extensionVariables";
import { MongoCollectionTreeItem } from "./mongo/tree/MongoCollectionTreeItem";
import { MongoDatabaseTreeItem } from "./mongo/tree/MongoDatabaseTreeItem";
import { localize } from "./utils/localize";
import { getWorkspaceSetting, updateGlobalSetting } from "./utils/settingUtils";
import { getNodeEditorLabel } from "./utils/vscodeUtils";

export interface IEditableTreeItem extends AzExtTreeItem {
id: string;
filePath: string;
cTime: number;
mTime: number;
Expand Down Expand Up @@ -77,69 +74,4 @@ export class DatabasesFileSystem extends AzExtTreeFileSystem<IEditableTreeItem>
node.mTime = Date.now();
this.fireSoon({ type: FileChangeType.Changed, item: node });
}

protected getUriParts(node: IEditableTreeItem): AzExtItemUriParts {
const uriParts: AzExtItemUriParts = super.getUriParts(node);
if (node instanceof MongoCollectionTreeItem && node.findArgs) {
addFindArgsToQuery(uriParts.query, node.findArgs);
}
return uriParts;
}

protected async findItem(context: IActionContext, query: AzExtItemQuery): Promise<IEditableTreeItem | undefined> {
let node: IEditableTreeItem | undefined = query.id.includes('cosmosDBAttachedAccounts') ?
await ext.rgApi.workspaceResourceTree.findTreeItem(query.id, context) :
await ext.rgApi.appResourceTree.findTreeItem(query.id, context);

if (!node) {
const parentId: string = dirname(query.id);
const parentNode: IEditableTreeItem | undefined = parentId.includes('cosmosDBAttachedAccounts') ?
await ext.rgApi.workspaceResourceTree.findTreeItem(parentId, context) :
await ext.rgApi.appResourceTree.findTreeItem(parentId, context);
if (parentNode instanceof MongoDatabaseTreeItem) {
const db: Db = await parentNode.connectToDb();
const collectionName: string = basename(query.id);
const collection: Collection = db.collection(collectionName);
node = new MongoCollectionTreeItem(parentNode, collection);
}
}

if (node && node instanceof MongoCollectionTreeItem) {
const findArgs: {}[] | undefined = getFindArgsFromQuery(query);
if (findArgs) {
return new MongoCollectionTreeItem(node.parent, node.collection, findArgs);
}
}
return node;
}
}

function addFindArgsToQuery(query: AzExtItemQuery, commandArgs: {}[]): void {
let count: number = 0;
for (const arg of commandArgs) {
const key: string = getFindArgKey(count);
query[key] = JSON.stringify(arg);
count += 1;
}
}

function getFindArgsFromQuery(query: AzExtItemQuery): {}[] | undefined {
const result: {}[] = [];
let count: number = 0;
// eslint-disable-next-line no-constant-condition
while (true) {
const key: string = getFindArgKey(count);
const value: string | string[] | undefined = query[key];
if (typeof value === 'string') {
result.push(JSON.parse(value));
} else if (!value) {
break;
}
count += 1;
}
return result.length > 0 ? result : undefined;
}

function getFindArgKey(count: number): string {
return 'arg' + String(count);
}