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 update: or-app header current menu item selection highlighting bug fix (Fixes #577)
Rich Turner20f7cfc4b9a4
diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.tsindex 6bcae97fc..eba7b79e9 100644--- a/ui/component/or-app/src/index.ts+++ b/ui/component/or-app/src/index.ts@@ -94,6 +94,9 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {@state()protected _realm?: string;+ @state()+ protected _activeMenu?: string;+protected _realms!: Tenant[];protected _store: EnhancedStore<S, AnyAction, ReadonlyArray<ThunkMiddleware<S>>>;protected _storeUnsubscribe!: Unsubscribe;@@ -238,6 +241,17 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {this._initialised = true;+ // Create route listener to set header active item (this must be done before any routes added)+ const headerUpdater = (activeMenu: string | undefined) => {+ this._activeMenu = activeMenu;+ };+ router.hooks({+ before(done, match) {+ headerUpdater(match ? match.url.split('/')[0] : undefined);+ done();+ }+ });+// Configure routesthis.appConfig.pages.forEach((pageProvider, index) => {if (pageProvider.routes) {@@ -339,7 +353,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {${this._config.styles ? typeof(this._config.styles) === "string" ? html`<style>${this._config.styles}</style>` : this._config.styles.strings : ``}${consoleStyles}${this._config.header ? html`- <or-header .store="${this._store}" .realm="${this._realm}" .realms="${this._realms}" .logo="${this._config.logo}" .logoMobile="${this._config.logoMobile}" .config="${this._config.header}"></or-header>+ <or-header .activeMenu="${this._activeMenu}" .store="${this._store}" .realm="${this._realm}" .realms="${this._realms}" .logo="${this._config.logo}" .logoMobile="${this._config.logoMobile}" .config="${this._config.header}"></or-header>` : ``}<!-- Main content -->diff --git a/ui/component/or-app/src/or-header.ts b/ui/component/or-app/src/or-header.tsindex 923308eb9..1cd9dfd6e 100644--- a/ui/component/or-app/src/or-header.ts+++ b/ui/component/or-app/src/or-header.ts@@ -84,7 +84,7 @@ function getCurrentMenuItemRef(defaultRef?: string): string | undefined {}@customElement("or-header")-class OrHeader extends LitElement {+export class OrHeader extends LitElement {// language=CSSstatic get styles() {@@ -353,18 +353,11 @@ class OrHeader extends LitElement {@query("div[id=mobile-bottom]")protected _mobileBottomDiv!: HTMLDivElement;- @state()- private _drawerOpened = false;+ @property()+ public activeMenu: string | undefined;@state()- private activeMenu: string | undefined;-- constructor() {- super();- router.on("*", (match) => {- this.activeMenu = match ? match.url : undefined;- });- }+ private _drawerOpened = false;public _onRealmSelect(realm: string) {this.store.dispatch(updateRealm(realm));@@ -379,8 +372,12 @@ class OrHeader extends LitElement {protected render() {- const mainItems = this.config ? this.config.mainMenu : undefined;- const secondaryItems = this.config ? this.config.secondaryMenu : undefined;+ if (!this.config) {+ return html``;+ }++ const mainItems = this.config.mainMenu;+ const secondaryItems = this.config.secondaryMenu;return html`<!-- Header -->