import { ApiManagementModels } from "@azure/arm-apimanagement" ; import { ProgressLocation , window } from "vscode" ; import { AzureParentTreeItem , AzureTreeItem , DialogResponses , ISubscriptionContext , UserCancelledError } from "vscode-azureextensionui" ; import { localize } from "../localize" ; import { OperationConsole } from "../operationConsole/OperationConsole" ; import { nonNullProp } from "../utils/nonNull" ; import { treeUtils } from "../utils/treeUtils" ; import { IApiTreeRoot } from "./IApiTreeRoot" ; import { IOperationTreeRoot } from "./IOperationTreeRoot" ; import { OperationPolicyTreeItem } from "./OperationPolicyTreeItem" ; export class ApiOperationTreeItem extends AzureParentTreeItem < IOperationTreeRoot > { public static contextValue : string = 'azureApiManagementApiOperation' ; public contextValue : string = ApiOperationTreeItem . contextValue ; public readonly commandId : string = 'azureApiManagement.showArmApiOperation' ; public readonly policyTreeItem : OperationPolicyTreeItem ; private _name : string ; private _label : string ; public get root ( ) : IOperationTreeRoot { return this . _root ; } public get iconPath ( ) : { light : string ; dark : string ; } { return treeUtils . getThemedIconPath ( 'op' ) ; } public get label ( ) : string { return this . _label ; } public get id ( ) : string { return this . _name ; } private _root : IOperationTreeRoot ; constructor ( parent , public readonly operationContract ) { super ( parent ) ; this . _root = this . createRoot ( parent . root ) ; this . policyTreeItem = new OperationPolicyTreeItem ( this ) ; this . _label = `[${ nonNullProp ( this . operationContract , 'method' ) }] ${ nonNullProp ( this . operationContract , 'displayName' ) }` ; this . _name = nonNullProp ( this . operationContract , 'name' ) ; } public async loadMoreChildrenImpl ( ) { return [ this . policyTreeItem ] ; } public hasMoreChildrenImpl ( ) { return false ; } public async deleteTreeItemImpl ( ) { const message = localize ( "confirmDeleteOperation" , `Are you sure you want to delete operation '${ this . root . opName }'?` ) ; const result = await window . showWarningMessage ( message , { modal : true } , DialogResponses . deleteResponse , DialogResponses . cancel ) ; if ( result === DialogResponses . deleteResponse ) { const deletingMessage = localize ( "" , `Deleting operation "${ this . root . opName }"...` ) ; await window . withProgress ( { location : ProgressLocation . Notification , title : deletingMessage } , async ( ) => { await this . root . client . apiOperation . deleteMethod ( this . root . resourceGroupName , this . root . serviceName , this . root . apiName , this . root . opName , '*' ) ; } ) ; window . showInformationMessage ( localize ( "deletedOperation" , `Successfully deleted API "${ this . root . apiName }".` ) ) ; } else { throw new UserCancelledError ( ) ; } } public async getOperationTestInfo ( ) { return await new OperationConsole ( ) . buildRequestInfo ( this . root ) ; } public async getOperationDebugInfo ( ) { return await new OperationConsole ( ) . buildDebugRequestInfo ( this . root ) ; } private createRoot ( subRoot ) { return Object . assign ( { } , < IApiTreeRoot > subRoot , { opName : nonNullProp ( this . operationContract , 'name' ) } ) ; } }