Skip to content

Commit

Permalink
fix: update the code according to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
wenytang-ms committed Aug 13, 2024
1 parent 9816f7c commit 405785a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 38 deletions.
4 changes: 3 additions & 1 deletion src/commands/addDataPlaneApis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ export async function getDataPlaneApis(context: IActionContext): Promise<any | v
if (!tenantid) {
return;
}
// return await getSessionToken(clientid, tenantid);

setAccountToExt(endpointUrl, clientid, tenantid);
ext.workspaceItem.refresh(context);
}
export function setAccountToExt(domain: string, clientId: string, tenantId: string) {
function pushIfNotExist(array: DataPlaneAccount[], element: DataPlaneAccount) {
if (!array.some(item => item.domain === element.domain)) {
array.push(element);
} else {
vscode.window.showInformationMessage(UiStrings.DatplaneAlreadyAdded);
}
}
pushIfNotExist(ext.dataPlaneAccounts, { domain: domain, tenantId: tenantId, clientId: clientId });
Expand Down
4 changes: 2 additions & 2 deletions src/commands/registerApiSubCommands/registerStepByStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as fse from 'fs-extra';
import * as vscode from 'vscode';
import { ApiCenterService } from "../../azure/ApiCenter/ApiCenterService";
import { ApiCenterApi, ApiCenterApiVersion, ApiCenterApiVersionDefinition, ApiCenterApiVersionDefinitionImport, ApiKind, ApiVersionLifecycleStage, SpecificationName } from "../../azure/ApiCenter/contracts";
import { ApiCenterVersionDefinitionManagement } from "../../azure/ApiCenterDefines/ApiCenterDefinition";
import { ApiCenterVersionDefinitionDataPlane } from "../../azure/ApiCenterDefines/ApiCenterDefinition";
import { ext } from "../../extensionVariables";
import { ApiCenterTreeItem } from "../../tree/ApiCenterTreeItem";
import { ApisTreeItem } from "../../tree/ApisTreeItem";
Expand All @@ -17,7 +17,7 @@ export async function registerStepByStep(context: IActionContext, node?: ApisTre
const apiCenterNode = await ext.treeDataProvider.showTreeItemPicker<ApiCenterTreeItem>(ApiCenterTreeItem.contextValue, context);
node = apiCenterNode.apisTreeItem;
}
if (node.apiCenter instanceof ApiCenterVersionDefinitionManagement) {
if (node.apiCenter instanceof ApiCenterVersionDefinitionDataPlane) {
return;
}

Check warning on line 22 in src/commands/registerApiSubCommands/registerStepByStep.ts

View check run for this annotation

Codecov / codecov/patch

src/commands/registerApiSubCommands/registerStepByStep.ts#L20-L22

Added lines #L20 - L22 were not covered by tests

Expand Down
68 changes: 33 additions & 35 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,13 @@ import { searchApi } from './commands/searchApi';
import { setApiRuleset } from './commands/setApiRuleset';
import { SignInToDataPlane } from "./commands/signInToDataPlane";

Check warning on line 40 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L40

Added line #L40 was not covered by tests
import { testInPostman } from './commands/testInPostman';
import { ErrorProperties, TelemetryProperties } from './common/telemetryEvent';
import { doubleClickDebounceDelay, selectedNodeKey } from './constants';
import { ext } from './extensionVariables';
import { ApiVersionDefinitionTreeItem } from './tree/ApiVersionDefinitionTreeItem';
import { createAzureAccountTreeItem } from "./tree/AzureAccountTreeItem";
import { createAzureDataAccountTreeItem } from './tree/DataPlaneAccount';

Check warning on line 47 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L47

Added line #L47 was not covered by tests
import { OpenApiEditor } from './tree/Editors/openApi/OpenApiEditor';
// Copilot Chat
import { ErrorProperties, TelemetryProperties } from './common/telemetryEvent';
export async function activate(context: vscode.ExtensionContext) {
console.log('Congratulations, your extension "azure-api-center" is now active!');

Expand All @@ -60,39 +59,8 @@ export async function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(ext.outputChannel);
registerAzureUtilsExtensionVariables(ext);

AzureSessionProviderHelper.activateAzureSessionProvider(context);
const sessionProvider = AzureSessionProviderHelper.getSessionProvider();

const azureAccountTreeItem = createAzureAccountTreeItem(sessionProvider);
context.subscriptions.push(azureAccountTreeItem);
ext.treeItem = azureAccountTreeItem;
// var a = ext.treeItem.subscription;
ext.dataPlaneAccounts = [];
const treeDataProvider = new AzExtTreeDataProvider(azureAccountTreeItem, "appService.loadMore");

ext.treeItem = azureAccountTreeItem;

ext.treeDataProvider = treeDataProvider;

const treeView = vscode.window.createTreeView("apiCenterTreeView", { treeDataProvider });
context.subscriptions.push(treeView);

AzureDataSessionProviderHelper.activateAzureSessionProvider(context);
const dataPlaneSessionProvider = AzureDataSessionProviderHelper.getSessionProvider();
const dataPlanAccountManagerTreeItem = createAzureDataAccountTreeItem(dataPlaneSessionProvider);
context.subscriptions.push(dataPlanAccountManagerTreeItem);
ext.workspaceItem = dataPlanAccountManagerTreeItem;

const workspaceTreeDataProvider = new AzExtTreeDataProvider(dataPlanAccountManagerTreeItem, "appService.loadMore");
ext.workspaceProvider = workspaceTreeDataProvider;

vscode.window.registerTreeDataProvider('apiCenterWorkspace', workspaceTreeDataProvider);

treeView.onDidChangeSelection((e: vscode.TreeViewSelectionChangeEvent<AzExtTreeItem>) => {
const selectedNode = e.selection[0];
ext.outputChannel.appendLine(selectedNode.id!);
ext.context.globalState.update(selectedNodeKey, selectedNode.id);
});
setupControlView(context);
setupDataTreeView(context);

Check warning on line 63 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L62-L63

Added lines #L62 - L63 were not covered by tests

// Register API Center extension commands

Expand Down Expand Up @@ -203,4 +171,34 @@ async function registerCommandWithTelemetry(commandId: string, callback: Command
}, debounce);
}

function setupControlView(context: vscode.ExtensionContext) {
AzureSessionProviderHelper.activateAzureSessionProvider(context);
const sessionProvider = AzureSessionProviderHelper.getSessionProvider();
const azureAccountTreeItem = createAzureAccountTreeItem(sessionProvider);
context.subscriptions.push(azureAccountTreeItem);
ext.treeItem = azureAccountTreeItem;
const treeDataProvider = new AzExtTreeDataProvider(azureAccountTreeItem, "appService.loadMore");
ext.treeItem = azureAccountTreeItem;
ext.treeDataProvider = treeDataProvider;
const treeView = vscode.window.createTreeView("apiCenterTreeView", { treeDataProvider });
context.subscriptions.push(treeView);
treeView.onDidChangeSelection((e: vscode.TreeViewSelectionChangeEvent<AzExtTreeItem>) => {
const selectedNode = e.selection[0];
ext.outputChannel.appendLine(selectedNode.id!);
ext.context.globalState.update(selectedNodeKey, selectedNode.id);
});
}

function setupDataTreeView(context: vscode.ExtensionContext) {
ext.dataPlaneAccounts = [];
AzureDataSessionProviderHelper.activateAzureSessionProvider(context);
const dataPlaneSessionProvider = AzureDataSessionProviderHelper.getSessionProvider();
const dataPlanAccountManagerTreeItem = createAzureDataAccountTreeItem(dataPlaneSessionProvider);
context.subscriptions.push(dataPlanAccountManagerTreeItem);
ext.workspaceItem = dataPlanAccountManagerTreeItem;
const workspaceTreeDataProvider = new AzExtTreeDataProvider(dataPlanAccountManagerTreeItem, "appService.loadMore");
ext.workspaceProvider = workspaceTreeDataProvider;
vscode.window.registerTreeDataProvider('apiCenterWorkspace', workspaceTreeDataProvider);
}

Check warning on line 203 in src/extension.ts

View check run for this annotation

Codecov / codecov/patch

src/extension.ts#L174-L203

Added lines #L174 - L203 were not covered by tests
export function deactivate() { }
1 change: 1 addition & 0 deletions src/uiStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,5 @@ export class UiStrings {
static readonly AddDataPlaneTenantId = vscode.l10n.t("Input Entra App Tenant ID");
static readonly RequestFailedWithStatusCode = vscode.l10n.t("Request failed with status code: {0}");
static readonly DownloadDefinitionFileWithErrorMsg = vscode.l10n.t("Download API Center Definition File error: {0}");
static readonly DatplaneAlreadyAdded = vscode.l10n.t("This Data Plane Runtime URL already added to Data View.");
}

0 comments on commit 405785a

Please sign in to comment.