import { ApiManagementModels } from "@azure/arm-apimanagement" ; import { ProgressLocation , window } from "vscode" ; import { AzureParentTreeItem , AzureTreeItem , DialogResponses , UserCancelledError } from "vscode-azureextensionui" ; import { localize } from "../localize" ; import { nonNullProp } from "../utils/nonNull" ; import { treeUtils } from "../utils/treeUtils" ; import { IProductTreeRoot } from "./IProductTreeRoot" ; export class ProductApiTreeItem extends AzureTreeItem < IProductTreeRoot > { public static contextValue : string = 'azureApiManagementProductApi' ; public contextValue : string = ProductApiTreeItem . contextValue ; private _label : string ; constructor ( parent , public readonly productApiContract ) { super ( parent ) ; this . _label = nonNullProp ( productApiContract , 'displayName' ) ; } public get label ( ) : string { return this . _label ; } public get iconPath ( ) : { light : string ; dark : string ; } { return treeUtils . getThemedIconPath ( 'api' ) ; } public async deleteTreeItemImpl ( ) { const message = localize ( "confirmProductAPIRemove" , `Are you sure you want to remove API '${ this . productApiContract . displayName }' from product '${ this . root . productName }'?` ) ; const result = await window . showWarningMessage ( message , { modal : true } , DialogResponses . deleteResponse , DialogResponses . cancel ) ; if ( result === DialogResponses . deleteResponse ) { const deletingMessage = localize ( "removingProductAPI" , `Removing API "${ this . productApiContract . displayName }" from product '${ this . root . productName }.'` ) ; await window . withProgress ( { location : ProgressLocation . Notification , title : deletingMessage } , async ( ) => { await this . root . client . productApi . deleteMethod ( this . root . resourceGroupName , this . root . serviceName , this . root . productName , nonNullProp ( this . productApiContract , "name" ) ) ; } ) ; window . showInformationMessage ( localize ( "removedProduct" , `Successfully removed API "${ this . productApiContract . displayName }" from product '${ this . root . productName }'.` ) ) ; } else { throw new UserCancelledError ( ) ; } } }