diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts new file mode 100644 index 0000000000..e01e1937b0 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.test.ts @@ -0,0 +1,77 @@ +import { expect } from '@open-wc/testing'; +import { UmbEntityContext } from './entity.context.js'; +import { UMB_ENTITY_CONTEXT } from './entity.context-token.js'; +import { Observable } from '@umbraco-cms/backoffice/external/rxjs'; +import { customElement } from '@umbraco-cms/backoffice/external/lit'; +import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'; + +@customElement('umb-test-host') +export class UmbTestHostElement extends UmbElementMixin(HTMLElement) {} + +@customElement('umb-test-child') +export class UmbTestChildElement extends UmbElementMixin(HTMLElement) {} + +describe('UmbEntityContext', () => { + let context: UmbEntityContext; + let host: UmbTestHostElement; + let child: UmbTestChildElement; + + beforeEach(() => { + host = new UmbTestHostElement(); + child = new UmbTestChildElement(); + host.appendChild(child); + document.body.appendChild(host); + context = new UmbEntityContext(host); + }); + + describe('Public API', () => { + describe('properties', () => { + it('has a entity type property', () => { + expect(context).to.have.property('entityType').to.be.an.instanceOf(Observable); + }); + + it('has a unique property', () => { + expect(context).to.have.property('unique').to.be.an.instanceOf(Observable); + }); + }); + + describe('methods', () => { + it('has a getEntityType method', () => { + expect(context).to.have.property('getEntityType').that.is.a('function'); + }); + + it('has a setEntityType method', () => { + expect(context).to.have.property('setEntityType').that.is.a('function'); + }); + + it('has a getUnique method', () => { + expect(context).to.have.property('getUnique').that.is.a('function'); + }); + + it('has a setUnique method', () => { + expect(context).to.have.property('setUnique').that.is.a('function'); + }); + }); + }); + + describe('set and get entity type', () => { + it('should set entity type', () => { + context.setEntityType('entity-type'); + expect(context.getEntityType()).to.equal('entity-type'); + }); + }); + + describe('set and get unique', () => { + it('should set unique', () => { + context.setUnique('unique-value'); + expect(context.getUnique()).to.equal('unique-value'); + }); + }); + + describe('it is provided as a context', () => { + it('should be provided as a context', async () => { + const providedContext = await child.getContext(UMB_ENTITY_CONTEXT); + expect(providedContext).to.equal(context); + }); + }); +}); diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.ts b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.ts index acb9abfc8b..8f193465ae 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/entity/entity.context.ts @@ -4,7 +4,7 @@ import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api'; import { UmbStringState } from '@umbraco-cms/backoffice/observable-api'; /** - * UmbEntityContext + * Provides the entity context * @export * @class UmbEntityContext * @extends {UmbContextBase} @@ -25,18 +25,38 @@ export class UmbEntityContext extends UmbContextBase { super(host, UMB_ENTITY_CONTEXT); } + /** + * Set the entity type + * @param {string | undefined} entityType + * @memberof UmbEntityContext + */ setEntityType(entityType: string | undefined) { this.#entityType.setValue(entityType); } - getEntityType() { + /** + * Get the entity type + * @returns {string | undefined} + * @memberof UmbEntityContext + */ + getEntityType(): string | undefined { return this.#entityType.getValue(); } + /** + * Set the unique + * @param {string | null | undefined} unique + * @memberof UmbEntityContext + */ setUnique(unique: string | null | undefined) { this.#unique.setValue(unique); } + /** + * Get the unique + * @returns {string | null | undefined} + * @memberof UmbEntityContext + */ getUnique() { return this.#unique.getValue(); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts index 927acdbecb..c017ba460c 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/documents/documents/workspace/document-workspace.context.ts @@ -1,3 +1,4 @@ +import { UmbEntityContext } from '@umbraco-cms/backoffice/entity'; import { UmbDocumentTypeDetailRepository } from '../../document-types/repository/detail/document-type-detail.repository.js'; import { UmbDocumentPropertyDataContext } from '../property-dataset-context/document-property-dataset-context.js'; import { UMB_DOCUMENT_ENTITY_TYPE } from '../entity.js'; @@ -132,6 +133,9 @@ export class UmbDocumentWorkspaceContext }, ); + // TODO: this should be set up for all entity workspace contexts in a base class + #entityContext = new UmbEntityContext(this); + constructor(host: UmbControllerHost) { super(host, UMB_DOCUMENT_WORKSPACE_ALIAS); @@ -162,6 +166,8 @@ export class UmbDocumentWorkspaceContext component: () => import('./document-workspace-editor.element.js'), setup: (_component, info) => { const unique = info.match.params.unique; + this.#entityContext.setEntityType(UMB_DOCUMENT_ENTITY_TYPE); + this.#entityContext.setUnique(unique); this.load(unique); }, }, diff --git a/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/performance-profiling/dashboard-performance-profiling.element.ts b/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/performance-profiling/dashboard-performance-profiling.element.ts index 3931e17776..5cb5371c94 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/performance-profiling/dashboard-performance-profiling.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/settings/dashboards/performance-profiling/dashboard-performance-profiling.element.ts @@ -28,8 +28,8 @@ export class UmbDashboardPerformanceProfilingElement extends UmbLitElement { private async _getProfilingStatus() { const { data } = await tryExecuteAndNotify(this, ProfilingResource.getProfilingStatus()); - if (!data || !data.enabled) return; - this._profilingStatus = data.enabled; + if (!data) return; + this._profilingStatus = data.enabled ?? false; } private async _changeProfilingStatus() {