determine wether tab has properties

This commit is contained in:
Niels Lyngsø
2023-02-18 22:04:52 +01:00
parent 0b1a9894ab
commit d224e95f7d
3 changed files with 49 additions and 9 deletions

View File

@@ -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'

View File

@@ -58,6 +58,9 @@ export class UmbDocumentWorkspaceViewEditTabElement extends UmbLitElement {
@state()
_tabContainers: PropertyTypeContainerViewModelBaseModel[] = [];
@state()
_hasTabProperties = false;
@state()
_groups: Array<PropertyTypeContainerViewModelBaseModel> = [];
@@ -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`
<uui-box>
<umb-document-workspace-view-edit-properties
container-type="Tab"
container-name=${this.tabName || ''}></umb-document-workspace-view-edit-properties>
</uui-box>
${this._hasTabProperties
? html`
<uui-box>
<umb-document-workspace-view-edit-properties
container-type="Tab"
container-name=${this.tabName || ''}></umb-document-workspace-view-edit-properties>
</uui-box>
`
: ''}
${repeat(
this._groups,
(group) => group.name,

View File

@@ -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'