-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathDeleteScaleRuleStep.ts
More file actions
37 lines (29 loc) · 1.78 KB
/
DeleteScaleRuleStep.ts
File metadata and controls
37 lines (29 loc) · 1.78 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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { nonNullValueAndProp } from "@microsoft/vscode-azext-utils";
import { ext } from "../../../../extensionVariables";
import { type RevisionsItemModel } from "../../../../tree/revisionManagement/RevisionItem";
import { localize } from "../../../../utils/localize";
import { getParentResourceFromItem } from "../../../../utils/revisionDraftUtils";
import { RevisionDraftUpdateBaseStep } from "../../../revisionDraft/RevisionDraftUpdateBaseStep";
import { type ScaleRuleContext } from "../ScaleRuleContext";
export class DeleteScaleRuleStep<T extends ScaleRuleContext> extends RevisionDraftUpdateBaseStep<T> {
public priority: number = 100;
constructor(baseItem: RevisionsItemModel) {
super(baseItem);
}
public async execute(context: T): Promise<void> {
this.revisionDraftTemplate.scale ||= {};
this.revisionDraftTemplate.scale.rules ||= [];
const index = this.revisionDraftTemplate.scale.rules.findIndex(r => r.name === nonNullValueAndProp(context.scaleRule, 'name'));
this.revisionDraftTemplate.scale.rules.splice(index, 1);
await this.updateRevisionDraftWithTemplate(context);
const resourceName = getParentResourceFromItem(this.baseItem).name;
ext.outputChannel.appendLog(localize('deletedScaleRule', 'Deleted rule "{0}" from "{1}" (draft).', context.scaleRule?.name, resourceName));
}
public shouldExecute(context: T): boolean {
return !!context.scaleRule;
}
}