Merge branch 'feature/entity-context' into feature/document-user-permission

This commit is contained in:
Mads Rasmussen
2024-04-08 11:54:20 +02:00
committed by GitHub
4 changed files with 107 additions and 4 deletions

View File

@@ -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);
});
});
});

View File

@@ -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<UmbEntityContext>}
@@ -25,18 +25,38 @@ export class UmbEntityContext extends UmbContextBase<UmbEntityContext> {
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();
}

View File

@@ -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);
},
},

View File

@@ -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() {