From d224e95f7d54c72745eec783a8384bc059bd0d8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Sat, 18 Feb 2023 22:04:52 +0100 Subject: [PATCH] determine wether tab has properties --- .../workspace/document-workspace.context.ts | 19 +++++++++++ ...ocument-workspace-view-edit-tab.element.ts | 32 ++++++++++++++++--- .../document-workspace-view-edit.element.ts | 7 ++-- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts index 050c92aa9c..5fa4f286e1 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/document-workspace.context.ts @@ -190,6 +190,19 @@ export class UmbDocumentWorkspaceContext ); } + hasPropertyStructuresOf(containerKey: string | null) { + return this.#documentTypes.getObservablePart((docTypes) => { + return ( + docTypes.find((docType) => { + return docType.properties?.find((property) => { + if (property.containerKey === containerKey) { + return true; + } + }); + }) !== undefined + ); + }); + } rootPropertyStructures() { return this.propertyStructuresOf(null); } @@ -215,6 +228,12 @@ export class UmbDocumentWorkspaceContext }); } + hasRootContainers(containerType: 'Group' | 'Tab') { + return this.#containers.getObservablePart((data) => { + return data.filter((x) => x.parentKey === null && x.type === containerType).length > 0; + }); + } + containersOfParentKey( parentKey: DocumentTypePropertyTypeContainerModel['parentKey'], containerType: 'Group' | 'Tab' diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit-tab.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit-tab.element.ts index d29702a42e..40a79f9467 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit-tab.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit-tab.element.ts @@ -58,6 +58,9 @@ export class UmbDocumentWorkspaceViewEditTabElement extends UmbLitElement { @state() _tabContainers: PropertyTypeContainerViewModelBaseModel[] = []; + @state() + _hasTabProperties = false; + @state() _groups: Array = []; @@ -73,6 +76,20 @@ export class UmbDocumentWorkspaceViewEditTabElement extends UmbLitElement { }); } + private _observeHasTabProperties() { + if (!this._workspaceContext) return; + + this._tabContainers.forEach((container) => { + this.observe( + this._workspaceContext!.hasPropertyStructuresOf(container.key!), + (hasTabProperties) => { + this._hasTabProperties = hasTabProperties; + }, + '_observeHasTabProperties_' + container.key + ); + }); + } + private _observeTabContainers() { if (!this._workspaceContext) return; @@ -83,6 +100,7 @@ export class UmbDocumentWorkspaceViewEditTabElement extends UmbLitElement { (tabContainers) => { this._tabContainers = tabContainers || []; if (this._tabContainers.length > 0) { + this._observeHasTabProperties(); this._observeGroups(); } }, @@ -127,11 +145,15 @@ export class UmbDocumentWorkspaceViewEditTabElement extends UmbLitElement { render() { // TODO: only show tab properties if there was any. We need some event? to tell us when the properties is empty. return html` - - - + ${this._hasTabProperties + ? html` + + + + ` + : ''} ${repeat( this._groups, (group) => group.name, diff --git a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit.element.ts b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit.element.ts index 735cc2dfa0..b1ceb68394 100644 --- a/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit.element.ts +++ b/src/Umbraco.Web.UI.Client/src/backoffice/documents/documents/workspace/views/document-workspace-view-edit.element.ts @@ -80,10 +80,9 @@ export class UmbDocumentWorkspaceViewEditElement extends UmbLitElement { */ this.observe( - this._workspaceContext.containersOfParentKey(null, 'Group'), - (rootGroups) => { - this._hasRootGroups = rootGroups.length > 0; - console.log('this._hasRootGroups', this._hasRootGroups); + this._workspaceContext.hasRootContainers('Group'), + (hasRootGroups) => { + this._hasRootGroups = hasRootGroups; this._createRoutes(); }, '_observeTabs'