100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Improve large asset tree rendering (#848)
Jérôme Vervier4678ef23217c
diff --git a/ui/app/manager/src/pages/page-assets.ts b/ui/app/manager/src/pages/page-assets.tsindex 540558fb2..d58a06037 100644--- a/ui/app/manager/src/pages/page-assets.ts+++ b/ui/app/manager/src/pages/page-assets.ts@@ -55,9 +55,9 @@ const pageAssetsSlice = createSlice({expandedParents.push({ realm: manager.displayRealm, ids: []});}const expandedId = expandedParents.findIndex(x => x.realm == manager.displayRealm);- if(!action.payload[1] && expanded.ids.includes(action.payload[0])) {+ if(!action.payload[1] && expanded && expanded.ids && expanded.ids.includes(action.payload[0])) {expandedParents[expandedId].ids = expanded.ids.filter((parent) => parent != action.payload[0]); // filter out collapsed ones- } else if(!expanded || (action.payload[1] && !expanded.ids.includes(action.payload[0]))) {+ } else if(!expanded || (action.payload[1] && expanded && expanded.ids && !expanded.ids.includes(action.payload[0]))) {expandedParents[expandedId].ids.push(action.payload[0]); // add new extended ones}return { ...state, expandedParents: expandedParents }diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex 6abfa83f2..f8316cb72 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -627,23 +627,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {return result;}- protected updated(_changedProperties: PropertyValues) {-- // After nodes have been rendered, expand entries if necessary- // (for example reopening parents after switching back to the asset page)- if (_changedProperties.has("_nodes")) {- if(!this.expandAllNodes && this.expandedIds && this.expandedIds.length > 0) {- this.expandedIds.forEach((id) => {- const node = this._findNodeFromAssetId(id);- let elem = this.shadowRoot?.querySelector('[node-asset-id="' + id + '"]');- if(elem && node && !node.expanded) {- this._toggleExpander(elem.firstElementChild!.firstElementChild! as HTMLElement, node);- }- });- }- }- }-protected _updateSelectedNodes() {const actuallySelectedIds: string[] = [];const selectedNodes: UiAssetTreeNode[] = [];@@ -715,6 +698,30 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {const elem = expander.parentElement!.parentElement!.parentElement!;elem.toggleAttribute("data-expanded");this.dispatchEvent(new OrAssetTreeToggleExpandEvent({ node: node }));+ this.requestUpdate();+ }+ }++ /**+ * This method is used to avoid to re-render and erase all the this.selectedIds attribute+ *+ * @param expander+ * @param node+ * @protected+ */+ protected _toggleExpanderWithoutEventDispatch(expander: HTMLElement, node: UiAssetTreeNode | null) {+ if (node && node.expandable) {+ node.expanded = !node.expanded;++ if (node.expanded) {+ this._expandedNodes.push(node);+ } else {+ this._expandedNodes = this._expandedNodes.filter(n => n !== node);+ }++ const elem = expander.parentElement!.parentElement!.parentElement!;+ elem.toggleAttribute("data-expanded");+ this.requestUpdate();}}@@ -1860,16 +1867,19 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {if (assetId && this.isExpandable(assetId) && !this._expandTimer) {this._expandTimer = window.setTimeout(() => {- this.expandeNode(assetId);+ this.expandNode(assetId);}, 1000);}}- protected expandeNode(assetId: string | null): void {+ protected expandNode(assetId: string | null): void {if (this.shadowRoot && assetId && assetId === this._dragDropParentId) {- let elem: HTMLElement | null = this.shadowRoot.querySelector('[node-asset-id="' + assetId + '"]');+ const node = this._findNodeFromAssetId(assetId);+ let elem: HTMLElement | null = this.shadowRoot?.querySelector('[node-asset-id="' + assetId + '"]');+ if(elem && node && !node.expanded) {- elem?.parentElement?.setAttribute('data-expanded','');+ this._toggleExpanderWithoutEventDispatch(elem.firstElementChild!.firstElementChild! as HTMLElement, node);+ }}}@@ -1893,7 +1903,6 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {}protected _treeNodeTemplate(treeNode: UiAssetTreeNode, level: number): TemplateResult | string | undefined {-const descriptor = AssetModelUtil.getAssetDescriptor(treeNode.asset!.type!);let parentCheckboxIcon;@@ -1919,6 +1928,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {treeNode.expanded = false;}+ if (this.expandedIds && this.expandedIds.findIndex((expandId: string) => { return expandId === treeNode.asset!.id!; }) !== -1) {+ treeNode.expanded = true;+ }+return html`<li class="asset-list-element" ?data-selected="${treeNode.selected}" ?data-expanded="${treeNode.expanded}" @click="${(evt: MouseEvent) => this._onNodeClicked(evt, treeNode)}"><div class="in-between-element" node-asset-id="${treeNode.parent ? (treeNode.parent.asset ? treeNode.parent.asset.id : '' ) : undefined}" @dragleave=${(ev: DragEvent) => { this._onDragLeave(ev) }} @dragenter="${(ev: DragEvent) => this._onDragEnter(ev)}" @dragend="${(ev: DragEvent) => this._onDragEnd(ev)}" @dragover="${(ev: DragEvent) => this._onDragOver(ev)}"></div>@@ -1942,7 +1955,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {</div></div><ol>- ${!treeNode.children ? `` : treeNode.children.map((childNode) => this._treeNodeTemplate(childNode, level + 1)).filter(t => !!t)}+ ${!treeNode.children || (treeNode.expandable && !treeNode.expanded) ? `` : treeNode.children.map((childNode) => this._treeNodeTemplate(childNode, level + 1)).filter(t => !!t)}</ol></li>`;diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 2a16d2329..b949776b7 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -1229,7 +1229,10 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElemev.stopPropagation();};- const dialogContent = html`<or-asset-tree id="parent-asset-tree" disableSubscribe readonly .selectedIds="${[]}" @or-asset-tree-request-select="${blockEvent}" @or-asset-tree-selection-changed="${blockEvent}"></or-asset-tree>`;+ const dialogContent = html`+ <or-asset-tree id="parent-asset-tree" disableSubscribe readonly .selectedIds="${[]}"+ @or-asset-tree-request-select="${blockEvent}"+ @or-asset-tree-selection-changed="${blockEvent}"></or-asset-tree>`;const setParent = () => {const assetTree = dialog.shadowRoot!.getElementById("parent-asset-tree") as OrAssetTree;@@ -1264,29 +1267,32 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem.setContent(dialogContent).setActions(dialogActions).setStyles(html`- <style>- .mdc-dialog__surface {- width: 400px;- height: 800px;- display: flex;- overflow: visible;- overflow-x: visible !important;- overflow-y: visible !important;- }- #dialog-content {- flex: 1;- overflow: visible;- min-height: 0;- padding: 0;- }- footer.mdc-dialog__actions {- border-top: 1px solid ${unsafeCSS(DefaultColor5)};- }- or-asset-tree {- height: 100%;- }- </style>- `)+ <style>+ .mdc-dialog__surface {+ width: 400px;+ height: 800px;+ display: flex;+ overflow: visible;+ overflow-x: visible !important;+ overflow-y: visible !important;+ }++ #dialog-content {+ flex: 1;+ overflow: visible;+ min-height: 0;+ padding: 0;+ }++ footer.mdc-dialog__actions {+ border-top: 1px solid ${unsafeCSS(DefaultColor5)};+ }++ or-asset-tree {+ height: 100%;+ }+ </style>+ `).setHeading(i18next.t("setParent")).setDismissAction(null));}diff --git a/ui/component/or-mwc-components/src/or-mwc-input.ts b/ui/component/or-mwc-components/src/or-mwc-input.tsindex d9908cb24..031d8a925 100644--- a/ui/component/or-mwc-components/src/or-mwc-input.ts+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts@@ -1462,8 +1462,7 @@ export class OrMwcInput extends LitElement {(this._mdcComponent as any).foundation.adapter.floatLabel(!!selectedText);// Set width of fixed select menu to match the component width- this.shadowRoot!.getElementById("mdc-select-menu")!.style.width = component.getBoundingClientRect().width + "px";-+ //this.shadowRoot!.getElementById("mdc-select-menu")!.style.width = component.getBoundingClientRect().width + "px";// This overrides the standard mdc menu body click capture handler as it doesn't work with webcomponents(mdcSelect as any).menu.menuSurface_.foundation.handleBodyClick = function (evt: MouseEvent) {