-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathchooseRevisionMode.ts
More file actions
66 lines (56 loc) · 3.38 KB
/
chooseRevisionMode.ts
File metadata and controls
66 lines (56 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode } from "@azure/arm-appcontainers";
import { IActionContext, IAzureQuickPickItem } from "@microsoft/vscode-azext-utils";
import { ProgressLocation, window } from "vscode";
import { ext } from "../extensionVariables";
import { ContainerAppModel, refreshContainerApp } from "../tree/ContainerAppItem";
import { ContainerAppsItem } from "../tree/ContainerAppsBranchDataProvider";
import { localize } from "../utils/localize";
import { pickContainerApp } from "../utils/pickContainerApp";
import { updateContainerApp } from "./updateContainerApp";
export async function chooseRevisionMode(context: IActionContext, node?: ContainerAppsItem): Promise<void> {
const { subscription, containerApp } = node ?? await pickContainerApp(context);
const pickedRevisionMode = await pickRevisionsMode(context, containerApp);
// only update it if it's actually different
if (containerApp.revisionsMode !== pickedRevisionMode) {
const updating = localize('updatingRevision', 'Updating revision mode of "{0}" to "{1}"...', containerApp.name, pickedRevisionMode);
ext.outputChannel.appendLog(updating);
await window.withProgress({ location: ProgressLocation.Notification, title: updating }, async (): Promise<void> => {
await updateContainerApp(context, subscription, containerApp, { configuration: { activeRevisionsMode: pickedRevisionMode } });
// TODO: scoped container app refresh
refreshContainerApp(containerApp.id);
// ext.state.notifyChildrenChanged(containerApp.managedEnvironmentId);
});
const updated = localize('updatedRevision', 'Updated revision mode of "{0}" to "{1}".', containerApp.name, pickedRevisionMode);
void window.showInformationMessage(updated);
ext.outputChannel.appendLog(updated);
}
}
function getRevisionsModePicks(containerApp: ContainerAppModel): IAzureQuickPickItem<KnownActiveRevisionsMode>[] {
function appendCurrent(description: string, revisionsMode: KnownActiveRevisionsMode): string {
return revisionsMode === containerApp.revisionsMode ? `${description} (current)` : description;
}
return [
{
label: localize('multiple', 'Multiple'),
description: appendCurrent(localize('multipleDesc', 'Several revisions active simultaneously'), KnownActiveRevisionsMode.Multiple),
data: KnownActiveRevisionsMode.Multiple,
},
{
label: localize('single', 'Single'),
description: appendCurrent(localize('singleDesc', 'One active revision at a time'), KnownActiveRevisionsMode.Single),
data: KnownActiveRevisionsMode.Single,
},
];
}
async function pickRevisionsMode(context: IActionContext, containerApp: ContainerAppModel): Promise<KnownActiveRevisionsMode> {
const placeHolder = localize('chooseRevision', 'Choose revision mode');
const result = await context.ui.showQuickPick(getRevisionsModePicks(containerApp), {
placeHolder,
suppressPersistence: true,
});
return result.data;
}