diff --git a/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/package-view.js b/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/package-view.js index d10ba9e5a7..8a028d0ece 100644 --- a/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/package-view.js +++ b/src/Umbraco.Web.UI.Client/public-assets/App_Plugins/package-view.js @@ -23,7 +23,6 @@ export default class MyPackageViewCustom extends HTMLElement { } onClick() { - console.log(this.modalHandler); this.modalHandler.close(); } } diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/modal/modal-context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/modal/modal-context.ts index 1dd7e5ec9b..d56e954986 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/modal/modal-context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/modal/modal-context.ts @@ -162,7 +162,6 @@ export class UmbModalContextClass implements UmbEntityWorkspaceContextInterface { - public host: UmbControllerHostElement; - public repository: T; + public readonly host: UmbControllerHostElement; + public readonly repository: T; + + // TODO: We could make a base type for workspace modal data, and use this here: As well as a base for the result, to make sure we always include the unique. + public readonly modalContext?: UmbModalContext<{ preset: object }>; #isNew = new UmbBooleanState(undefined); isNew = this.#isNew.asObservable(); @@ -23,6 +27,9 @@ export abstract class UmbWorkspaceContext this.host = host; this.repository = repository; new UmbContextProviderController(host, UMB_ENTITY_WORKSPACE_CONTEXT, this); + new UmbContextConsumerController(host, UMB_MODAL_CONTEXT_TOKEN, (context) => { + (this.modalContext as UmbModalContext) = context; + }); } getIsNew() { @@ -34,11 +41,16 @@ export abstract class UmbWorkspaceContext } protected saveComplete(data: EntityType) { - // TODO: Should we make a Event class for this=? - this.host.dispatchEvent(new CustomEvent('workspace-submit', { composed: true, bubbles: true, detail: { data } })); + if (this.modalContext) { + this.submitModal(data); + } else { + // No need to have UI changing to "not new" if we are in a modal. + this.setIsNew(false); + } + } - // If it went well, then its not new anymore?. - this.setIsNew(false); + protected submitModal(data: EntityType) { + this.modalContext?.submit(data); } abstract getEntityId(): string | undefined; // COnsider if this should go away now that we have getUnique() diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-modal/workspace-modal.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-modal/workspace-modal.element.ts index 4cf4a114c2..02dff6e98f 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-modal/workspace-modal.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace-modal/workspace-modal.element.ts @@ -1,36 +1,19 @@ import { UUITextStyles } from '@umbraco-cms/backoffice/external/uui'; import { css, CSSResultGroup, html, customElement, property } from '@umbraco-cms/backoffice/external/lit'; -import { UmbModalContext, UmbWorkspaceData, UmbWorkspaceResult } from '@umbraco-cms/backoffice/modal'; +import { UmbWorkspaceData } from '@umbraco-cms/backoffice/modal'; import { UmbLitElement } from '@umbraco-cms/internal/lit-element'; @customElement('umb-workspace-modal') export class UmbWorkspaceModalElement extends UmbLitElement { - @property({ attribute: false }) - modalHandler?: UmbModalContext; - @property() data?: UmbWorkspaceData; - private _reject = (event: CustomEvent) => { - event.stopPropagation(); - this.modalHandler?.reject(); - }; - - private _submit = (event: CustomEvent) => { - event.stopPropagation(); - this.modalHandler?.submit(event.detail); - }; - /** * TODO: Consider if this binding and events integration is the right for communicating back the modal handler. Or if we should go with some Context API. like a Modal Context API. * */ render() { - return html``; + return html``; } static styles: CSSResultGroup = [ diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace.element.ts index a6521513b8..d6ed14cf62 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/workspace/workspace.element.ts @@ -8,14 +8,10 @@ export class UmbWorkspaceElement extends UmbLitElement { @property({ type: String, attribute: 'entity-type' }) entityType = ''; - @property({ type: Object, attribute: false }) - preset?: Record; - render() { if (!this.entityType) return nothing; return html` manifest.meta.entityType === this.entityType}>`; } diff --git a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts index 726b8ab7d4..dc0e25b629 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/settings/data-types/workspace/data-type-workspace.context.ts @@ -12,8 +12,6 @@ export class UmbDataTypeWorkspaceContext #data = new UmbObjectState(undefined); data = this.#data.asObservable(); - #preset?: Partial; - name = this.#data.getObservablePart((data) => data?.name); id = this.#data.getObservablePart((data) => data?.id); @@ -21,10 +19,6 @@ export class UmbDataTypeWorkspaceContext super(host, new UmbDataTypeRepository(host)); } - public setPreset(preset: Partial) { - this.#preset = preset; - } - async load(id: string) { const { data } = await this.repository.requestById(id); if (data) { @@ -35,8 +29,8 @@ export class UmbDataTypeWorkspaceContext async createScaffold(parentId: string | null) { let { data } = await this.repository.createScaffold(parentId); - if (this.#preset) { - data = { ...data, ...this.#preset }; + if (this.modalContext) { + data = { ...data, ...this.modalContext.data.preset }; } this.setIsNew(true); // TODO: This is a hack to get around the fact that the data is not typed correctly.