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 395ca7be7d..cc02411639 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 @@ -114,6 +114,7 @@ export class UmbContentTypeContainerStructureHelper { + this._ownerContainers = containers ?? []; + //console.log('this._ownerContainers', this._ownerContainers); + }, + '_observeOwnerContainers', + ); this._parentMatchingContainers.forEach((container) => { this.observe( @@ -179,20 +186,21 @@ export class UmbContentTypeContainerStructureHelper { // 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); + + //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), - ), + (x) => !containers.some((y) => y.id === x.id || (y.name === x.name && y.type === x.type)), ); - const newFiltered = oldFiltered.concat(appends); + + const newFiltered = oldFiltered.concat(containers); + /* // 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); +*/ + this.#containers.setValue(this._filterContainers(newFiltered)); + //console.log('new set of containers:', this.#containers.getValue(), this._parentId); + //debugger; // TODO: make sure we filter away any inherited containers: }, '_observeGroupsOf_' + container.id, @@ -200,19 +208,33 @@ export class UmbContentTypeContainerStructureHelper) { + return old.filter( + (anyCon) => + !this._ownerContainers.some( + (ownerCon) => + // We would like to keep the owner container in the anyCons, so do not filter that + ownerCon.id !== anyCon.id || + (ownerCon.name === anyCon.name && + ownerCon.type === anyCon.type && + ownerCon.parent?.id === anyCon.parent?.id), + ), + ); + } + private _observeRootContainers() { if (!this.#structure || !this._isRoot || !this._childType || this._parentId === undefined) return; this.observe( this.#structure.rootContainers(this._childType), (rootContainers) => { - this.#containers.setValue(this._insertChildContainers(rootContainers)); + this.#containers.setValue(rootContainers); this._ownerContainers = this.#structure!.getOwnerContainers(this._childType!, this._parentId!) ?? []; }, '_observeRootContainers', ); } - + /* private _insertChildContainers( childContainers: UmbPropertyTypeContainerModel[], ): Array { @@ -225,7 +247,7 @@ export class UmbContentTypeContainerStructureHelper x.id === containerId); } 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 05facd034e..2290534137 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 @@ -591,13 +591,19 @@ export class UmbContentTypePropertyStructureManager x.containers?.filter((x) => x.type === containerType) ?? []); + ownerContainersOf(containerType: UmbPropertyContainerTypes, parentId: string | null) { + return this.ownerContentTypeObservablePart( + (x) => + x.containers?.filter( + (x) => (parentId ? x.parent?.id === parentId : x.parent === null) && x.type === containerType, + ) ?? [], + ); } getOwnerContainers(containerType: UmbPropertyContainerTypes, parentId: string | null) { - return this.getOwnerContentType()?.containers?.filter((x) => - parentId ? x.parent?.id === parentId : x.parent === null && x.type === containerType, + console.log(this.getOwnerContentType()?.containers); + return this.getOwnerContentType()?.containers?.filter( + (x) => (parentId ? x.parent?.id === parentId : x.parent === null) && x.type === containerType, ); } diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit-tab.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit-tab.element.ts index 618e74a6f3..dcb5b18cd3 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit-tab.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit-tab.element.ts @@ -1,7 +1,7 @@ import { UMB_CONTENT_TYPE_WORKSPACE_CONTEXT } from '../../content-type-workspace.context-token.js'; import type { UmbContentTypeWorkspaceViewEditGroupElement } from './content-type-workspace-view-edit-group.element.js'; import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'; -import { css, html, customElement, property, state, repeat, ifDefined } from '@umbraco-cms/backoffice/external/lit'; +import { css, html, customElement, property, state, repeat } from '@umbraco-cms/backoffice/external/lit'; import { UmbContentTypeContainerStructureHelper, type UmbContentTypeModel, @@ -32,7 +32,6 @@ export class UmbContentTypeWorkspaceViewEditTabElement extends UmbLitElement { throw new Error('OwnerTabId is not set, we have not made a local duplicated of this container.'); return; } - console.log('_ownerTabId', this._inherited); /** Explanation: If the item is the first in list, we compare it to the item behind it to set a sortOrder. * If it's not the first in list, we will compare to the item in before it, and check the following item to see if it caused overlapping sortOrder, then update * the overlap if true, which may cause another overlap, so we loop through them till no more overlaps... @@ -161,7 +160,6 @@ export class UmbContentTypeWorkspaceViewEditTabElement extends UmbLitElement { const len = this._groups.length; const sortOrder = len === 0 ? 0 : this._groups[len - 1].sortOrder + 1; const container = this.#groupStructureHelper.addContainer(this._containerId, sortOrder); - console.log('container', container); }; render() { diff --git a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit.element.ts b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit.element.ts index 2a8a8fa2e4..5111e75874 100644 --- a/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit.element.ts +++ b/src/Umbraco.Web.UI.Client/src/packages/core/content-type/workspace/views/design/content-type-workspace-view-edit.element.ts @@ -134,6 +134,10 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem }); } + #toggleSortMode() { + this._workspaceContext?.setIsSorting(!this._sortModeActive); + } + private _observeRootGroups() { if (!this._workspaceContext) return; @@ -147,10 +151,6 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem ); } - #changeMode() { - this._workspaceContext?.setIsSorting(!this._sortModeActive); - } - private _createRoutes() { // TODO: How about storing a set of elements based on tab ids? to prevent re-initializing the element when renaming..[NL] if (!this._workspaceContext || !this._tabs || this._hasRootGroups === undefined) return; @@ -202,8 +202,7 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem } // If we have an active tab name, then we might have a active tab name re-name, then we will redirect to the new name if it has been changed: [NL] - // TODOD: this._activeTabId could be left out. - if (this._activeTabId && activeTabName) { + if (activeTabName) { if (this._activePath && this._routerPath) { const oldPath = this._activePath.split(this._routerPath)[1]; const newPath = '/tab/' + encodeFolderName(activeTabName); @@ -216,9 +215,7 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem } } - //if (jsonStringComparison(this._routes, routes) === false) { this._routes = routes; - //} } async #requestRemoveTab(tab: PropertyTypeContainerModelBaseModel | undefined) { @@ -382,7 +379,7 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem ${this.localize.term('contentTypeEditor_compositions')} - + ${sortButtonText} @@ -420,34 +417,35 @@ export class UmbContentTypeWorkspaceViewEditElement extends UmbLitElement implem renderTab(tab: PropertyTypeContainerModelBaseModel) { const path = this._routerPath + (tab.name ? '/tab/' + encodeFolderName(tab.name) : '/tab'); const tabActive = path === this._activePath; - const tabInherited = !this._tabsStructureHelper.isOwnerChildContainer(tab.id!); + const ownedTab = this._tabsStructureHelper.isOwnerChildContainer(tab.id!) ?? false; + console.log('ownedTab', ownedTab); return html` - ${this.renderTabInner(tab, tabActive, tabInherited)} + ${this.renderTabInner(tab, tabActive, ownedTab)} `; } - renderTabInner(tab: PropertyTypeContainerModelBaseModel, tabActive: boolean, tabInherited: boolean) { + renderTabInner(tab: PropertyTypeContainerModelBaseModel, tabActive: boolean, ownedTab: boolean) { // TODO: Localize this: if (this._sortModeActive) { return html`
- ${tabInherited - ? html`${tab.name!}` - : html` ${tab.name!} + ${ownedTab + ? html` ${tab.name!} this.#changeOrderNumber(tab, e)}>`} + @change=${(e: UUIInputEvent) => this.#changeOrderNumber(tab, e)}>` + : html`${tab.name!}`}
`; } - if (tabActive && !tabInherited) { + if (tabActive && ownedTab) { return html`
`; } - if (tabInherited) { - return html`
${tab.name!}
`; - } else { + if (ownedTab) { return html`
${tab.name!} ${this.renderDeleteFor(tab)}
`; + } else { + return html`
${tab.name!}
`; } }