import { ApiCollection } from "@azure/arm-apimanagement/src/models" ; import { IActionContext } from "vscode-azureextensionui" ; import { ApisTreeItem } from "../explorer/ApisTreeItem" ; import { ServiceTreeItem } from '../explorer/ServiceTreeItem' ; import { ext } from "../extensionVariables" ; export async function addApiFilter ( context , node ? ) { if ( ! node ) { const serviceNode = < ServiceTreeItem > await ext . tree . showTreeItemPicker ( ServiceTreeItem . contextValue , context ) ; node = serviceNode . apisTreeItem ; } let nextLink ; const apiCollection = nextLink === undefined ? await node . root . client . api . listByService ( node . root . resourceGroupName , node . root . serviceName , { expandApiVersionSet : false , top : 100 } ) : await node . root . client . api . listByServiceNext ( nextLink ) ; while ( nextLink !== undefined ) { const curApiCollection = await node . root . client . api . listByServiceNext ( nextLink ) ; nextLink = curApiCollection . nextLink ; apiCollection . concat ( curApiCollection ) ; } const apis = apiCollection . map ( ( s ) => { return s ; } ) . filter ( ( s ) => ( s . isCurrent !== undefined && s . isCurrent === true ) ) ; const picks = await ext . ui . showQuickPick ( apis . map ( ( s ) => { let apiName = s . displayName ! ; if ( s . apiVersionSetId !== undefined ) { if ( s . apiVersion !== undefined ) { apiName = apiName . concat ( " (VersionSet) - " , s . apiVersion ) ; } else { apiName = apiName . concat ( " (VersionSet) - Original" ) ; } } let picked = false ; for ( const api of node ! . selectedApis ) { if ( api . name ! === s . name ! ) { picked = true ; } } return { label : apiName , api : s , picked : picked } ; } ) , { canPickMany : true , placeHolder : 'Select APIs' } ) ; node . selectedApis = picks . map ( ( s ) => s . api ) ; await node ! . refresh ( context ) ; }