44 *--------------------------------------------------------------------------------------------*/
55
66import { KnownActiveRevisionsMode , type Revision } from "@azure/arm-appcontainers" ;
7+ import { ext } from "../extensionVariables" ;
78import { ContainerAppItem , type ContainerAppModel } from "../tree/ContainerAppItem" ;
9+ import { RevisionDraftItem } from "../tree/revisionManagement/RevisionDraftItem" ;
810import { 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