import { ProgressLocation , window } from "vscode" ; import { IActionContext } from "vscode-azureextensionui" ; import { ApiTreeItem } from "../explorer/ApiTreeItem" ; import { IProductTreeItemContext , ProductApisTreeItem } from "../explorer/ProductApisTreeItem" ; import { ProductsTreeItem } from "../explorer/ProductsTreeItem" ; import { ProductTreeItem } from "../explorer/ProductTreeItem" ; import { ServiceTreeItem } from "../explorer/ServiceTreeItem" ; import { ext } from "../extensionVariables" ; import { localize } from "../localize" ; import { nonNullProp } from "../utils/nonNull" ; export async function addApiToProduct ( context , node ? ) { let productNode ; if ( ! node ) { productNode = < ProductTreeItem > await ext . tree . showTreeItemPicker ( ProductTreeItem . contextValue , context ) ; node = productNode . productApisTreeItem ; } else { productNode = < ProductTreeItem > node . parent ; } const serviceTreeItem = < ServiceTreeItem > ( < ProductsTreeItem > < unknown > productNode . parent ) . parent ; const apiTreeItem = < ApiTreeItem > await ext . tree . showTreeItemPicker ( ApiTreeItem . contextValue , context , serviceTreeItem ) ; const apiName = nonNullProp ( apiTreeItem . apiContract , "name" ) ; context . apiName = apiName ; window . withProgress ( { location : ProgressLocation . Notification , title : localize ( "addApiToProduct" , `Adding API '${ apiName }' to product ${ node . root . productName } ...` ) , cancellable : false } , async ( ) => { return node ! . createChild ( context ) ; } ) . then ( async ( ) => { await node ! . refresh ( context ) ; window . showInformationMessage ( localize ( "addedApiToProduct" , `Added API '${ apiName }' to product ${ node ! . root . productName }.` ) ) ; } ) ; }