-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix: Prevent delete a template when has children (#2479)
* Adds "Template Has No Children Condition" to prevent the "delete" action being displayed for templates that have child templates. * Removed condition config type it didn't have any configurable properties. Lazy-loaded the manifest api. * Renamed "Template Has No Children" condition to "Template Allow Delete Action" condition.
- Loading branch information
1 parent
c2befd8
commit 2a981d2
Showing
6 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/packages/templating/templates/conditions/allow-delete/const.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS = 'Umb.Condition.Template.AllowDeleteAction'; |
8 changes: 8 additions & 0 deletions
8
src/packages/templating/templates/conditions/allow-delete/manifest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from './const.js'; | ||
|
||
export const manifest: UmbExtensionManifest = { | ||
type: 'condition', | ||
name: 'Template Allow Delete Action Condition', | ||
alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS, | ||
api: () => import('./template-allow-delete-action.condition.js'), | ||
}; |
22 changes: 22 additions & 0 deletions
22
...es/templating/templates/conditions/allow-delete/template-allow-delete-action.condition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry'; | ||
import { UMB_TREE_ITEM_CONTEXT } from '@umbraco-cms/backoffice/tree'; | ||
import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api'; | ||
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; | ||
|
||
export class UmbTemplateAllowDeleteActionCondition extends UmbConditionBase<never> implements UmbExtensionCondition { | ||
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<never>) { | ||
super(host, args); | ||
|
||
this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => { | ||
this.observe( | ||
context.hasChildren, | ||
(hasChildren) => { | ||
this.permitted = hasChildren === false; | ||
}, | ||
'_templateAllowDeleteActionCondition', | ||
); | ||
}); | ||
} | ||
} | ||
|
||
export { UmbTemplateAllowDeleteActionCondition as api }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { manifest as templateAllowDeleteActionCondition } from './allow-delete/manifest.js'; | ||
|
||
export const manifests: Array<UmbExtensionManifest> = [templateAllowDeleteActionCondition]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters