-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathRevisionDraftUpdateBaseStep.ts
More file actions
77 lines (67 loc) · 3.99 KB
/
RevisionDraftUpdateBaseStep.ts
File metadata and controls
77 lines (67 loc) · 3.99 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
67
68
69
70
71
72
73
74
75
76
77
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { KnownActiveRevisionsMode, type Template } from "@azure/arm-appcontainers";
import { AzureWizardExecuteStep, callWithTelemetryAndErrorHandling, nonNullValueAndProp, type IActionContext } from "@microsoft/vscode-azext-utils";
import { ProgressLocation, window, type Progress } from "vscode";
import { ext } from "../../extensionVariables";
import { type ContainerAppItem } from "../../tree/ContainerAppItem";
import { type RevisionDraftItem } from "../../tree/revisionManagement/RevisionDraftItem";
import { type RevisionsItemModel } from "../../tree/revisionManagement/RevisionItem";
import { localize } from "../../utils/localize";
import { pickContainerAppWithoutPrompt } from "../../utils/pickItem/pickContainerApp";
import { pickRevisionDraft } from "../../utils/pickItem/pickRevision";
import { getParentResourceFromItem } from "../../utils/revisionDraftUtils";
import { deployRevisionDraft } from "./deployRevisionDraft/deployRevisionDraft";
import { type RevisionDraftContext } from "./RevisionDraftContext";
export abstract class RevisionDraftUpdateBaseStep<T extends RevisionDraftContext> extends AzureWizardExecuteStep<T> {
/**
* This property holds the active template revisions used for updating the revision draft
*/
protected revisionDraftTemplate: Template;
constructor(readonly baseItem: ContainerAppItem | RevisionsItemModel) {
super();
this.revisionDraftTemplate = this.initRevisionDraftTemplate();
}
abstract execute(context: T, progress: Progress<{ message?: string | undefined; increment?: number | undefined }>): Promise<void>;
abstract shouldExecute(context: T): boolean;
private initRevisionDraftTemplate(): Template {
let template: Template | undefined = ext.revisionDraftFileSystem.parseRevisionDraft(this.baseItem);
if (!template) {
// Make deep copies so we don't accidentally modify the cached values
template = JSON.parse(JSON.stringify(nonNullValueAndProp(getParentResourceFromItem(this.baseItem), 'template'))) as Template;
}
return template;
}
/**
* Call this method to upload `revisionDraftTemplate` changes to the container app revision draft
*/
protected async updateRevisionDraftWithTemplate(context: T): Promise<void> {
ext.revisionDraftFileSystem.updateRevisionDraftWithTemplate(this.baseItem, this.revisionDraftTemplate);
if (context.shouldDeployRevisionDraft) {
void this.deployRevisionDraftTemplate(context);
}
}
/**
* A deployment quick pick to show after executing a revision draft command
* (Used to be an informational deployment pop-up)
*/
private async deployRevisionDraftTemplate(context: T): Promise<void> {
const item: ContainerAppItem | RevisionDraftItem = await window.withProgress({
location: ProgressLocation.Notification,
cancellable: false,
title: localize('preparingForDeployment', 'Preparing for deployment...')
}, async () => {
const containerAppItem: ContainerAppItem = await pickContainerAppWithoutPrompt(context, this.baseItem.containerApp, { showLoadingPrompt: false });
if (this.baseItem.containerApp.revisionsMode === KnownActiveRevisionsMode.Single) {
return containerAppItem;
} else {
return await pickRevisionDraft(context, containerAppItem, { showLoadingPrompt: false });
}
});
// Pass the deploy command a fresh context
await callWithTelemetryAndErrorHandling('revisionDraftUpdateBaseStep.deploy',
async (context: IActionContext) => await deployRevisionDraft(context, item));
}
}