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 eaa4a17a66..395ca7be7d 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 @@ -27,13 +27,14 @@ export class UmbContentTypeContainerStructureHelper([], (x) => x.id); readonly containers = this.#containers.asObservable(); + // Owner containers are containers owned by the owner Content Type (The specific one up for editing) + private _ownerContainers: UmbPropertyTypeContainerModel[] = []; + #hasProperties = new UmbBooleanState(false); readonly hasProperties = this.#hasProperties.asObservable(); @@ -103,6 +104,7 @@ export class UmbContentTypeContainerStructureHelper { this.#containers.setValue([]); - this._parentOwnerContainers = parentContainers.filter((x) => x.id === this._parentId) || []; + //this._parentOwnerContainers = parentContainers.filter((x) => x.id === this._parentId) || []; this._parentMatchingContainers = parentContainers ?? []; if (this._parentMatchingContainers.length > 0) { this._observeChildProperties(); @@ -165,11 +167,33 @@ export class UmbContentTypeContainerStructureHelper { this.observe( this.#structure!.containersOfParentKey(container.id, this._childType!), (containers) => { - this.#containers.append(this._insertChildContainers(containers)); + // TODO: This stinks, we need to finder a smarter way to do merging on the way. Think about the case when a container is appended but matches a container already in the list. + const old = this.#containers.getValue(); + const appends = this._insertChildContainers(containers); + // Make sure entries are unique on name and type: + const oldFiltered = old.filter( + (x) => + !appends.some( + (y) => + y.name === x.name && y.type === x.type && this._ownerContainers.some((oc) => oc.id === y.parent?.id), + ), + ); + const newFiltered = oldFiltered.concat(appends); + // Filter the newFiltered so it becomes unique name and type: + newFiltered.forEach((x, i, value) => !value.some((y) => y.name === x.name && y.type === x.type)); + + this.#containers.setValue(newFiltered); + // TODO: make sure we filter away any inherited containers: }, '_observeGroupsOf_' + container.id, ); @@ -183,7 +207,7 @@ export class UmbContentTypeContainerStructureHelper { this.#containers.setValue(this._insertChildContainers(rootContainers)); - this._parentOwnerContainers = this.#structure!.getOwnerContainers(this._childType!, this._parentId!) ?? []; + this._ownerContainers = this.#structure!.getOwnerContainers(this._childType!, this._parentId!) ?? []; }, '_observeRootContainers', ); @@ -192,6 +216,7 @@ export class UmbContentTypeContainerStructureHelper { + // TODO: This place needs to be more intelligent about the existing containers. Now it only takes care of it self. [NL] return childContainers.flatMap((group, i, value) => { if (group.name !== null && group.name !== undefined) { if (value.find((x) => x.name === group.name)) { @@ -218,7 +243,7 @@ export class UmbContentTypeContainerStructureHelper x.id === containerId); + return this._ownerContainers.some((x) => x.id === containerId); } /** Manipulate methods: */ diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-structure-manager.class.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-structure-manager.class.ts index 24c3054d92..05facd034e 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-structure-manager.class.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/structure/content-type-structure-manager.class.ts @@ -251,9 +251,11 @@ export class UmbContentTypePropertyStructureManager x.unique === toContentTypeUnique)?.containers ?? []), - ]; + // Correction the spread is removed now, cause we do a filter: [NL] + // And then we remove the existing one, to have the more local one replacing it. [NL] + const containers = ( + this.#contentTypes.getValue().find((x) => x.unique === toContentTypeUnique)?.containers ?? [] + ).filter((x) => x.name !== clonedContainer.name && x.type === clonedContainer.type); containers.push(clonedContainer); // eslint-disable-next-line @typescript-eslint/ban-ts-comment