diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-container-structure-helper.class.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-container-structure-helper.class.ts index 5fa0cba57a..90955831c2 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-container-structure-helper.class.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-container-structure-helper.class.ts @@ -85,109 +85,6 @@ export class UmbContentTypeContainerStructureHelper { - this.removeControllerByAlias('_observeParentHasProperties_' + container.id); - this.removeControllerByAlias('_observeGroupsOf_' + container.id); - }); - this._parentMatchingContainers = []; - this.removeControllerByAlias('_observeOwnerContainers'); - this.#containers.setValue([]); - this.#mergedContainers.setValue([]); - //this._observeChildProperties(); // We cannot have root properties currently, therefor we instead just set it to false: - this.#hasProperties.setValue(false); - this.#observeRootContainers(); - } else if (this._parentName && this._parentType) { - this.#containers.setValue([]); - this.#mergedContainers.setValue([]); - this.observe( - // This only works because we just have two levels, meaning this is the upper level and we want it to merge, so its okay this does not take parent-parent (And further structure) into account: [NL] - this.#structure.containersByNameAndType(this._parentName, this._parentType), - (parentContainers) => { - this._ownerContainers = []; - this.#containers.setValue([]); - this.#mergedContainers.setValue([]); - // Stop observing a the previous _parentMatchingContainers... - this._parentMatchingContainers.forEach((container) => { - this.removeControllerByAlias('_observeParentHasProperties_' + container.id); - this.removeControllerByAlias('_observeGroupsOf_' + container.id); - }); - this._parentMatchingContainers = parentContainers ?? []; - if (this._parentMatchingContainers.length > 0) { - this.#observeChildProperties(); - this.#observeChildContainers(); - } else { - // Do some reset: - this.#hasProperties.setValue(false); - this.removeControllerByAlias('_observeOwnerContainers'); - } - }, - '_observeParentContainers', - ); - } - } - - #observeChildProperties() { - if (!this.#structure) return; - - this._parentMatchingContainers.forEach((container) => { - this.observe( - this.#structure!.hasPropertyStructuresOf(container.id!), - (hasProperties) => { - this.#hasProperties.setValue(hasProperties); - }, - '_observeParentHasProperties_' + container.id, - ); - }); - } - - #observeChildContainers() { - if (!this.#structure || !this._parentName || !this._childType || !this._parentId) return; - - // TODO: If a owner container is removed, Or suddenly matches name-wise with a inherited container, then we now miss the inherited container,maybe [NL] - this.observe( - this.#structure.ownerContainersOf(this._childType, this._parentId), - (containers) => { - this._ownerContainers = containers ?? []; - this.#containers.append(this._ownerContainers); - //this.#mergedContainers.setValue(this.#filterNonOwnerContainers(this.#mergedContainers.getValue())); - }, - '_observeOwnerContainers', - ); - - this._parentMatchingContainers.forEach((parentCon) => { - this.observe( - this.#structure!.containersOfParentId(parentCon.id, this._childType!), - (containers) => { - // Problem this will never remove a container? [NL] - this.#containers.append(containers); - - // First we will filter out non-owner containers: - const old = this.#mergedContainers.getValue(); - // Then filter out the containers that are in the new list, either based on id or a match on name & type. - // Matching on name & type will result in the latest being the one we include, notice will only counts for non-owner containers. - const oldFiltered = old.filter( - (x) => !containers.some((y) => y.id === x.id || (y.name === x.name && y.type === x.type)), - ); - - const newFiltered = oldFiltered.concat(containers); - - // Filter out non owners again: - this.#mergedContainers.setValue(this.#filterNonOwnerContainers(newFiltered)); - - }, - '_observeGroupsOf_' + parentCon.id, - ); - }); - } - - */ - private _containerName?: string; private _containerType?: UmbPropertyContainerTypes; private _parentName?: string | null; @@ -205,6 +102,7 @@ export class UmbContentTypeContainerStructureHelper { if (container) { + console.log('Container update', container.name); this._containerName = container.name ?? ''; this._containerType = container.type; if (container.parent) { @@ -221,6 +119,7 @@ export class UmbContentTypeContainerStructureHelper { - console.log('root containers', rootContainers); // Here (When getting root containers) we get containers from all ContentTypes. It also means we need to do an extra filtering to ensure we only get one of each containers. [NL] // For that we get the owner containers first (We do not need to observe as this observation will be triggered if one of the owner containers change) [NL] this._ownerContainers = this.#structure!.getOwnerContainers(this._childType!, this._containerId!) ?? []; this.#containers.setValue(rootContainers); - /* - // Then we filter out the duplicate containers based on type and name: - rootContainers = rootContainers.filter( - (x, i, cons) => i === cons.findIndex((y) => y.name === x.name && y.type === x.type), - ); - - this.#mergedContainers.setValue(this.#filterNonOwnerContainers(rootContainers)); - */ }, '_observeRootContainers', ); @@ -351,6 +238,10 @@ export class UmbContentTypeContainerStructureHelper x.id === containerId); } + containersByNameAndType(name: string, type: UmbPropertyContainerTypes) { + return this.#containers.asObservablePart((cons) => cons.filter((x) => x.name === name && x.type === type)); + } + /** Manipulate methods: */ async insertContainer(container: UmbPropertyTypeContainerModel, sortOrder = 0) { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-group.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-group.element.ts index 2fb54f7387..c5f423ba43 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-group.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-group.element.ts @@ -56,17 +56,12 @@ export class UmbContentTypeWorkspaceViewEditGroupElement extends UmbLitElement { if (this.group.name) { // We can first match with something if we have a name [NL] this.observe( - // TODO: Missing something about parent name and type here as well, or maybe this one can use the groupStructureHelper for this case: - // TODO: When the groupStructureHelper holds the full list of containers, then we can use that to look up all child containers by name and type.[NL] - this.groupStructureHelper.getStructureManager()!.containersByNameAndType(this.group.name, 'Group'), + this.groupStructureHelper.containersByNameAndType(this.group.name, 'Group'), (containers) => { - const amountOfContainers = containers.length; - const hasAOwnerContainer = containers.some((con) => this.groupStructureHelper!.isOwnerChildContainer(con.id), ); - - const pureOwnerContainer = hasAOwnerContainer && amountOfContainers === 1; + const pureOwnerContainer = hasAOwnerContainer && containers.length === 1; this._hasOwnerContainer = hasAOwnerContainer; this._inherited = !pureOwnerContainer; diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-properties.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-properties.element.ts index 801dafad0b..ec0fb04c71 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-properties.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-design-editor-properties.element.ts @@ -154,9 +154,8 @@ export class UmbContentTypeDesignEditorPropertiesElement extends UmbLitElement { this._editContentTypePath = routeBuilder({}); }); - const docTypeObservable = workspaceContext.structure.ownerContentType; this.observe( - docTypeObservable, + workspaceContext.structure.ownerContentType, (contentType) => { this._ownerContentType = contentType; },