Skip to content

Commit

Permalink
Bugfix: Prevent delete a template when has children (#2479)
Browse files Browse the repository at this point in the history
* 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
leekelleher authored and nielslyngsoe committed Nov 4, 2024
1 parent c2befd8 commit 2a981d2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 0 deletions.
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';
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'),
};
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 };
3 changes: 3 additions & 0 deletions src/packages/templating/templates/conditions/manifests.ts
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];
2 changes: 2 additions & 0 deletions src/packages/templating/templates/entity-actions/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS, UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS } from '../repository/index.js';
import { UMB_TEMPLATE_ENTITY_TYPE, UMB_TEMPLATE_ROOT_ENTITY_TYPE } from '../entity.js';
import { UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS } from '../conditions/allow-delete/const.js';

export const manifests: Array<UmbExtensionManifest> = [
{
Expand All @@ -26,5 +27,6 @@ export const manifests: Array<UmbExtensionManifest> = [
detailRepositoryAlias: UMB_TEMPLATE_DETAIL_REPOSITORY_ALIAS,
itemRepositoryAlias: UMB_TEMPLATE_ITEM_REPOSITORY_ALIAS,
},
conditions: [{ alias: UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS }],
},
];
2 changes: 2 additions & 0 deletions src/packages/templating/templates/manifests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { manifests as conditionsManifests } from './conditions/manifests.js';
import { manifests as entityActionsManifests } from './entity-actions/manifests.js';
import { manifests as menuManifests } from './menu/manifests.js';
import { manifests as modalManifests } from './modals/manifests.js';
Expand All @@ -7,6 +8,7 @@ import { manifests as treeManifests } from './tree/manifests.js';
import { manifests as workspaceManifests } from './workspace/manifests.js';

export const manifests: Array<UmbExtensionManifest> = [
...conditionsManifests,
...entityActionsManifests,
...menuManifests,
...modalManifests,
Expand Down

0 comments on commit 2a981d2

Please sign in to comment.