Skip to content

Commit 5e9aa0e

Browse files
authored
Don't show editScalingRange on another ScaleItem if a draft item already exists (#758)
1 parent 8116b95 commit 5e9aa0e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/commands/scaling/scaleRange/editScaleRange.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { type ScaleItem } from "../../../tree/scaling/ScaleItem";
1010
import { createActivityContext } from "../../../utils/activityUtils";
1111
import { localize } from "../../../utils/localize";
1212
import { pickScale } from "../../../utils/pickItem/pickScale";
13-
import { getParentResource } from "../../../utils/revisionDraftUtils";
13+
import { getParentResource, isTemplateItemEditable, throwTemplateItemNotEditable } from "../../../utils/revisionDraftUtils";
1414
import { type ScaleRangeContext } from "./ScaleRangeContext";
1515
import { ScaleRangePromptStep } from "./ScaleRangePromptStep";
1616
import { ScaleRangeUpdateStep } from "./ScaleRangeUpdateStep";
@@ -19,6 +19,10 @@ export async function editScaleRange(context: IActionContext, node?: ScaleItem):
1919
const item: ScaleItem = node ?? await pickScale(context, { autoSelectDraft: true });
2020
const { containerApp, revision, subscription } = item;
2121

22+
if (!isTemplateItemEditable(item)) {
23+
throwTemplateItemNotEditable(item);
24+
}
25+
2226
const parentResource: ContainerAppModel | Revision = getParentResource(containerApp, revision);
2327
const scale: Scale = nonNullValueAndProp(parentResource.template, 'scale');
2428

src/utils/revisionDraftUtils.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
*--------------------------------------------------------------------------------------------*/
55

66
import { KnownActiveRevisionsMode, type Revision } from "@azure/arm-appcontainers";
7+
import { ext } from "../extensionVariables";
78
import { ContainerAppItem, type ContainerAppModel } from "../tree/ContainerAppItem";
9+
import { RevisionDraftItem } from "../tree/revisionManagement/RevisionDraftItem";
810
import { type RevisionsItemModel } from "../tree/revisionManagement/RevisionItem";
11+
import { localize } from "./localize";
912

1013
/**
1114
* Use to always select the correct parent resource model
@@ -26,3 +29,24 @@ export function getParentResourceFromItem(item: ContainerAppItem | RevisionsItem
2629
return item.revision;
2730
}
2831
}
32+
33+
/**
34+
* Checks to see whether a given container app template item is in an editable state
35+
* (Template item here refers to any tree item descendant of the RevisionItem - see 'RevisionItem.getTemplateChildren')
36+
* (The name template originates from the container app envelope's 'template' set of properties which happen to also be tied to each revision)
37+
*/
38+
export function isTemplateItemEditable(item: RevisionsItemModel): boolean {
39+
// Rule 1: Single revision edits are always okay
40+
// Rule 2: If in multiple revisions mode and no draft is in session, revision edits are always okay
41+
// Rule 3: If in multiple revisions mode and a draft is in session, do not allow any other edits besides those on the draft item
42+
return item.containerApp.revisionsMode === KnownActiveRevisionsMode.Single ||
43+
!ext.revisionDraftFileSystem.doesContainerAppsItemHaveRevisionDraft(item) ||
44+
RevisionDraftItem.hasDescendant(item);
45+
}
46+
47+
/**
48+
* If a template item is not editable, throw this error to cancel and alert the user
49+
*/
50+
export function throwTemplateItemNotEditable(item: RevisionsItemModel) {
51+
throw new Error(localize('itemNotEditable', 'Action cannot be performed on revision "{0}" because a draft is currently active.', item.revision.name));
52+
}

0 commit comments

Comments
 (0)