Skip to content

Commit

Permalink
Implement Group By Arm Tag command (#517)
Browse files Browse the repository at this point in the history
Fixes #465
  • Loading branch information
alexweininger authored Jan 12, 2023
1 parent 7273a9c commit d905e8f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@
"@azure/arm-resources": "5.0.0",
"@azure/arm-resources-profile-2020-09-01-hybrid": "^2.0.0",
"@microsoft/vscode-azext-azureutils": "^0.3.4",
"@microsoft/vscode-azext-utils": "^0.3.25",
"@microsoft/vscode-azext-utils": "^0.3.26",
"jsonc-parser": "^2.2.1",
"open": "^8.0.4",
"semver": "^7.3.7",
Expand Down
22 changes: 16 additions & 6 deletions src/commands/explorer/groupBy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,39 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { IActionContext } from "@microsoft/vscode-azext-utils";
import { uiUtils } from "@microsoft/vscode-azext-azureutils";
import { IActionContext, nonNullProp, subscriptionExperience } from "@microsoft/vscode-azext-utils";
import { AzureSubscription } from "@microsoft/vscode-azext-utils/hostapi.v2";
import { QuickPickItem } from "vscode";
import { ext } from "../../extensionVariables";
import { createResourceClient } from "../../utils/azureClients";
import { localize } from "../../utils/localize";
import { settingUtils } from "../../utils/settingUtils";
import { createSubscriptionContext } from "../../utils/v2/credentialsUtils";

export function buildGroupByCommand(setting: string) {
return (context: IActionContext): Promise<void> => groupBy(context, setting);
}

async function groupBy(context: IActionContext, setting: string): Promise<void> {
if (setting === 'armTag') {
const tag = await context.ui.showQuickPick(getQuickPicks(context), {
placeHolder: localize('groupByArmTagKey', 'Select the tag key to group by...')
const subscription = await subscriptionExperience(context, ext.v2.api.resources.azureResourceTreeDataProvider);
const tag = await context.ui.showQuickPick(getQuickPicks(context, subscription), {
placeHolder: localize('groupByArmTagKey', 'Select the tag key to group by...'),
loadingPlaceHolder: localize('loadingTags', 'Loading tags...'),
});
setting += `-${tag.label}`;
}

await settingUtils.updateGlobalSetting('groupBy', setting);
}

async function getQuickPicks(_context: IActionContext): Promise<QuickPickItem[]> {
// TODO
throw new Error('Getting arm tag keys is not implemented yet');
async function getQuickPicks(context: IActionContext, subscription: AzureSubscription): Promise<QuickPickItem[]> {
const client = await createResourceClient([context, createSubscriptionContext(subscription)]);
const tags = await uiUtils.listAllIterator(client.tagsOperations.list());
return tags.map(tag => ({
label: nonNullProp(tag, 'tagName'),
}));
}

export enum GroupBySettings {
Expand Down

0 comments on commit d905e8f

Please sign in to comment.