Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Prevent delete a template when has children #2479

Merged
merged 3 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/packages/templating/templates/conditions/const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const UMB_TEMPLATE_HAS_NO_CHILDREN_CONDITION_ALIAS = 'Umb.Condition.TemplateHasNoChildren';
1 change: 1 addition & 0 deletions src/packages/templating/templates/conditions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type * from './types.js';
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 templateHasNoChildrenCondition } from './template-has-no-children.condition.js';

export const manifests: Array<UmbExtensionManifest> = [templateHasNoChildrenCondition];
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { UMB_TEMPLATE_HAS_NO_CHILDREN_CONDITION_ALIAS } from './const.js';
import type { UmbTemplateHasNoChildrenConditionConfig } from './types.js';
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';

const ObserveSymbol = Symbol();

export class UmbTemplateHasNoChildrenCondition
extends UmbConditionBase<UmbTemplateHasNoChildrenConditionConfig>
implements UmbExtensionCondition
{
constructor(host: UmbControllerHost, args: UmbConditionControllerArguments<UmbTemplateHasNoChildrenConditionConfig>) {
super(host, args);

this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => {
this.observe(
context.hasChildren,
(hasChildren) => {
this.permitted = hasChildren === false;
},
ObserveSymbol,
);
});
}
}

export const manifest: UmbExtensionManifest = {
type: 'condition',
name: 'Template Has No Children Condition',
alias: UMB_TEMPLATE_HAS_NO_CHILDREN_CONDITION_ALIAS,
api: UmbTemplateHasNoChildrenCondition,
};
12 changes: 12 additions & 0 deletions src/packages/templating/templates/conditions/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { UMB_TEMPLATE_HAS_NO_CHILDREN_CONDITION_ALIAS } from './const.js';
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';

export type UmbTemplateHasNoChildrenConditionConfig = UmbConditionConfigBase<
typeof UMB_TEMPLATE_HAS_NO_CHILDREN_CONDITION_ALIAS
>;

declare global {
interface UmbExtensionConditionConfigMap {
umbTemplateHasNoChildren: UmbTemplateHasNoChildrenConditionConfig;
}
}
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_HAS_NO_CHILDREN_CONDITION_ALIAS } from '../conditions/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_HAS_NO_CHILDREN_CONDITION_ALIAS }],
},
];
1 change: 1 addition & 0 deletions src/packages/templating/templates/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import './global-components/index.js';

export * from './conditions/index.js';
export * from './global-components/index.js';
export * from './entity.js';
export * from './modals/index.js';
Expand Down
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
Loading