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
Replace Material UI menus with Vaadin components (#2911)
Martin Peetersf7349686fbed
diff --git a/ui/app/manager/test/rules.test.ts b/ui/app/manager/test/rules.test.tsindex 0592dcff9..aae80d6e5 100644--- a/ui/app/manager/test/rules.test.ts+++ b/ui/app/manager/test/rules.test.ts@@ -108,13 +108,13 @@ test("Create a When-Then rule for an asset with a trigger and action", async ({pawait manager.goToRealmStartPage("smartcity");await manager.navigateToTab("Rules");await page.click(".mdi-plus >> nth=0");- await page.locator("li").filter({hasText: "When-Then"}).click();+ await page.getByRole("menuitem", {name: "When-Then", exact: true}).click();await page.getByRole("textbox", { name: "Rule name" }).fill(energyRule.name);// When clauseconst when = page.locator("or-rule-when");- await when.getByRole("button", { name: "Add condition", exact: true }).click();- await when.locator("li[role='menuitem']").filter({hasText: energyRule.asset_type}).click();+ await when.getByRole("menuitem", {name: "Add condition"}).click();+ await when.getByRole("menuitem", {name: energyRule.asset_type}).click();await when.getByRole("combobox", { name: "Asset", exact: true }).click();await when.getByRole("option", { name: energyRule.asset, exact: true }).click();await when.getByRole("combobox", { name: "Attribute", exact: true }).click();@@ -125,8 +125,8 @@ test("Create a When-Then rule for an asset with a trigger and action", async ({p// Then clauseconst then = page.locator("or-rule-then-otherwise")- await then.getByRole("button", {name: "Add action", exact: true}).click();- await then.locator("li[role='menuitem']").filter({hasText: energyRule.asset_type}).click();+ await then.getByRole("menuitem", {name: "Add action"}).click();+ await then.getByRole("menuitem", {name: energyRule.asset_type}).click();await then.getByRole("combobox", { name: "Asset", exact: true }).click();await then.getByRole("option", { name: energyRule.asset, exact: true }).click();await then.getByRole("combobox", {name: "Attribute", exact: true}).click();@@ -164,13 +164,13 @@ test("Create a When-Then rule by searching for an asset", async ({page, manager,expect(lastAssetName).toContain(energyRule.asset);await page.click(".mdi-plus >> nth=0");- await page.locator("li").filter({hasText: "When-Then"}).click();+ await page.getByRole("menuitem", {name: "When-Then", exact: true}).click();await page.getByRole("textbox", { name: "Rule name" }).fill(energyRule.name);// Select asset type of the When clause, search for the last asset in the list, and select the attributeconst when = page.locator("or-rule-when")- await when.getByRole("button", { name: "Add condition" }).click();- await when.locator("li[role='menuitem']").filter({hasText: energyRule.asset_type}).click();+ await when.getByRole("menuitem", {name: "Add condition"}).click();+ await when.getByRole("menuitem", {name: energyRule.asset_type}).click();await when.getByRole("combobox", {name: "Asset", exact: true}).fill(lastAssetName);await when.getByRole("option", { name: lastAssetName, exact: true }).click();await when.getByRole("combobox", {name: "Attribute", exact: true}).fill(energyRule.attribute_when);@@ -181,8 +181,8 @@ test("Create a When-Then rule by searching for an asset", async ({page, manager,// Configure Then clauseconst then = page.locator("or-rule-then-otherwise");- await then.getByRole("button", {name: "Add action"}).click();- await then.locator("li[role='menuitem']").filter({hasText: energyRule.asset_type}).click();+ await then.getByRole("menuitem", {name: "Add action"}).click();+ await then.getByRole("menuitem", {name: energyRule.asset_type}).click();await then.getByRole("combobox", {name: "Asset", exact: true}).fill(firstAssetName);await then.getByRole("option", {name: firstAssetName, exact: true}).click();await then.getByRole("combobox", {name: "Attribute", exact: true}).fill(energyRule.attribute_then);@@ -211,7 +211,7 @@ test("Create a Flow rule for an asset with logic connections", async ({page, shaawait manager.goToRealmStartPage("smartcity");await manager.navigateToTab("Rules");await page.click(".mdi-plus >> nth=0");- await page.locator("li", {hasText: "Flow"}).click();+ await page.getByRole("menuitem", {name: "Flow", exact: true}).click();await page.getByRole("textbox", { name: "Rule name" }).fill("Solar panel");await page.locator(".node-item.input-node", {hasText: "Attribute value"}).hover();@@ -294,7 +294,7 @@ test("Legacy JavaScript rules are visible but read-only in the rules UI", asyncawait expect(page.locator("or-rule-tree").locator("or-mwc-input[icon='content-copy']")).toHaveCount(0);await page.click(".mdi-plus >> nth=0");- await expect(page.locator("li").filter({hasText: "JavaScript"})).toHaveCount(0);+ await expect(page.getByRole("menuitem", {name: "JavaScript", exact: true})).toHaveCount(0);expect(api.postRequests).toBe(0);expect(api.putRequests).toBe(0);diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.tsindex ea643e19c..61d176450 100644--- a/ui/component/or-app/src/index.ts+++ b/ui/component/or-app/src/index.ts@@ -2,7 +2,6 @@ import {css, html, LitElement, PropertyValues, TemplateResult, unsafeCSS} from "import {customElement, property, query, state} from "lit/decorators.js";import {AppConfig, Page, RealmAppConfig, router} from "./types";import "@openremote/or-translate";-import "@openremote/or-mwc-components/or-mwc-menu";import "@openremote/or-mwc-components/or-mwc-snackbar";import "./or-header";import "@openremote/or-icon";@@ -15,8 +14,15 @@ import {OrMwcSnackbar, showSnackbar} from "@openremote/or-mwc-components/or-mwc-import {AnyAction, Store, Unsubscribe} from "@reduxjs/toolkit";import {AppStateKeyed, setOffline, setVisibility, updatePage, updateRealm} from "./app";import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {+ dialogFooterRenderer,+ dialogHeaderRenderer,+ dialogRenderer,+ OrVaadinDialog+} from "@openremote/or-vaadin-components/or-vaadin-dialog";import {Auth, ManagerConfig, Realm} from "@openremote/model";import {pageOfflineProvider} from "./page-offline";+import { ifDefined } from "lit/directives/if-defined.js";export const DefaultLogo = require("../images/logo.svg");export const DefaultMobileLogo = require("../images/logo-mobile.svg");@@ -82,6 +88,9 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {@state()protected _activeMenu?: string;+ @query("#language-dialog")+ protected _languageDialog?: OrVaadinDialog;+protected _onEvent = (ev: OREvent) => this._handleEvent(ev);protected _onVisibilityChanged = (ev: Event) => this._handleVisibilityChange(ev);protected _realms!: Realm[];@@ -432,6 +441,8 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {<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>` : ``}+ ${this._getLanguageDialogTemplate()}+<!-- Main content --><main role="main" class="main-content d-none"></main>@@ -473,6 +484,39 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}}+ protected _getLanguageDialogTemplate(): TemplateResult {+ const languages = Object.entries(this.appConfig!.languages || DEFAULT_LANGUAGES);+ const selected = languages.findIndex(([key]) => key === manager.language);+ const onchange = (ev: CustomEvent) => {+ const lang = languages[ev.detail.value]?.[0] ?? languages[0][0];+ if (lang !== manager.language) {+ this.setLanguage(lang);+ this._languageDialog?.close();+ }+ }+ const header = () => html`+ <h2 style="padding-left: 7px; margin: 0;">+ <or-translate value="language"></or-translate>+ </h2>+ `;+ const content = () => html`+ <or-vaadin-list-box selected=${ifDefined(selected)} style="margin: 0 -18px 6px -18px;"+ @selected-changed=${(ev: CustomEvent) => onchange(ev)}>+ ${languages.map(([key, value]) => html`+ <or-vaadin-item value=${key}>+ <or-translate value=${value}></or-translate>+ </or-vaadin-item>+ `)}+ </or-vaadin-list-box>+ `+ return html`+ <or-vaadin-dialog id="language-dialog" width="240px"+ ${dialogHeaderRenderer(header)}+ ${dialogRenderer(content)}+ ></or-vaadin-dialog>+ `+ }+// Offline timer logic//// This will start a Deferred promise that keeps track of the 'wait before showing offline page' timer.@@ -524,18 +568,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}public showLanguageModal() {- showDialog(new OrMwcDialog()- .setHeading("language")- .setDismissAction(null)- .setStyles(html`<style>.selected { color: ${unsafeCSS(DefaultColor4)} }</style>`)- .setActions(Object.entries(this.appConfig!.languages || DEFAULT_LANGUAGES).map(([key, value]) => {- return {- content: html`<span class="${(key === manager.language) ? 'selected' : ''}">${i18next.t(value)}</span>`,- actionName: key,- action: () => {- manager.language = key;- }- }})));+ this._languageDialog?.open();}protected doAppConfigInit() {diff --git a/ui/component/or-app/src/or-header.ts b/ui/component/or-app/src/or-header.tsindex 015715725..8541aca55 100644--- a/ui/component/or-app/src/or-header.ts+++ b/ui/component/or-app/src/or-header.ts@@ -195,11 +195,6 @@ export class OrHeader extends LitElement {display: inline-block;line-height: var(--internal-or-header-height);}-- or-mwc-menu {- margin-right: 10px;- display: block;- }.or-language-container {display: flex;diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex f14a00933..8c2820b70 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -30,7 +30,6 @@ import {style} from "./style";import manager, {EventCallback, subscribe, Util} from "@openremote/core";import Qs from "qs";import {getAssetDescriptorIconTemplate, OrIcon} from "@openremote/or-icon";-import "@openremote/or-mwc-components/or-mwc-menu";import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";import "@openremote/or-mwc-components/or-mwc-list";import {i18next} from "@openremote/or-translate";diff --git a/ui/component/or-attribute-barchart/src/index.ts b/ui/component/or-attribute-barchart/src/index.tsindex dc3d505f2..c9161ab16 100644--- a/ui/component/or-attribute-barchart/src/index.ts+++ b/ui/component/or-attribute-barchart/src/index.ts@@ -42,7 +42,6 @@ import {isAxiosError} from "@openremote/rest";import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";import {cache} from "lit/directives/cache.js";-import "@openremote/or-mwc-components/or-mwc-menu";import {createMenuBarItem, MenuBarItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";import {OrVaadinDateTimePicker} from "@openremote/or-vaadin-components/or-vaadin-date-time-picker";import {when} from "lit/directives/when.js";diff --git a/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts b/ui/component/or-dashboard-builder/src/or-dashboard-tree.tsindex 88764af6b..ece187148 100644--- a/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts+++ b/ui/component/or-dashboard-builder/src/or-dashboard-tree.ts@@ -24,7 +24,6 @@ import {style} from './style';import {Dashboard} from '@openremote/model';import manager, {Util} from '@openremote/core';import {ListItem} from '@openremote/or-mwc-components/or-mwc-list';-import '@openremote/or-mwc-components/or-mwc-menu';import {showOkCancelDialog} from '@openremote/or-mwc-components/or-mwc-dialog';import {i18next, translate} from '@openremote/or-translate';import {showSnackbar} from '@openremote/or-mwc-components/or-mwc-snackbar';diff --git a/ui/component/or-log-viewer/src/index.ts b/ui/component/or-log-viewer/src/index.tsindex d0d4f28ea..4cc846cf9 100644--- a/ui/component/or-log-viewer/src/index.ts+++ b/ui/component/or-log-viewer/src/index.ts@@ -15,7 +15,6 @@ import "@openremote/or-components/or-panel";import "@openremote/or-translate";import {MDCDataTable} from "@material/data-table";import moment from "moment";-import "@openremote/or-mwc-components/or-mwc-menu";import type { GenericAxiosResponse } from "axios";import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";import {OrVaadinSelect} from "@openremote/or-vaadin-components/or-vaadin-select";diff --git a/ui/component/or-mwc-components/src/or-mwc-menu.ts b/ui/component/or-mwc-components/src/or-mwc-menu.tsindex ebdbe4cdf..11e74fc9e 100644--- a/ui/component/or-mwc-components/src/or-mwc-menu.ts+++ b/ui/component/or-mwc-components/src/or-mwc-menu.ts@@ -74,6 +74,9 @@ export function positionMenuAtElement<T extends OrMwcMenu>(return menu;}+/**+ * @deprecated Please use the <or-vaadin-*> components instead.+ */export function getContentWithMenuTemplate(content: TemplateResult, menuItems: (ListItem | ListItem[] | null)[], selectedValues: string[] | string | undefined, valueChangedCallback: (values: string[] | string) => void, closedCallback?: () => void, multiSelect = false, translateValues = true, midHeight = false, fullWidth = false, menuId = "menu", fixedToHost = false): TemplateResult {let menuRef: OrMwcMenu | null = null; // Reference to the menudiff --git a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts b/ui/component/or-rules/src/json-viewer/or-rule-condition.tsindex 5650936c8..9e3931117 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts@@ -4,20 +4,18 @@ import {AssetTypeInfo, RuleCondition, WellknownAssets, AssetModelUtil, AssetQuerimport {ConditionType, getAssetTypeFromQuery, RulesConfig} from "../index";import "./or-rule-asset-query";import "./or-rule-trigger-query";-import "@openremote/or-mwc-components/or-mwc-menu";-import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";-import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";import "@openremote/or-icon";import "@openremote/or-translate";import {Util} from "@openremote/core";import {i18next, translate} from "@openremote/or-translate";import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";import {OrRuleAssetQuery} from "./or-rule-asset-query";+import {createMenuBarItem, MenuBarItem, SubMenuItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";const TIMER_COLOR = "4b87ea";const DATE_TIME_COLOR = "6AEAA4";-export function getWhenTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[]): (ListItem | null)[] {+export function getWhenTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[], selectedType?: string): SubMenuItem[] {let addAssetTypes = true;let addAgentTypes = true;@@ -29,59 +27,58 @@ export function getWhenTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfaddTimer = config.controls.allowedConditionTypes.indexOf(ConditionType.TIME) >= 0;}- const menu: (ListItem | null)[] = [];+ const getMenuItem = (assetTypeInfo: AssetTypeInfo): SubMenuItem => {+ const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);+ const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);+ return {+ checked: selectedType && assetTypeInfo.assetDescriptor!.name === selectedType,+ component: createMenuBarItem(html`+ <div style="display: flex; align-items: center; gap: 6px;">+ <or-icon style=${color ? `--or-icon-fill: #${color}` : undefined}+ icon=${icon ? icon : AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET)}+ ></or-icon>+ <span>${Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!)}</span>+ </div>+ `),+ value: assetTypeInfo.assetDescriptor!.name,+ } as SubMenuItem;+ }++ const menu: SubMenuItem[] = [];if (assetInfos) {if (addAssetTypes) {- const items = assetInfos.filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent").map((assetTypeInfo) => {+ const items = assetInfos+ .filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent")+ .sort(Util.sortByString(assetTypeInfo => Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!)))+ .map(getMenuItem);- const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);- const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);- const styleMap = color ? {"--or-icon-fill": "#" + color} : undefined;-- return {- text: Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!),- value: assetTypeInfo.assetDescriptor!.name,- icon: icon ? icon : AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET),- styleMap: styleMap- } as ListItem;- });-- menu.push(...items.sort(Util.sortByString((listItem) => listItem.text!)));+ menu.push(...items);}if (addAssetTypes && addAgentTypes) {- menu.push(null);+ menu.push({ component: "hr" });}if (addAgentTypes) {- const items = assetInfos.filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType === "agent").map((assetTypeInfo) => {-- const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);- const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);- const styleMap = color ? {"--or-icon-fill": "#" + color} : undefined;-- return {- text: Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!),- value: assetTypeInfo.assetDescriptor!.name,- icon: icon ? icon : AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET),- styleMap: styleMap- } as ListItem;- });-- menu.push(...items.sort(Util.sortByString((listItem) => listItem.text!)));+ const items = assetInfos+ .filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType === "agent")+ .sort(Util.sortByString(assetTypeInfo => Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!)))+ .map(getMenuItem);+ menu.push(...items);}}if (addTimer) {- menu.push(null);+ menu.push({ component: "hr" });menu.push({- text: i18next.t("time"),- icon: "timer",+ component: createMenuBarItem(html`+ <or-icon style="--or-icon-fill: #${TIMER_COLOR}" icon="timer"></or-icon>+ <or-translate value="time"></or-translate>+ `),value: ConditionType.TIME,- styleMap: {"--or-icon-fill": "#" + TIMER_COLOR}- } as ListItem);+ } as SubMenuItem);}return menu;@@ -183,22 +180,24 @@ class OrRuleCondition extends translate(i18next)(LitElement) {}if(this.readonly) {typeTemplate = html`- <div id="type" style="--or-icon-fill: #${buttonColor}">- <or-vaadin-button disabled theme="icon tertiary">- <or-icon icon=${buttonIcon ?? ""}></or-icon>- </or-vaadin-button>- </div>+ <div id="type" style="--or-icon-fill: #${buttonColor}">+ <or-vaadin-button disabled theme="icon tertiary">+ <or-icon icon=${buttonIcon ?? ""}></or-icon>+ </or-vaadin-button>+ </div>`;} else {+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`<or-icon icon=${buttonIcon ?? ""}></or-icon>`),+ children: getWhenTypesMenu(this.config, this.assetInfos, type)+ }]typeTemplate = html`- <div id="type" style="--or-icon-fill: #${buttonColor}">- ${getContentWithMenuTemplate(- html`<or-vaadin-button theme="icon tertiary"><or-icon icon=${buttonIcon ?? ""}></or-icon></or-vaadin-button>`,- getWhenTypesMenu(this.config, this.assetInfos),- type,- (value) => this.type = value as ConditionType)}- </div>- `;+ <div id="type" style="--or-icon-fill: #${buttonColor}">+ <or-vaadin-menu-bar theme="icon" .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this.type = ev.detail.value.value}>+ </or-vaadin-menu-bar>+ </div>+ `;}}@@ -236,7 +235,7 @@ class OrRuleCondition extends translate(i18next)(LitElement) {protected set type(value: string | ConditionType | undefined) {updateRuleConditionType(this.ruleCondition, value, this.config);- if (this._assetQuery) {+ if (this._assetQuery?.refresh) {this._assetQuery.refresh();}this.dispatchEvent(new OrRulesJsonRuleChangedEvent());diff --git a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.tsindex e630b6ffe..10ebd63d8 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts@@ -1,9 +1,12 @@import {css, html, LitElement, TemplateResult} from "lit";import {customElement, property} from "lit/decorators.js";+import { when } from "lit/directives/when.js";import {buttonStyle} from "../style";import "./or-rule-asset-query";import {ActionType, getAssetTypeFromQuery, RulesConfig} from "../index";import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";+import {OrVaadinSelect, SelectItem} from "@openremote/or-vaadin-components/or-vaadin-select";+import {createMenuBarItem, MenuBarItem, SubMenuItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";import {AbstractNotificationMessageUnion,AlarmSeverity,@@ -21,8 +24,6 @@ import {WellknownAssets} from "@openremote/model";import {i18next, translate} from "@openremote/or-translate"-import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";-import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";import {manager, Util} from "@openremote/core";import "./or-rule-action-attribute";import "./or-rule-action-notification";@@ -33,7 +34,7 @@ const NOTIFICATION_COLOR = "4B87EA";const WAIT_COLOR = "EACC54";const ALARM_COLOR = "FC2D2D";-function getActionTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[]): (ListItem | null)[] {+function getActionTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[], selectedType?: string): SubMenuItem[] {let addAssetTypes = true;let addWait = true;@@ -64,70 +65,78 @@ function getActionTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[]):(x[0] === manager.displayRealm || x[0] === "default") && x[1] !== undefined).length > 0;}- const menu: (ListItem | null)[] = [];+ const menu: SubMenuItem[] = [];- if (addAssetTypes && assetInfos) {- menu.push(...assetInfos.filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent").map((assetTypeInfo) => {-- const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);- const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);- const styleMap = color ? {"--or-icon-fill": "#" + color} : undefined;+ const getMenuBarItem = (icon?: string, content?: string | TemplateResult, color?: string) => createMenuBarItem(html`+ <div style="display: flex; align-items: center; gap: 6px;">+ <or-icon style=${color ? `--or-icon-fill: #${color}` : undefined}+ icon=${icon ? icon : AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET)}+ ></or-icon>+ ${when(typeof content === "string",+ () => html`<span>${content}</span>`,+ () => content+ )}+ </div>+ `);- return {- text: Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!),- value: assetTypeInfo.assetDescriptor!.name,- icon: icon ? icon : AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET),- styleMap: styleMap- } as ListItem;+ if (addAssetTypes && assetInfos) {+ menu.push(...assetInfos+ .filter((assetInfo) => assetInfo.assetDescriptor!.descriptorType !== "agent")+ .sort(Util.sortByString(assetTypeInfo => assetTypeInfo.assetDescriptor!.name!))+ .map((assetTypeInfo) => {++ const color = AssetModelUtil.getAssetDescriptorColour(assetTypeInfo);+ const icon = AssetModelUtil.getAssetDescriptorIcon(assetTypeInfo);+ return {+ checked: selectedType && assetTypeInfo.assetDescriptor!.name === selectedType,+ component: getMenuBarItem(icon, Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!), color),+ value: assetTypeInfo.assetDescriptor!.name+ } as SubMenuItem;}));}- menu.sort(Util.sortByString((listItem) => listItem?.value!));- menu.push(null); // divider+ menu.push({ component: "hr" }); // dividerif (addEmailNotification) {+ const value: ActionType = multiLanguage && addEmailLocalizedNotification ? ActionType.EMAIL_LOCALIZED : ActionType.EMAILmenu.push({- text: i18next.t("email"),- icon: "email",- value: multiLanguage && addEmailLocalizedNotification ? ActionType.EMAIL_LOCALIZED : ActionType.EMAIL,- styleMap: {"--or-icon-fill": "#" + NOTIFICATION_COLOR}- } as ListItem);+ checked: selectedType && selectedType === value,+ component: getMenuBarItem("email", html`<or-translate value="email"></or-translate>`, NOTIFICATION_COLOR),+ value: value,+ } as SubMenuItem);}if (addPushNotification) {+ const value: ActionType = multiLanguage && addPushLocalizedNotification ? ActionType.PUSH_LOCALIZED : ActionType.PUSH_NOTIFICATION;menu.push({- text: i18next.t("push-notification"),- icon: "cellphone-message",- value: multiLanguage && addPushLocalizedNotification ? ActionType.PUSH_LOCALIZED : ActionType.PUSH_NOTIFICATION,- styleMap: {"--or-icon-fill": "#" + NOTIFICATION_COLOR}- } as ListItem);+ checked: selectedType && selectedType === value,+ component: getMenuBarItem("cellphone-message", html`<or-translate value="push-notification"></or-translate>`, NOTIFICATION_COLOR),+ value: value,+ } as SubMenuItem);}if (addWait) {menu.push({- text: i18next.t("wait"),- icon: "timer",+ checked: selectedType && selectedType === ActionType.WAIT,+ component: getMenuBarItem("timer", html`<or-translate value="wait"></or-translate>`, WAIT_COLOR),value: ActionType.WAIT,- styleMap: {"--or-icon-fill": "#" + WAIT_COLOR}- } as ListItem);+ } as SubMenuItem);}if (addAlarm) {menu.push({- text: i18next.t("alarm."),- icon: "bell-outline",+ checked: selectedType && selectedType === ActionType.ALARM,+ component: getMenuBarItem("bell-outline", html`<or-translate value="alarm."></or-translate>`, ALARM_COLOR),value: ActionType.ALARM,- styleMap: {"--or-icon-fill": "#" + ALARM_COLOR}- } as ListItem);+ } as SubMenuItem);}if (addWebhook) {menu.push({- text: i18next.t("webhook"),- icon: "webhook",+ checked: selectedType && selectedType === ActionType.WEBHOOK,+ component: getMenuBarItem("webhook", html`<or-translate value="webhook"></or-translate>`, NOTIFICATION_COLOR),value: ActionType.WEBHOOK,- styleMap: {"--or-icon-fill": "#" + NOTIFICATION_COLOR}- });+ } as SubMenuItem);}return menu;@@ -145,12 +154,12 @@ export enum RecurrenceOption {ONCE_PER_WEEK = "oncePerWeek",}-function getRecurrenceMenu(config?: RulesConfig): ListItem[] {+function getRecurrenceOptions(config?: RulesConfig): SelectItem[] {if (config && config.controls && config.controls.allowedRecurrenceOptions) {return config.controls.allowedRecurrenceOptions.map((value) => {return {- text: i18next.t(value),+ label: i18next.t(value),value: value};});@@ -158,7 +167,7 @@ function getRecurrenceMenu(config?: RulesConfig): ListItem[] {return Object.values(RecurrenceOption).map((value) => {return {- text: i18next.t(value),+ label: i18next.t(value),value: value};});@@ -177,6 +186,7 @@ const style = css`.rule-action {display: flex;margin: 10px 0;+ align-items: baseline;}.rule-action-wrapper {@@ -216,10 +226,6 @@ const style = css`margin-right: 6px;}- .add-button-wrapper or-mwc-menu {- text-transform: capitalize;- }-#type {white-space: nowrap;text-transform: capitalize;@@ -287,13 +293,11 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {</div>`;} else {- recurrenceTemplate = html`- <div style="margin-right: 6px;">- ${getContentWithMenuTemplate(- html`<or-vaadin-button><or-translate value="${value}"></or-translate></or-vaadin-button>`,- getRecurrenceMenu(this.config),- value,- (value) => this.setRecurrenceOption(value as RecurrenceOption))}+ recurrenceTemplate = html`+ <div style="margin-right: 6px; min-width: 180px;">+ <or-vaadin-select .items=${getRecurrenceOptions(this.config)} value=${value}+ @change=${(ev: Event) => this.setRecurrenceOption((ev.currentTarget as OrVaadinSelect).value as RecurrenceOption)}>+ </or-vaadin-select></div>`;}@@ -363,13 +367,15 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {</div>`;} else {+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`<or-icon icon=${buttonIcon ?? ""}></or-icon>`),+ children: getActionTypesMenu(this.config, this.assetInfos, type ?? action.action)+ }]typeTemplate = html`<div id="type" style="--or-icon-fill: #${buttonColor}">- ${getContentWithMenuTemplate(- html`<or-vaadin-button theme="icon tertiary"><or-icon icon=${buttonIcon ?? ""}></or-icon></or-vaadin-button>`,- getActionTypesMenu(this.config, this.assetInfos),- action.action,- (value) => this.setActionType(actions, action, value as string))}+ <or-vaadin-menu-bar theme="icon" .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this.setActionType(actions, action, ev.detail.value.value)}+ ></or-vaadin-menu-bar></div>`;}@@ -416,6 +422,15 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {protected render() {const thenAllowAdd = !this.readonly && (this.thenAllowAdd || this.rule.then!.length > 1);+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`+ <div style="display: flex; align-items: center; gap: 0.25em;">+ <or-icon icon="plus"></or-icon>+ <or-translate value="rulesEditorAddAction"></or-translate>+ </div>+ `),+ children: getActionTypesMenu(this.config, this.assetInfos)+ }]return html`<div><or-panel .heading="${i18next.t("then")}...">@@ -424,14 +439,9 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {${!this.rule.then ? `` : this.rule.then.map((action: RuleActionUnion) => this.ruleActionTemplate(this.rule.then!, action, this.readonly))}${thenAllowAdd ? html`<span class="add-button-wrapper">- ${getContentWithMenuTemplate(html`- <or-vaadin-button theme="tertiary">- <or-icon slot="prefix" icon="plus"></or-icon>- <or-translate value="rulesEditorAddAction"></or-translate>- </or-vaadin-button>`,- getActionTypesMenu(this.config, this.assetInfos),- undefined,- (value) => this.addAction(value as string))}+ <or-vaadin-menu-bar .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this.addAction(ev.detail.value.value)}+ ></or-vaadin-menu-bar></span>` : ``}</or-panel>diff --git a/ui/component/or-rules/src/json-viewer/or-rule-when.ts b/ui/component/or-rules/src/json-viewer/or-rule-when.tsindex 733631117..8ae014272 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-when.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-when.ts@@ -7,7 +7,8 @@ import "./or-rule-condition";import {i18next, translate} from "@openremote/or-translate"import {OrRulesJsonRuleChangedEvent} from "./or-rule-json-viewer";import {getWhenTypesMenu, updateRuleConditionType} from "./or-rule-condition";-import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";+import {createMenuBarItem, MenuBarItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";+import { when } from "lit/directives/when.js";enum ResetOption {NO_LONGER_MATCHES = "noLongerMatches",@@ -89,10 +90,6 @@ const style = css`.add-button-wrapper > * {margin-right: 6px;}-- .add-button-wrapper or-mwc-menu {- text-transform: capitalize;- }strong {margin: var(--internal-or-panel-heading-margin);@@ -197,18 +194,20 @@ class OrRuleWhen extends translate(i18next)(LitElement) {}if (!isTopLevel && showAddCondition) {+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`+ <div style="display: flex; align-items: center; gap: 0.25em;">+ <or-icon icon="plus"></or-icon>+ <or-translate value="rulesEditorAddCondition"></or-translate>+ </div>+ `),+ children: getWhenTypesMenu(this.config, this.assetInfos)+ }]addTemplate = html`<span class="add-button-wrapper">- ${getContentWithMenuTemplate(- html`- <or-vaadin-button theme="tertiary">- <or-icon slot="prefix" icon="plus"></or-icon>- <or-translate value="rulesEditorAddCondition"></or-translate>- </or-vaadin-button>- `,- getWhenTypesMenu(this.config, this.assetInfos),- undefined,- (value) => this.addCondition(group, value as string))}+ <or-vaadin-menu-bar .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this.addCondition(group, ev.detail.value.value)}+ ></or-vaadin-menu-bar></span>`;}@@ -255,23 +254,27 @@ class OrRuleWhen extends translate(i18next)(LitElement) {${this.ruleGroupTemplate(this.rule.when)}</div>- ${!showAddGroup ? `` : html`- <or-panel>- <strong>${i18next.t(!this.rule.when.groups || this.rule.when.groups.length === 0 ? "when" : "orWhen")}...</strong>- <span class="add-button-wrapper">- ${getContentWithMenuTemplate(- html`- <or-vaadin-button theme="tertiary">- <or-icon slot="prefix" icon="plus"></or-icon>- <or-translate value="rulesEditorAddCondition"></or-translate>- </or-vaadin-button>- `,- getWhenTypesMenu(this.config, this.assetInfos),- undefined,- (value) => this.addGroup(this.rule!.when!, value as string))}- </span>- </or-panel>- `}+ ${when(showAddGroup, () => {+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`+ <div style="display: flex; align-items: center; gap: 0.25em;">+ <or-icon icon="plus"></or-icon>+ <or-translate value="rulesEditorAddCondition"></or-translate>+ </div>+ `),+ children: getWhenTypesMenu(this.config, this.assetInfos)+ }]+ return html`+ <or-panel>+ <strong><or-translate value=${this.rule?.when?.groups?.length ? "orWhen" : "when"}></or-translate>...</strong>+ <span class="add-button-wrapper">+ <or-vaadin-menu-bar .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this.addGroup(this.rule!.when!, ev.detail.value.value)}+ </or-vaadin-menu-bar>+ </span>+ </or-panel>+ `+ })}`;}diff --git a/ui/component/or-rules/src/or-rule-tree.ts b/ui/component/or-rules/src/or-rule-tree.tsindex a1a1ff422..e1f85f31c 100644--- a/ui/component/or-rules/src/or-rule-tree.ts+++ b/ui/component/or-rules/src/or-rule-tree.ts@@ -20,13 +20,12 @@import {OrTreeMenu, TreeMenuSelection, TreeMenuSorting, TreeNode} from "@openremote/or-tree-menu";import {customElement, property, state} from "lit/decorators.js";import {RealmRuleset, RulesetLang, RulesetStatus, RulesetUnion} from "@openremote/model";+import {createMenuBarItem, MenuBarItem, SubMenuItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";import {css, html, PropertyValues, TemplateResult} from "lit";import manager, {Util} from "@openremote/core";import {i18next} from "@openremote/or-translate";-import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";import {showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";-import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";import {OrRules,OrRulesAddEvent,@@ -448,26 +447,28 @@ export class OrRuleTree extends OrTreeMenu {* Generates a HTML {@link TemplateResult} for the "add" button in the controls menu.*/protected _getAddActionTemplate(): TemplateResult {- const menuOptions: (ListItem | null)[] = (this._getAllowedLanguages() || []).map(l =>- ({value: l, text: i18next.t("rulesLanguages." + l)} as ListItem)- );- menuOptions.push(null);- menuOptions.push({value: "group", text: i18next.t("group")} as ListItem);++ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`<or-icon icon="plus"></or-icon>`),+ children: [+ ...(this._getAllowedLanguages() ?? []).map(l => ({+ component: createMenuBarItem(html`<or-translate value="rulesLanguages.${l}"></or-translate>`),+ value: l+ })),+ { component: "hr" },+ { component: createMenuBarItem(html`<or-translate value="group"></or-translate>`), value: "group" } as SubMenuItem+ ]+ }];const onValueChange = (value: string) => {value === "group" ? this._onGroupAddClick() : this._onRulesetAddClick(value as RulesetLang);};- return getContentWithMenuTemplate(- html`- <or-vaadin-button theme="icon" title=${i18next.t("addRule")}>- <or-icon icon="plus"></or-icon>- </or-vaadin-button>- `,- menuOptions,- undefined,- value => onValueChange(String(value))- );+ return html`+ <or-vaadin-menu-bar theme="icon" .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => onValueChange(ev.detail.value.value)}>+ </or-vaadin-menu-bar>+ `;}/**diff --git a/ui/component/or-tree-menu/package.json b/ui/component/or-tree-menu/package.jsonindex e2cb80842..1c732a0e3 100644--- a/ui/component/or-tree-menu/package.json+++ b/ui/component/or-tree-menu/package.json@@ -23,8 +23,8 @@"license": "AGPL-3.0-or-later","dependencies": {"@openremote/core": "workspace:*",- "@openremote/or-mwc-components": "workspace:*","@openremote/or-translate": "workspace:*",+ "@openremote/or-vaadin-components": "workspace:*","lit": "^3.3.1"},"devDependencies": {diff --git a/ui/component/or-tree-menu/src/index.ts b/ui/component/or-tree-menu/src/index.tsindex e4354dab9..d343bc7e4 100644--- a/ui/component/or-tree-menu/src/index.ts+++ b/ui/component/or-tree-menu/src/index.ts@@ -21,15 +21,13 @@ import {css, html, LitElement, PropertyValues, TemplateResult} from "lit";import {customElement, property, queryAll} from "lit/decorators.js";import {map} from "lit/directives/map.js";import {when} from "lit/directives/when.js";-import {InputType} from "@openremote/or-mwc-components/or-mwc-input";-import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";-import {ListItem} from "@openremote/or-mwc-components/or-mwc-list";import {Util} from "@openremote/core";import {OrTreeNode} from "./or-tree-node";import {OrTreeGroup} from "./or-tree-group";import {moveNodesToGroupNode} from "./util";import {OrTreeDragEvent, OrTreeSelectEvent, TreeMenuSelection, TreeMenuSorting, TreeNode} from "./model";-import {i18next} from "@openremote/or-translate";+import {createMenuBarItem, MenuBarItem, SubMenuItem} from "@openremote/or-vaadin-components/or-vaadin-menu-bar";+import "@openremote/or-translate";import "./or-tree-group";import "./or-tree-node";@@ -329,12 +327,19 @@ export class OrTreeMenu extends LitElement {* @param options - The available sorting options*/protected _getSortActionTemplate(value?: string, options?: TreeMenuSorting[]): TemplateResult {- return getContentWithMenuTemplate(- html`<or-mwc-input type=${InputType.BUTTON} icon="sort-variant" title="${i18next.t("sort")}"></or-mwc-input>`,- (options || []).map(sort => ({ value: sort, text: sort } as ListItem)),- value,- value => this._onSortClick(String(value))- );+ const menuItems: MenuBarItem[] = [{+ component: createMenuBarItem(html`<or-icon icon="sort-variant"></or-icon>`),+ children: (options ?? []).map(o => ({+ checked: value && o === value,+ component: createMenuBarItem(html`<or-translate value=${o}></or-translate>`),+ value: o+ })) as SubMenuItem[]+ }]+ return html`+ <or-vaadin-menu-bar theme="icon" .items=${menuItems}+ @item-selected=${(ev: CustomEvent) => this._onSortClick(ev.detail.value.value)}+ ></or-vaadin-menu-bar>+ `;}/**diff --git a/ui/component/or-tree-menu/tsconfig.json b/ui/component/or-tree-menu/tsconfig.jsonindex b9811bcfc..849516e91 100644--- a/ui/component/or-tree-menu/tsconfig.json+++ b/ui/component/or-tree-menu/tsconfig.json@@ -9,9 +9,7 @@],"references": [{ "path": "../core" },- { "path": "../rest" },- { "path": "../model" },- { "path": "../or-mwc-components" },- { "path": "../or-translate" }+ { "path": "../or-translate" },+ { "path": "../or-vaadin-components" }]}diff --git a/ui/component/or-vaadin-components/src/or-vaadin-menu-bar.ts b/ui/component/or-vaadin-components/src/or-vaadin-menu-bar.tsindex 0e2f1d494..baba81228 100644--- a/ui/component/or-vaadin-components/src/or-vaadin-menu-bar.ts+++ b/ui/component/or-vaadin-components/src/or-vaadin-menu-bar.ts@@ -23,7 +23,7 @@ import {customElement} from "lit/decorators.js";import {OrVaadinComponent} from "./util";import "@vaadin/menu-bar";-export {MenuBarItem} from "@vaadin/menu-bar";+export {MenuBarItem, SubMenuItem} from "@vaadin/menu-bar";export function createMenuBarItem(content: TemplateResult) {const item = document.createElement("vaadin-menu-bar-item");diff --git a/yarn.lock b/yarn.lockindex 9dfcf2837..4d13ccf74 100644--- a/yarn.lock+++ b/yarn.lock@@ -2200,8 +2200,8 @@ __metadata:resolution: "@openremote/or-tree-menu@workspace:ui/component/or-tree-menu"dependencies:"@openremote/core": "workspace:*"- "@openremote/or-mwc-components": "workspace:*""@openremote/or-translate": "workspace:*"+ "@openremote/or-vaadin-components": "workspace:*""@openremote/util": "workspace:*"lit: "npm:^3.3.1"languageName: unknown