|
3 | 3 | * Licensed under the MIT License. See License.txt in the project root for license information. |
4 | 4 | *--------------------------------------------------------------------------------------------*/ |
5 | 5 |
|
| 6 | +import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers"; |
6 | 7 | import { IActionContext, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils"; |
7 | 8 | import { ProgressLocation, window } from "vscode"; |
8 | | -import { RevisionConstants, rootFilter } from "../constants"; |
9 | 9 | import { ext } from "../extensionVariables"; |
10 | | -import { ContainerAppTreeItem } from "../tree/ContainerAppTreeItem"; |
11 | | -import { RevisionsTreeItem } from "../tree/RevisionsTreeItem"; |
| 10 | +import { ContainerAppModel, refreshContainerApp } from "../tree/ContainerAppItem"; |
| 11 | +import { ContainerAppsItem } from "../tree/ContainerAppsBranchDataProvider"; |
12 | 12 | import { localize } from "../utils/localize"; |
13 | | -import { nonNullValue } from "../utils/nonNull"; |
| 13 | +import { pickContainerApp } from "../utils/pickContainerApp"; |
14 | 14 | import { updateContainerApp } from "./updateContainerApp"; |
15 | 15 |
|
16 | | -export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppTreeItem | RevisionsTreeItem): Promise<void> { |
17 | | - if (!node) { |
18 | | - node = await ext.rgApi.pickAppResource<ContainerAppTreeItem>(context, { |
19 | | - filter: rootFilter, |
20 | | - expectedChildContextValue: ContainerAppTreeItem.contextValueRegExp |
21 | | - }); |
22 | | - } |
| 16 | +export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppsItem): Promise<void> { |
| 17 | + const { subscription, containerApp } = node ?? await pickContainerApp(context); |
23 | 18 |
|
24 | | - if (node instanceof RevisionsTreeItem) { |
25 | | - node = node.parent; |
26 | | - } |
| 19 | + const pickedRevisionMode = await pickRevisionsMode(context, containerApp); |
| 20 | + // only update it if it's actually different |
| 21 | + if (containerApp.revisionsMode !== pickedRevisionMode) { |
| 22 | + const updating = localize('updatingRevision', 'Updating revision mode of "{0}" to "{1}"...', containerApp.name, pickedRevisionMode); |
| 23 | + ext.outputChannel.appendLog(updating); |
27 | 24 |
|
28 | | - const picks: IAzureQuickPickItem<string>[] = [RevisionConstants.single, RevisionConstants.multiple]; |
29 | | - const placeHolder = localize('chooseRevision', 'Choose revision mode'); |
| 25 | + await window.withProgress({ location: ProgressLocation.Notification, title: updating }, async (): Promise<void> => { |
| 26 | + await updateContainerApp(context, subscription, containerApp, { configuration: { activeRevisionsMode: pickedRevisionMode } }); |
| 27 | + refreshContainerApp(containerApp.id); |
| 28 | + }); |
30 | 29 |
|
31 | | - for (const pick of picks) { |
32 | | - pick.description = pick.data === node.getRevisionMode() ? localize('current', ' current') : undefined; |
| 30 | + const updated = localize('updatedRevision', 'Updated revision mode of "{0}" to "{1}".', containerApp.name, pickedRevisionMode); |
| 31 | + void window.showInformationMessage(updated); |
| 32 | + ext.outputChannel.appendLog(updated); |
33 | 33 | } |
| 34 | +} |
34 | 35 |
|
35 | | - const result = await context.ui.showQuickPick(picks, { placeHolder, suppressPersistence: true }); |
36 | | - |
37 | | - // only update it if it's actually different |
38 | | - if (node.getRevisionMode() !== result.data) { |
39 | | - const updating = localize('updatingRevision', 'Updating revision mode of "{0}" to "{1}"...', node.name, result.data); |
40 | | - const updated = localize('updatedRevision', 'Updated revision mode of "{0}" to "{1}".', node.name, result.data); |
| 36 | +function getRevisionsModePicks(containerApp: ContainerAppModel): IAzureQuickPickItem<KnownActiveRevisionsMode>[] { |
41 | 37 |
|
42 | | - await window.withProgress({ location: ProgressLocation.Notification, title: updating }, async (): Promise<void> => { |
43 | | - const pNode = nonNullValue(node) as ContainerAppTreeItem; |
44 | | - ext.outputChannel.appendLog(updating); |
| 38 | + function appendCurrent(description: string, revisionsMode: KnownActiveRevisionsMode): string { |
| 39 | + return revisionsMode === containerApp.revisionsMode ? `${description} (current)` : description; |
| 40 | + } |
45 | 41 |
|
46 | | - await updateContainerApp(context, pNode, { configuration: { activeRevisionsMode: result.data } }); |
47 | | - await node?.parent?.refresh(context); |
| 42 | + return [ |
| 43 | + { |
| 44 | + label: localize('multiple', 'Multiple'), |
| 45 | + description: appendCurrent(localize('multipleDesc', 'Several revisions active simultaneously'), KnownActiveRevisionsMode.Multiple), |
| 46 | + data: KnownActiveRevisionsMode.Multiple, |
| 47 | + }, |
| 48 | + { |
| 49 | + label: localize('single', 'Single'), |
| 50 | + description: appendCurrent(localize('singleDesc', 'One active revision at a time'), KnownActiveRevisionsMode.Single), |
| 51 | + data: KnownActiveRevisionsMode.Single, |
| 52 | + }, |
| 53 | + ]; |
| 54 | +} |
48 | 55 |
|
49 | | - void window.showInformationMessage(updated); |
50 | | - ext.outputChannel.appendLog(updated); |
51 | | - }); |
52 | | - } |
| 56 | +async function pickRevisionsMode(context: IActionContext, containerApp: ContainerAppModel): Promise<KnownActiveRevisionsMode> { |
| 57 | + const placeHolder = localize('chooseRevision', 'Choose revision mode'); |
| 58 | + const result = await context.ui.showQuickPick(getRevisionsModePicks(containerApp), { |
| 59 | + placeHolder, |
| 60 | + suppressPersistence: true, |
| 61 | + }); |
| 62 | + return result.data; |
53 | 63 | } |
0 commit comments