Skip to content

Commit

Permalink
perf: update the code according to the comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wenytang-ms committed Feb 14, 2025
1 parent 5359230 commit c6ce4a2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 34 deletions.
14 changes: 7 additions & 7 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ export enum GatewayKeyType {
}

export const APIMAccountCommandId = {
createAzureAccount: "Create an Azure Account...",
createAzureStudentAccount: "Create an Azure for Students Account...",
accountLoading: "azureManagementAccountLoading",
accountSignIn: "azureManagementAccountSignIn",
accountSigningIn: "azureManagementAccountSigningIn",
accountSelectTenant: "azureManagementAccountSelectTenant",
accountError: "AzureAccountError",
createAzureAccount: "azureApiManagementCreateAzureAccount",
createAzureStudentAccount: "azureApiManagementCreateAzureStudentAccount",
accountLoading: "azureApiManagementAccountLoading",
accountSignIn: "azureApiManagementAccountSignIn",
accountSigningIn: "azureApiManagementAccountSigningIn",
accountSelectTenant: "azureApiManagementAccountSelectTenant",
accountError: "azureApiManagementAccountError",
}

export const AzureAccountUrl = {
Expand Down
7 changes: 0 additions & 7 deletions src/explorer/ApiManagementProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { getWorkspaceSetting, updateGlobalSetting } from '../vsCodeConfig/settin
import { ServiceTreeItem } from './ServiceTreeItem';
import { treeUtils } from '../utils/treeUtils';

export function createSubscriptionTreeItem(
parent: AzExtParentTreeItem,
subscription: ISubscriptionContext,
): AzExtTreeItem {
return new ApiManagementProvider(parent, subscription);
}

export class ApiManagementProvider extends SubscriptionTreeItemBase {
public readonly childTypeLabel: string = localize('azureApiManagement.ApimService', 'API Management Service');

Expand Down
14 changes: 3 additions & 11 deletions src/explorer/AzureAccountTreeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ import { GeneralUtils } from "../utils/generalUtils";
import { AzureAuth } from "../azure/azureLogin/azureAuth";
import { APIMAccountCommandId } from "../constants";
import { Subscription } from "@azure/arm-resources-subscriptions";
import { createSubscriptionTreeItem } from "./ApiManagementProvider";

export function createAzureAccountTreeItem(
sessionProvider: AzureSessionProvider,
): AzExtParentTreeItem & { dispose(): unknown } {
return new AzureAccountTreeItem(sessionProvider);
}
import { ApiManagementProvider } from "./ApiManagementProvider";

export class AzureAccountTreeItem extends AzExtParentTreeItem {
private subscriptionTreeItems: AzExtTreeItem[] | undefined;
Expand Down Expand Up @@ -46,9 +40,7 @@ export class AzureAccountTreeItem extends AzExtParentTreeItem {
}

// no need to sort the array
public compareChildrenImpl(item1: AzExtTreeItem, item2: AzExtTreeItem): number {
item1;
item2;
public compareChildrenImpl(_item1: AzExtTreeItem, _item2: AzExtTreeItem): number {
return 0;
}

Expand Down Expand Up @@ -173,7 +165,7 @@ export class AzureAccountTreeItem extends AzExtParentTreeItem {
session.result,
subscription,
);
return await createSubscriptionTreeItem(this, subscriptionContext);
return new ApiManagementProvider(this, subscriptionContext);
}
}),
);
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import { AuthorizationProvidersTreeItem } from './explorer/AuthorizationProvider
import { AuthorizationProviderTreeItem } from './explorer/AuthorizationProviderTreeItem';
import { AuthorizationsTreeItem } from './explorer/AuthorizationsTreeItem';
import { AuthorizationTreeItem } from './explorer/AuthorizationTreeItem';
import { createAzureAccountTreeItem } from './explorer/AzureAccountTreeItem';
import { AzureAccountTreeItem } from './explorer/AzureAccountTreeItem';
import { ApiResourceEditor } from './explorer/editors/arm/ApiResourceEditor';
import { AuthorizationAccessPolicyResourceEditor } from './explorer/editors/arm/AuthorizationAccessPolicyResourceEditor';
import { AuthorizationProviderResourceEditor } from './explorer/editors/arm/AuthorizationProviderResourceEditor';
Expand Down Expand Up @@ -100,11 +100,11 @@ export async function activateInternal(context: vscode.ExtensionContext) {
activateContext.telemetry.properties.isActivationEvent = 'true';
AzureSessionProviderHelper.activateAzureSessionProvider(context);
const sessionProvider = AzureSessionProviderHelper.getSessionProvider();
const azureAccountTreeItem = createAzureAccountTreeItem(sessionProvider);
const azureAccountTreeItem = new AzureAccountTreeItem(sessionProvider);
context.subscriptions.push(azureAccountTreeItem);
ext.azureAccountTreeItem = azureAccountTreeItem;

ext.tree = new AzExtTreeDataProvider(azureAccountTreeItem, 'azureApiManagement.loadMore');
ext.tree = new AzExtTreeDataProvider(azureAccountTreeItem, 'azureApiManagement.LoadMore');
context.subscriptions.push(vscode.window.registerTreeDataProvider('azureApiManagementExplorer', ext.tree));

registerCommands(ext.tree);
Expand Down
4 changes: 2 additions & 2 deletions src/extensionVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { ExtensionContext } from "vscode";
import { ExtensionContext, Disposable } from "vscode";
import { AzExtTreeDataProvider, IAzExtOutputChannel, AzExtParentTreeItem } from "@microsoft/vscode-azext-utils";

/**
Expand All @@ -12,7 +12,7 @@ export namespace ext {
export let context: ExtensionContext;
export let tree: AzExtTreeDataProvider;
export let outputChannel: IAzExtOutputChannel;
export let azureAccountTreeItem: AzExtParentTreeItem & { dispose(): unknown };
export let azureAccountTreeItem: AzExtParentTreeItem & Disposable;
export const prefix: string = 'azureAPIM';
//export let reporter: ITelemetryContext;
}
3 changes: 1 addition & 2 deletions src/utils/azureClientUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export namespace azureClientUtil {
}

// tslint:disable: no-unsafe-any
export async function selectSubscription(context: IActionContext): Promise<string> {
context;
export async function selectSubscription(_context: IActionContext): Promise<string> {
await AzureAccount.selectSubscriptions();
let res = await AzureSubscriptionHelper.getFilteredSubscriptions();
return res[0].subscriptionId;
Expand Down
2 changes: 0 additions & 2 deletions test/createService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ suite('Create Azure Resources', async function (this: Suite): Promise<void> {

this.timeout(120 * 1000);
await testAccount.signIn();
// ext.azureAccountTreeItem = new AzureAccountTreeItem(testAccount);
// ext.tree = new AzExtTreeDataProvider(ext.azureAccountTreeItem, 'azureApiManagement.LoadMore');
const rootNode : AzExtParentTreeItem = await treeUtils.getRootNode(ext.tree);
rootNode.subscription.userId = "[email protected]"; // userId doesnt exist for service principal.
//apiManagementClient = getApiManagementClient(testAccount);
Expand Down

0 comments on commit c6ce4a2

Please sign in to comment.