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.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
export const UMB_TEMPLATE_ALLOW_DELETE_ACTION_CONDITION_ALIAS = 'Umb.Condition.Template.AllowDeleteAction';
|
||||
@@ -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'),
|
||||
};
|
||||
@@ -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 };
|
||||
@@ -0,0 +1,3 @@
|
||||
import { manifest as templateAllowDeleteActionCondition } from './allow-delete/manifest.js';
|
||||
|
||||
export const manifests: Array<UmbExtensionManifest> = [templateAllowDeleteActionCondition];
|
||||
@@ -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> = [
|
||||
{
|
||||
@@ -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 }],
|
||||
},
|
||||
];
|
||||
|
||||
@@ -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';
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user