From 0b03d6c856681518fd1825b58f74e7fcd06def4a Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Fri, 1 Mar 2024 15:25:40 +0100 Subject: [PATCH] pass parent unique and entityType to all the modals --- .../create-folder/create-folder.action.ts | 5 ++++- .../modal/folder-create-modal.element.ts | 4 ++-- .../folder/modal/folder-create-modal.token.ts | 5 ++++- .../data-type-create-options-modal.element.ts | 6 ++--- .../entity-actions/create/create.action.ts | 8 ++++--- ...ument-type-create-options-modal.element.ts | 18 ++++++++------- .../entity-actions/create/modal/index.ts | 6 +++-- .../entity-actions/create/create.action.ts | 7 ++++-- .../entity-actions/create/modal/index.ts | 5 ++++- ...media-type-create-options-modal.element.ts | 15 ++++++++----- .../entity-actions/create/create.action.ts | 8 ++++--- .../create/options-modal/index.ts | 6 +++-- ...rtial-view-create-options-modal.element.ts | 22 ++++++++++--------- .../create-from-snippet-modal.token.ts | 5 ++++- .../create-from-snippet-modal.ts | 10 ++++++--- .../entity-actions/create/create.action.ts | 8 ++++--- .../create/options-modal/index.ts | 6 +++-- .../script-create-options-modal.element.ts | 18 ++++++++------- .../entity-actions/create/create.action.ts | 8 ++++--- .../create/options-modal/index.ts | 6 +++-- ...stylesheet-create-options-modal.element.ts | 22 +++++++++---------- .../entity-actions/create/create.action.ts | 2 -- 22 files changed, 121 insertions(+), 79 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/entity-action/create-folder/create-folder.action.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/entity-action/create-folder/create-folder.action.ts index d5b7efffb6..ce7e3ed77a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/entity-action/create-folder/create-folder.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/entity-action/create-folder/create-folder.action.ts @@ -21,7 +21,10 @@ export class UmbCreateFolderEntityAction extends const modalContext = this.#modalContext.open(UMB_FOLDER_CREATE_MODAL, { data: { folderRepositoryAlias: this.repositoryAlias, - parentUnique: this.unique ?? null, + parent: { + unique: this.unique, + entityType: this.entityType, + }, }, }); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.element.ts index b3bc180d4d..1ddac179c0 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.element.ts @@ -33,11 +33,11 @@ export class UmbFolderCreateModalElement extends UmbFolderModalElementBase< async onFormSubmit({ name }: { name: string }): Promise { if (!this.folderRepository) throw new Error('A folder repository is required to create a folder'); if (!this._folderScaffold) throw new Error('The folder scaffold was not initialized correctly'); - if (this.data?.parentUnique === undefined) throw new Error('A parent unique is required to create folder'); + if (!this.data?.parent) throw new Error('A parent is required to create folder'); const createFolderModel: UmbCreateFolderModel = { ...this._folderScaffold, - parentUnique: this.data.parentUnique, + parentUnique: this.data.parent.unique, name, }; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.token.ts index feb4db3518..898e51318a 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/tree/folder/modal/folder-create-modal.token.ts @@ -3,7 +3,10 @@ import type { UmbFolderModel } from '@umbraco-cms/backoffice/tree'; export interface UmbFolderCreateModalData { folderRepositoryAlias: string; - parentUnique: string | null; + parent: { + unique: string | null; + entityType: string; + }; } export interface UmbFolderCreateModalValue { diff --git a/src/Umbraco.Web.UI.Client/src/packages/data-type/entity-actions/create/modal/data-type-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/data-type/entity-actions/create/modal/data-type-create-options-modal.element.ts index e9886efb4b..ca22cdf531 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/data-type/entity-actions/create/modal/data-type-create-options-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/data-type/entity-actions/create/modal/data-type-create-options-modal.element.ts @@ -21,12 +21,12 @@ export class UmbDataTypeCreateOptionsModalElement extends UmbModalBaseElement { @@ -22,8 +22,10 @@ export class UmbCreateDataTypeEntityAction extends UmbEntityActionBase - + } diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/create/modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/create/modal/index.ts index 83c29c5f65..0b916444d9 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/create/modal/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/document-types/entity-actions/create/modal/index.ts @@ -1,8 +1,10 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; export interface UmbDocumentTypeCreateOptionsModalData { - parentUnique: string | null; - entityType: string; + parent: { + unique: string | null; + entityType: string; + }; } export const UMB_DOCUMENT_TYPE_CREATE_OPTIONS_MODAL = new UmbModalToken( diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/create.action.ts index 44a8aa2cf6..4d0fb77df7 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/create.action.ts @@ -2,7 +2,7 @@ import type { UmbMediaTypeDetailRepository } from '../../repository/detail/media import { UMB_MEDIA_TYPE_CREATE_OPTIONS_MODAL } from './modal/index.js'; import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; -import type { UmbModalManagerContext} from '@umbraco-cms/backoffice/modal'; +import type { UmbModalManagerContext } from '@umbraco-cms/backoffice/modal'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; export class UmbCreateMediaTypeEntityAction extends UmbEntityActionBase { @@ -22,7 +22,10 @@ export class UmbCreateMediaTypeEntityAction extends UmbEntityActionBase( diff --git a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/modal/media-type-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/modal/media-type-create-options-modal.element.ts index 3011704ef9..e3d237515b 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/modal/media-type-create-options-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/media/media-types/entity-actions/create/modal/media-type-create-options-modal.element.ts @@ -28,12 +28,12 @@ export class UmbDataTypeCreateOptionsModalElement extends UmbLitElement { #onClick(event: PointerEvent) { event.stopPropagation(); - if (this.data?.parentKey === undefined) throw new Error('A parent unique is required to create a folder'); + if (!this.data?.parent) throw new Error('A parent is required to create a folder'); const folderModalHandler = this.#modalContext?.open(UMB_FOLDER_CREATE_MODAL, { data: { folderRepositoryAlias: UMB_MEDIA_TYPE_FOLDER_REPOSITORY_ALIAS, - parentUnique: this.data?.parentKey, + parent: this.data?.parent, }, }); folderModalHandler?.onSubmit().then(() => this.modalContext?.submit()); @@ -48,15 +48,18 @@ export class UmbDataTypeCreateOptionsModalElement extends UmbLitElement { this.modalContext?.reject(); } + #getCreateHref() { + return `section/settings/workspace/media-type/create/parent/${this.data?.parent.entityType}/${ + this.data?.parent.unique || 'null' + }`; + } + render() { return html` - + diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create.action.ts index 8ecfb0a08c..185b74c4ca 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/create.action.ts @@ -1,7 +1,7 @@ import { UMB_PARTIAL_VIEW_CREATE_OPTIONS_MODAL } from './options-modal/index.js'; import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; -import type { UmbModalManagerContext} from '@umbraco-cms/backoffice/modal'; +import type { UmbModalManagerContext } from '@umbraco-cms/backoffice/modal'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; export class UmbPartialViewCreateOptionsEntityAction extends UmbEntityActionBase { @@ -21,8 +21,10 @@ export class UmbPartialViewCreateOptionsEntityAction extends UmbEntityActionBase this.#modalManagerContext?.open(UMB_PARTIAL_VIEW_CREATE_OPTIONS_MODAL, { data: { - parentUnique: this.unique, - entityType: this.entityType, + parent: { + unique: this.unique, + entityType: this.entityType, + }, }, }); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/index.ts index 0b9c86730b..37f53a978d 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/index.ts @@ -1,8 +1,10 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; export interface UmbPartialViewCreateOptionsModalData { - parentUnique: string | null; - entityType: string; + parent: { + unique: string | null; + entityType: string; + }; } export const UMB_PARTIAL_VIEW_CREATE_OPTIONS_MODAL = new UmbModalToken( diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/partial-view-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/partial-view-create-options-modal.element.ts index c487f349bf..e9fdaea423 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/partial-view-create-options-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/options-modal/partial-view-create-options-modal.element.ts @@ -24,8 +24,7 @@ export class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement connectedCallback(): void { super.connectedCallback(); - - if (this.data?.parentUnique === undefined) throw new Error('A parent unique is required to create a folder'); + if (!this.data?.parent) throw new Error('A parent unique is required to create a folder'); this.#createFolderAction = new UmbCreateFolderEntityAction( this, @@ -33,8 +32,8 @@ export class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // TODO: allow null for entity actions. Some actions can be executed on the root item - this.data.parentUnique, - this.data.entityType, + this.data.parent.unique, + this.data.parent.entityType, ); } @@ -51,11 +50,11 @@ export class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement async #onCreateFromSnippetClick(event: PointerEvent) { event.stopPropagation(); - if (this.data?.parentUnique === undefined) throw new Error('A parent unique is required to create a folder'); + if (!this.data?.parent) throw new Error('A parent is required to create a folder'); const modalContext = this.#modalManager?.open(UMB_PARTIAL_VIEW_FROM_SNIPPET_MODAL, { data: { - parentUnique: this.data.parentUnique, + parent: this.data.parent, }, }); @@ -67,15 +66,18 @@ export class UmbPartialViewCreateOptionsModalElement extends UmbModalBaseElement this._submitModal(); } + #getCreateHref() { + return `section/settings/workspace/partial-view/create/parent/${this.data?.parent.entityType}/${ + this.data?.parent.unique || 'null' + }`; + } + render() { return html` - + } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.token.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.token.ts index 412cb9990e..85498f9c73 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.token.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.token.ts @@ -1,7 +1,10 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; export interface UmbCreatePartialViewFromSnippetModalData { - parentUnique: string | null; + parent: { + unique: string | null; + entityType: string; + }; } export const UMB_PARTIAL_VIEW_FROM_SNIPPET_MODAL = new UmbModalToken( diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.ts index 285a5e67d0..325e94be04 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/partial-views/entity-actions/create/snippet-modal/create-from-snippet-modal.ts @@ -17,6 +17,12 @@ export class UmbPartialViewCreateFromSnippetModalElement extends UmbModalBaseEle @state() _snippets: Array = []; + #getCreateHref(snippet) { + return `section/settings/workspace/partial-view/create/parent/${this.data?.parent.entityType}/${ + this.data?.parent.unique || 'null' + }/snippet/${snippet.id}`; + } + protected async firstUpdated() { const { data } = await tryExecuteAndNotify(this, PartialViewResource.getPartialViewSnippet({ take: 10000 })); @@ -24,9 +30,7 @@ export class UmbPartialViewCreateFromSnippetModalElement extends UmbModalBaseEle this._snippets = data.items.map((snippet) => { return { name: snippet.name, - path: `section/settings/workspace/partial-view/create/${this.data?.parentUnique || 'null'}/snippet/${ - snippet.id - }`, + path: this.#getCreateHref(snippet), }; }); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts index 30f9295a63..c838201e51 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/create.action.ts @@ -1,7 +1,7 @@ import { UMB_SCRIPT_CREATE_OPTIONS_MODAL } from './options-modal/index.js'; import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; -import type { UmbModalManagerContext} from '@umbraco-cms/backoffice/modal'; +import type { UmbModalManagerContext } from '@umbraco-cms/backoffice/modal'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; export class UmbScriptCreateOptionsEntityAction extends UmbEntityActionBase { @@ -21,8 +21,10 @@ export class UmbScriptCreateOptionsEntityAction extends UmbEntityActionBase( diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts index bc99185023..86294646bf 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/scripts/entity-actions/create/options-modal/script-create-options-modal.element.ts @@ -20,8 +20,7 @@ export class UmbScriptCreateOptionsModalElement extends UmbModalBaseElement - + } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/create.action.ts index 84e2f5bfcb..ac49122547 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/create.action.ts @@ -1,7 +1,7 @@ import { UMB_STYLESHEET_CREATE_OPTIONS_MODAL } from './options-modal/index.js'; import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'; import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api'; -import type { UmbModalManagerContext} from '@umbraco-cms/backoffice/modal'; +import type { UmbModalManagerContext } from '@umbraco-cms/backoffice/modal'; import { UMB_MODAL_MANAGER_CONTEXT } from '@umbraco-cms/backoffice/modal'; export class UmbStylesheetCreateOptionsEntityAction extends UmbEntityActionBase { @@ -21,8 +21,10 @@ export class UmbStylesheetCreateOptionsEntityAction extends UmbEntityActionBase< this.#modalManagerContext?.open(UMB_STYLESHEET_CREATE_OPTIONS_MODAL, { data: { - parentUnique: this.unique, - entityType: this.entityType, + parent: { + unique: this.unique, + entityType: this.entityType, + }, }, }); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/index.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/index.ts index 016ac5d3a8..12ecad6881 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/index.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/index.ts @@ -1,8 +1,10 @@ import { UmbModalToken } from '@umbraco-cms/backoffice/modal'; export interface UmbStylesheetCreateOptionsModalData { - parentUnique: string | null; - entityType: string; + parent: { + unique: string | null; + entityType: string; + }; } export const UMB_STYLESHEET_CREATE_OPTIONS_MODAL = new UmbModalToken( diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/stylesheet-create-options-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/stylesheet-create-options-modal.element.ts index d457bae5f9..8c3fb77cef 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/stylesheet-create-options-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/stylesheets/entity-actions/create/options-modal/stylesheet-create-options-modal.element.ts @@ -13,8 +13,7 @@ export class UmbStylesheetCreateOptionsModalElement extends UmbModalBaseElement< connectedCallback(): void { super.connectedCallback(); - - if (this.data?.parentUnique === undefined) throw new Error('A parent unique is required to create a folder'); + if (!this.data?.parent) throw new Error('A parent is required to create a folder'); this.#createFolderAction = new UmbCreateFolderEntityAction( this, @@ -22,8 +21,8 @@ export class UmbStylesheetCreateOptionsModalElement extends UmbModalBaseElement< // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore // TODO: allow null for entity actions. Some actions can be executed on the root item - this.data.parentUnique, - this.data.entityType, + this.data.parent.unique, + this.data.parent.entityType, ); } @@ -43,22 +42,23 @@ export class UmbStylesheetCreateOptionsModalElement extends UmbModalBaseElement< this._submitModal(); } + #getCreateHref() { + return `section/settings/workspace/stylesheet/create/parent/${this.data?.parent.entityType}/${ + this.data?.parent.unique || 'null' + }`; + } + render() { return html` - + } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/entity-actions/create/create.action.ts b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/entity-actions/create/create.action.ts index 2684bd4661..8bd1de6169 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/templating/templates/entity-actions/create/create.action.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/templating/templates/entity-actions/create/create.action.ts @@ -6,9 +6,7 @@ export class UmbCreateEntityAction }> extends super(host, repositoryAlias, unique, entityType); } - // TODO: can we make this a generic create action async execute() { - // TODO: get entity type from repository? const url = `section/settings/workspace/template/create/${this.unique || 'null'}`; // TODO: how do we handle this with a href? history.pushState(null, '', url);