33* Licensed under the MIT License. See License.txt in the project root for license information.
44*--------------------------------------------------------------------------------------------*/
55
6- import { AzureResourceQuickPickWizardContext , AzureWizardPromptStep , ContextValueQuickPickStep , IActionContext , QuickPickAzureResourceStep , QuickPickAzureSubscriptionStep , QuickPickGroupStep , ResourceGroupsItem , runQuickPickWizard } from "@microsoft/vscode-azext-utils" ;
6+ import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers" ;
7+ import { AzureResourceQuickPickWizardContext , AzureWizardPromptStep , ContextValueQuickPickStep , IActionContext , QuickPickAzureResourceStep , QuickPickAzureSubscriptionStep , QuickPickGroupStep , ResourceGroupsItem , nonNullValue , runQuickPickWizard } from "@microsoft/vscode-azext-utils" ;
78import { AzExtResourceType } from "@microsoft/vscode-azureresources-api" ;
89import * as vscode from 'vscode' ;
10+ import { revisionModeMultipleContextValue , revisionModeSingleContextValue } from "../constants" ;
911import { ext } from "../extensionVariables" ;
1012import { ContainerAppItem } from "../tree/ContainerAppItem" ;
1113import { ManagedEnvironmentItem } from "../tree/ManagedEnvironmentItem" ;
@@ -15,6 +17,10 @@ export interface PickItemOptions {
1517 title ?: string ;
1618}
1719
20+ export interface ContainerAppPickItemOptions extends PickItemOptions {
21+ revisionsMode ?: KnownActiveRevisionsMode ;
22+ }
23+
1824function getPickEnvironmentSteps ( tdp : vscode . TreeDataProvider < unknown > ) : AzureWizardPromptStep < AzureResourceQuickPickWizardContext > [ ] {
1925 const types = [ AzExtResourceType . ContainerAppsEnvironment ] ;
2026 return [
@@ -26,25 +32,41 @@ function getPickEnvironmentSteps(tdp: vscode.TreeDataProvider<unknown>): AzureWi
2632 resourceTypes : types ,
2733 skipIfOne : false ,
2834 } , {
29- placeHolder : localize ( 'selectContainerAppsEnvironment' , 'Select Container Apps Environment ' ) ,
35+ placeHolder : localize ( 'selectContainerAppsEnvironment' , 'Select a container apps environment ' ) ,
3036 } ) ,
3137 ] ;
3238}
3339
34- export async function pickContainerApp ( context : IActionContext , options ?: PickItemOptions ) : Promise < ContainerAppItem > {
40+ export async function pickContainerApp ( context : IActionContext , options ?: ContainerAppPickItemOptions ) : Promise < ContainerAppItem > {
3541 return await containerAppExperience < ContainerAppItem > ( context , ext . rgApiV2 . resources . azureResourceTreeDataProvider , options ) ;
3642}
3743
38- export async function containerAppExperience < TPick > ( context : IActionContext , tdp : vscode . TreeDataProvider < ResourceGroupsItem > , options ?: PickItemOptions ) : Promise < TPick > {
44+ export async function containerAppExperience < TPick > ( context : IActionContext , tdp : vscode . TreeDataProvider < ResourceGroupsItem > , options ?: ContainerAppPickItemOptions ) : Promise < TPick > {
45+ const contextFilter : RegExp [ ] | undefined = [ ] ;
46+ let noPicksMessage : string | undefined ;
47+
48+ // Todo: Refactor when QuickPickStep logic supports matching 'allOf' vs 'anyOf' a RegExp[] filter
49+ // Bit of a workaround for now - would ideally be able to match more than one filter value, equivalent to enable something like /containerAppItem(.*)revisionMode:single/i
50+ if ( options ?. revisionsMode === KnownActiveRevisionsMode . Single ) {
51+ contextFilter . push ( new RegExp ( revisionModeSingleContextValue ) ) ;
52+ noPicksMessage = localize ( 'noSingleRevisionApps' , 'Selected environment has no container apps in single revisions mode.' ) ;
53+ } else if ( options ?. revisionsMode === KnownActiveRevisionsMode . Multiple ) {
54+ contextFilter . push ( new RegExp ( revisionModeMultipleContextValue ) ) ;
55+ noPicksMessage = localize ( 'noMultipleRevisionApps' , 'Selected environment has no container apps in multiple revisions mode.' ) ;
56+ } else {
57+ contextFilter . push ( ContainerAppItem . contextValueRegExp ) ;
58+ noPicksMessage = localize ( 'noContainerApps' , 'Selected environment has no container apps.' ) ;
59+ }
60+
3961 return await runQuickPickWizard ( context , {
4062 promptSteps : [
4163 ...getPickEnvironmentSteps ( tdp ) ,
4264 new ContextValueQuickPickStep ( tdp , {
43- contextValueFilter : { include : ContainerAppItem . contextValueRegExp } ,
65+ contextValueFilter : { include : nonNullValue ( contextFilter ) } ,
4466 skipIfOne : true ,
4567 } , {
46- placeHolder : localize ( 'selectContainerApp' , 'Select Container App ' ) ,
47- noPicksMessage : localize ( 'noContainerApps' , 'Selected Container Apps Environment has no Apps' ) ,
68+ placeHolder : localize ( 'selectContainerApp' , 'Select a container app ' ) ,
69+ noPicksMessage,
4870 } ) ,
4971 ] ,
5072 title : options ?. title ,
0 commit comments