import type { ApplicationInsightsManagementClient } from "@azure/arm-appinsights" ; import type { ApplicationInsightsComponent , ApplicationInsightsComponentListResult } from "@azure/arm-appinsights/esm/models" ; import { AzureWizardPromptStep , IAzureNamingRules , IAzureQuickPickItem , IAzureQuickPickOptions , IWizardOptions , LocationListStep } from "vscode-azureextensionui" ; import { localize } from "../localize" ; import { createAppInsightsClient } from "../utils/azureClients" ; import { nonNullProp } from "../utils/nonNull" ; import { AppInsightsCreateStep } from "./AppInsightsCreateStep" ; import { AppInsightsNameStep } from "./AppInsightsNameStep" ; import { IAppServiceWizardContext } from "./IAppServiceWizardContext" ; export const appInsightsNamingRules = { minLength : 1 , maxLength : 255 , invalidCharsRegExp : /[^a-zA-Z0-9\.\_\-\(\)]/ } ; const skipForNowLabel = '$(clock) Skip for now' ; export class AppInsightsListStep extends AzureWizardPromptStep < IAppServiceWizardContext > { private _suppressCreate : boolean | undefined ; public constructor ( suppressCreate ? ) { super ( ) ; this . _suppressCreate = suppressCreate ; } public static async getAppInsightsComponents ( context ) { if ( context . appInsightsTask === undefined ) { const client = await createAppInsightsClient ( context ) ; context . appInsightsTask = client . components . list ( ) ; } return await context . appInsightsTask ; } public async prompt ( context ) { const options = { placeHolder : 'Select an Application Insights resource for your app.' , id : `AppInsightsListStep/${ context . subscriptionId }` } ; const input = ( await context . ui . showQuickPick ( this . getQuickPicks ( context ) , options ) ) ; context . appInsightsComponent = input . data ; if ( input . label === skipForNowLabel ) { context . telemetry . properties . aiSkipForNow = 'true' ; context . appInsightsSkip = true ; } else { context . telemetry . properties . newAI = String ( ! context . appInsightsComponent ) ; } } public shouldPrompt ( context ) { return ! context . appInsightsComponent ; } public async getSubWizard ( context ) { if ( context . appInsightsComponent ) { context . valuesToMask . push ( nonNullProp ( context . appInsightsComponent , 'name' ) ) ; } else if ( ! context . appInsightsSkip ) { const promptSteps = [ new AppInsightsNameStep ( ) ] ; LocationListStep . addStep ( context , promptSteps ) ; return { promptSteps : promptSteps , executeSteps : [ new AppInsightsCreateStep ( ) ] } ; } return undefined ; } private async getQuickPicks ( context ) { const picks = ! this . _suppressCreate ? [ { label : localize ( 'newApplicationInsight' , '$(plus) Create new Application Insights resource' ) , data : undefined } ] : [ ] ; picks . push ( { label : localize ( 'skipForNow' , skipForNowLabel ) , data : undefined } ) ; let components = await AppInsightsListStep . getAppInsightsComponents ( context ) ; if ( ! Array . isArray ( components ) ) { components = [ ] ; } return picks . concat ( components . map ( ( ai ) => { return { id : ai . id , label : nonNullProp ( ai , 'name' ) , description : ai . location , data : ai } ; } ) ) ; } }