From 65d2edc288110cb9259aa2d0bb37f54717a4eb97 Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Mon, 28 Oct 2024 22:49:05 +0100 Subject: [PATCH] setup common action and generic modal --- .../common/create/create.action.kind.ts | 22 +++++++++ .../common/create/create.action.ts | 20 ++++++++ .../core/entity-action/common/create/index.ts | 1 + .../entity-action/common/create/manifests.ts | 4 ++ .../common/create/modal/constants.ts | 1 + ...create-option-action-list-modal.element.ts | 37 ++++++++++++++ ...y-create-option-action-list-modal.token.ts | 20 ++++++++ .../common/create/modal/index.ts | 2 + .../common/create/modal/manifests.ts | 10 ++++ .../core/entity-action/common/create/types.ts | 16 ++++++ .../core/entity-action/common/index.ts | 3 +- .../packages/core/entity-action/manifests.ts | 3 ++ .../create/create-user-entity-action.ts | 21 -------- .../user/entity-actions/create/manifests.ts | 11 +---- .../user/entity-actions/create/modal/index.ts | 8 --- .../entity-actions/create/modal/manifests.ts | 8 --- .../user-create-options-modal.element.ts | 49 ------------------- 17 files changed, 139 insertions(+), 97 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.kind.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/index.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/manifests.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/constants.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.element.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.token.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/index.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/manifests.ts create mode 100644 src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/types.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/create-user-entity-action.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/index.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/manifests.ts delete mode 100644 src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/user-create-options-modal.element.ts diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.kind.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.kind.ts new file mode 100644 index 0000000000..a220d955aa --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.kind.ts @@ -0,0 +1,22 @@ +import { UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST } from '../../default/default.action.kind.js'; +import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; + +export const manifest: UmbExtensionManifestKind = { + type: 'kind', + alias: 'Umb.Kind.EntityAction.Create', + matchKind: 'create', + matchType: 'entityAction', + manifest: { + ...UMB_ENTITY_ACTION_DEFAULT_KIND_MANIFEST.manifest, + type: 'entityAction', + kind: 'create', + api: () => import('./create.action.js'), + weight: 1200, + forEntityTypes: [], + meta: { + icon: 'icon-add', + label: '#actions_create', + additionalOptions: true, + }, + }, +}; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.ts new file mode 100644 index 0000000000..35f0dda58a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/create.action.ts @@ -0,0 +1,20 @@ +import { UmbEntityActionBase } from '../../entity-action-base.js'; +import type { MetaEntityActionCreateKind } from './types.js'; +import { UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL } from './modal/index.js'; +import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; + +export class UmbCreateEntityAction extends UmbEntityActionBase { + override async execute() { + const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); + const modalContext = modalManager.open(this, UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL, { + data: { + unique: this.args.unique, + entityType: this.args.entityType, + }, + }); + + await modalContext.onSubmit(); + } +} + +export { UmbCreateEntityAction as api }; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/index.ts new file mode 100644 index 0000000000..d44c5eca74 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/index.ts @@ -0,0 +1 @@ +export { UmbCreateEntityAction } from './create.action.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/manifests.ts new file mode 100644 index 0000000000..d1e496f559 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/manifests.ts @@ -0,0 +1,4 @@ +import { manifest as createKindManifest } from './create.action.kind.js'; +import { manifests as modalManifests } from './modal/manifests.js'; + +export const manifests = [createKindManifest, ...modalManifests]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/constants.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/constants.ts new file mode 100644 index 0000000000..ab81577a04 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/constants.ts @@ -0,0 +1 @@ +export const UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL_ALIAS = 'Umb.Modal.Entity.CreateOptionActionList'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.element.ts new file mode 100644 index 0000000000..e9ada04e69 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.element.ts @@ -0,0 +1,37 @@ +import type { + UmbEntityCreateOptionActionListModalData, + UmbEntityCreateOptionActionListModalValue, +} from './entity-create-option-action-list-modal.token.js'; +import { html, customElement } from '@umbraco-cms/backoffice/external/lit'; +import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; + +const elementName = 'umb-entity-create-option-action-list-modal'; +@customElement(elementName) +export class UmbEntityCreateOptionActionListModalElement extends UmbModalBaseElement< + UmbEntityCreateOptionActionListModalData, + UmbEntityCreateOptionActionListModalValue +> { + override render() { + return html` + + + + + + + `; + } +} + +export { UmbEntityCreateOptionActionListModalElement as element }; + +declare global { + interface HTMLElementTagNameMap { + [elementName]: UmbEntityCreateOptionActionListModalElement; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.token.ts new file mode 100644 index 0000000000..dd1aba66b4 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/entity-create-option-action-list-modal.token.ts @@ -0,0 +1,20 @@ +import { UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL_ALIAS } from './constants.js'; +import type { UmbEntityUnique } from '@umbraco-cms/backoffice/entity'; +import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; + +export interface UmbEntityCreateOptionActionListModalData { + unique: UmbEntityUnique; + entityType: string; +} + +export type UmbEntityCreateOptionActionListModalValue = never; + +export const UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL = new UmbModalToken< + UmbEntityCreateOptionActionListModalData, + UmbEntityCreateOptionActionListModalValue +>(UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL_ALIAS, { + modal: { + type: 'sidebar', + size: 'small', + }, +}); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/index.ts new file mode 100644 index 0000000000..876d392b23 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/index.ts @@ -0,0 +1,2 @@ +export * from './constants.js'; +export * from './entity-create-option-action-list-modal.token.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/manifests.ts new file mode 100644 index 0000000000..2b6ee6ed47 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/modal/manifests.ts @@ -0,0 +1,10 @@ +import { UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL_ALIAS } from './constants.js'; + +export const manifests: Array = [ + { + type: 'modal', + alias: UMB_ENTITY_CREATE_OPTION_ACTION_LIST_MODAL_ALIAS, + name: 'Entity Create Option Action List Modal', + element: () => import('./entity-create-option-action-list-modal.element.js'), + }, +]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/types.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/types.ts new file mode 100644 index 0000000000..7d102e750a --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/create/types.ts @@ -0,0 +1,16 @@ +import type { MetaEntityActionDefaultKind } from '../../default/index.js'; +import type { ManifestEntityAction } from '../../entity-action.extension.js'; + +export interface ManifestEntityActionCreateKind extends ManifestEntityAction { + type: 'entityAction'; + kind: 'create'; +} + +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +export interface MetaEntityActionCreateKind extends MetaEntityActionDefaultKind {} + +declare global { + interface UmbExtensionManifestMap { + umbEntityActionCreateKind: ManifestEntityActionCreateKind; + } +} diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/index.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/index.ts index 30877954f8..5a7c2ae86b 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/common/index.ts @@ -1,2 +1,3 @@ -export * from './duplicate/index.js'; +export * from './create/index.js'; export * from './delete/index.js'; +export * from './duplicate/index.js'; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/manifests.ts index aeaaceafc0..7d6813e49a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity-action/manifests.ts @@ -1,9 +1,12 @@ +import { manifests as createEntityActionManifests } from './common/create/manifests.js'; import { manifests as defaultEntityActionManifests } from './default/manifests.js'; import { manifests as deleteEntityActionManifests } from './common/delete/manifests.js'; import { manifests as duplicateEntityActionManifests } from './common/duplicate/manifests.js'; + import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; export const manifests: Array = [ + ...createEntityActionManifests, ...defaultEntityActionManifests, ...deleteEntityActionManifests, ...duplicateEntityActionManifests, diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/create-user-entity-action.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/create-user-entity-action.ts deleted file mode 100644 index a6da26da4f..0000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/create-user-entity-action.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { UMB_USER_CREATE_OPTIONS_MODAL } from './modal/index.js'; -import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; -import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; - -export class UmbCreateUserEntityAction extends UmbEntityActionBase { - override async execute() { - const modalManager = await this.getContext(UMB_MODAL_MANAGER_CONTEXT); - const modalContext = modalManager.open(this, UMB_USER_CREATE_OPTIONS_MODAL, { - data: { - parent: { - unique: this.args.unique, - entityType: this.args.entityType, - }, - }, - }); - - await modalContext.onSubmit(); - } -} - -export { UmbCreateUserEntityAction as api }; diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/manifests.ts index 658fa547d3..2e67f026d0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/manifests.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/manifests.ts @@ -1,26 +1,17 @@ import { UMB_USER_ROOT_ENTITY_TYPE } from '../../entity.js'; import { manifests as apiUser } from './api-user/manifests.js'; import { manifests as defaultUser } from './default-user/manifests.js'; -import { manifests as modalManifests } from './modal/manifests.js'; import type { UmbExtensionManifestKind } from '@umbraco-cms/backoffice/extension-registry'; export const manifests: Array = [ { type: 'entityAction', - kind: 'default', + kind: 'create', alias: 'Umb.EntityAction.User.Create', name: 'Create User Entity Action', - weight: 1200, - api: () => import('./create-user-entity-action.js'), forEntityTypes: [UMB_USER_ROOT_ENTITY_TYPE], - meta: { - icon: 'icon-add', - label: '#actions_create', - additionalOptions: true, - }, }, ...apiUser, ...defaultUser, - ...modalManifests, ]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/index.ts deleted file mode 100644 index 778a1fe38d..0000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; - -export const UMB_USER_CREATE_OPTIONS_MODAL = new UmbModalToken('Umb.Modal.User.CreateOptions', { - modal: { - type: 'sidebar', - size: 'small', - }, -}); diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/manifests.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/manifests.ts deleted file mode 100644 index 08dc77d154..0000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/manifests.ts +++ /dev/null @@ -1,8 +0,0 @@ -export const manifests: Array = [ - { - type: 'modal', - alias: 'Umb.Modal.User.CreateOptions', - name: 'User Create Options Modal', - element: () => import('./user-create-options-modal.element.js'), - }, -]; diff --git a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/user-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/user-create-options-modal.element.ts deleted file mode 100644 index cc9ba965f2..0000000000 --- a/src/Umbraco.Web.UI.Client/src/packages/user/user/entity-actions/create/modal/user-create-options-modal.element.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { html, customElement, state } from '@umbraco-cms/backoffice/external/lit'; -import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'; -import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity'; -import { UMB_ENTITY_CONTEXT } from '@umbraco-cms/backoffice/entity'; - -const elementName = 'umb-user-create-options-modal'; -@customElement(elementName) -export class UmbUserCreateOptionsModalElement extends UmbModalBaseElement { - @state() - entity: UmbEntityModel = { - entityType: '', - unique: '', - }; - - constructor() { - super(); - - this.consumeContext(UMB_ENTITY_CONTEXT, (context) => { - this.entity = { - entityType: context.getEntityType(), - unique: context.getUnique(), - }; - }); - } - - override render() { - return html` - - - - - - - `; - } -} - -export { UmbUserCreateOptionsModalElement as element }; - -declare global { - interface HTMLElementTagNameMap { - [elementName]: UmbUserCreateOptionsModalElement; - } -}