Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI: Migrate Rules dialogs to Vaadin counterpart (#3089)

Martin Peetersfea235d28c66
diff --git a/ui/app/manager/src/pages/page-alarms.ts b/ui/app/manager/src/pages/page-alarms.ts
index 23b608b83..2b5698696 100644
--- a/ui/app/manager/src/pages/page-alarms.ts
+++ b/ui/app/manager/src/pages/page-alarms.ts
@@ -37,7 +37,7 @@ import { type GenericAxiosResponse, isAxiosError } from "@openremote/rest";
import { getAlarmsRoute } from "../routes";
import { when } from "lit/directives/when.js";
import { until } from "lit/directives/until.js";
-import { OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
+import { showDialog } from "@openremote/or-vaadin-components/or-vaadin-dialog";
import type { OrAssetTreeRequestSelectionEvent, OrAssetTreeSelectionEvent } from "@openremote/or-asset-tree";
import type {
OrMwcTable,
@@ -967,12 +967,21 @@ export class PageAlarms extends Page<AppStateKeyed> {
});
};
+ const onCancel = () => openBtn.toggleAttribute("disabled", false);
+ const onOk = () => {
+ openBtn.toggleAttribute("disabled", false);
+ this.onAlarmChanged(this.shadowRoot.querySelector("or-vaadin-text-field") as HTMLElement);
+ this.requestUpdate();
+ };
+
const dialog = showDialog(
- new OrMwcDialog()
- .setHeading(i18next.t("linkedAssets"))
- .setContent(html`
+ this.shadowRoot!,
+ html`
+ <or-vaadin-dialog no-close-on-esc no-close-on-outside-click>
+ <h2 slot="header-content"><or-translate value="linkedAssets"></or-translate></h2>
<or-asset-tree
id="chart-asset-tree"
+ style="aspect-ratio: 1/1;"
readonly="true"
.selectedIds="${alarm.alarmAssetLinks?.map((al) => al.id.assetId)}"
.showSortBtn="${false}"
@@ -987,32 +996,28 @@ export class PageAlarms extends Page<AppStateKeyed> {
}
}}"
></or-asset-tree>
- `)
- .setActions([
- {
- default: true,
- actionName: "cancel",
- content: i18next.t("cancel"),
- action: () => {
- openBtn.toggleAttribute("disabled", false);
- },
- },
- {
- actionName: "ok",
- content: "ok",
- action: () => {
- openBtn.toggleAttribute("disabled", false);
- this.onAlarmChanged(this.shadowRoot.querySelector("or-vaadin-text-field") as HTMLElement);
- this.requestUpdate();
- },
- },
- ])
- .setDismissAction({
- actionName: "cancel",
- action: () => {
- openBtn.toggleAttribute("disabled", false);
- },
- })
+ <div slot="footer" style="width: 100%; display: flex; justify-content: space-between;">
+ <or-vaadin-button
+ theme="tertiary"
+ @click=${() => {
+ onCancel();
+ dialog?.close();
+ }}
+ >
+ <or-translate value="cancel"></or-translate>
+ </or-vaadin-button>
+ <or-vaadin-button
+ theme="primary"
+ @click=${() => {
+ onOk();
+ dialog?.close();
+ }}
+ >
+ <or-translate value="ok"></or-translate>
+ </or-vaadin-button>
+ </div>
+ </or-vaadin-dialog>
+ `
);
}
diff --git a/ui/app/manager/src/pages/page-users.ts b/ui/app/manager/src/pages/page-users.ts
index fec3038a4..109d43fe7 100644
--- a/ui/app/manager/src/pages/page-users.ts
+++ b/ui/app/manager/src/pages/page-users.ts
@@ -1061,7 +1061,7 @@ export class PageUsers extends Page<AppStateKeyed> {
<or-translate slot="label" value="username"></or-translate>
</or-vaadin-text-field>
<!-- if identity provider is set to use email as username, make it required -->
- <or-vaadin-email-field id="new-email" class=${isServiceUser ? "hidden" : "validate"}
+ <or-vaadin-email-field id="new-email" class=${isServiceUser ? "hidden" : "validate"}
?readonly=${(!!user.id && this._registrationEmailAsUsername) || readonly}
?required=${!isServiceUser && this._registrationEmailAsUsername}
value=${user.email} autocomplete="false"
diff --git a/ui/app/manager/test/fixtures/pages/rules.ts b/ui/app/manager/test/fixtures/pages/rules.ts
index f6abda864..555f565d5 100644
--- a/ui/app/manager/test/fixtures/pages/rules.ts
+++ b/ui/app/manager/test/fixtures/pages/rules.ts
@@ -16,9 +16,17 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import type { BasePage, Page, Shared } from "@openremote/test";
+import type { BasePage, Locator, Page, Shared } from "@openremote/test";
import type { Manager } from "../manager";
+export interface AttributeWhenClauseOptions {
+ assetType: string;
+ asset: string;
+ attribute: string;
+ value: string;
+ operator: string;
+}
+
export class RulesPage implements BasePage {
constructor(
private readonly page: Page,
@@ -27,6 +35,47 @@ export class RulesPage implements BasePage {
) {}
async goto() {
- this.manager.navigateToTab("Rules");
+ return this.manager.navigateToTab("Rules");
+ }
+
+ async createRule(type: "When-Then" | "Flow" | "Groovy") {
+ await this.page.click(".mdi-plus >> nth=0");
+ await this.page.getByRole("menuitem", { name: type, exact: true }).click();
+ }
+
+ async setRuleName(name: string) {
+ return this.page.getByRole("textbox", { name: "Rule name" }).fill(name);
+ }
+
+ async configureAttributeWhenClause(
+ when: Locator,
+ { assetType, asset, attribute, value, operator }: AttributeWhenClauseOptions
+ ) {
+ await when.getByRole("menuitem", { name: "Add condition" }).click();
+ await when.getByRole("menuitem", { name: assetType }).click();
+ await when.getByRole("combobox", { name: "Asset", exact: true }).fill(asset);
+ await when.getByRole("option", { name: asset, exact: true }).click();
+ await when.getByRole("combobox", { name: "Attribute", exact: true }).fill(attribute);
+ await when.getByRole("option", { name: attribute, exact: true }).click();
+ await when.getByRole("combobox", { name: "Operator", exact: true }).fill(operator);
+ await when.getByRole("option", { name: operator, exact: true }).click();
+ await when.getByRole("spinbutton", { name: attribute }).fill(value);
+ }
+
+ /**
+ * The overlay of an action settings dialog, which Vaadin renders in its own element rather than
+ * inside `or-rule-json-dialog`.
+ * @param scope - Clause the action belongs to, e.g. the `or-rule-then-otherwise` locator.
+ */
+ actionDialogOverlay(scope: Locator): Locator {
+ return scope.getByRole("dialog").locator("#overlay").first();
+ }
+
+ /**
+ * Moves focus off the field being edited so its `change` event fires and the dialog revalidates.
+ * The overlay padding is the only spot within the dialog that takes no focus of its own.
+ */
+ async blurActiveField(scope: Locator) {
+ await this.actionDialogOverlay(scope).click({ position: { x: 0, y: 0 } });
}
}
diff --git a/ui/app/manager/test/rules.test.ts b/ui/app/manager/test/rules.test.ts
index 12e1e324f..d9d49ff20 100644
--- a/ui/app/manager/test/rules.test.ts
+++ b/ui/app/manager/test/rules.test.ts
@@ -21,6 +21,7 @@ import { test, userStatePath } from "./fixtures/manager.js";
import { preparedAssetsForRules as assets } from "./fixtures/data/assets.js";
import { energyRule } from "./fixtures/data/rules.js";
import { type Asset, type RealmRuleset, RulesetLang } from "@openremote/model";
+import type { OrRuleTree } from "@openremote/or-rules/or-rule-tree";
test.use({ storageState: userStatePath });
@@ -107,7 +108,7 @@ async function mockRealmRulesApi(page: any, initialRules: RealmRuleset[]) {
* Simple function that generates assets based on {@link assets}
* @param multiplier - Amount of assets to generate per asset type
*/
-function generateALotOfAssets(multiplier = 5): Asset[] {
+function generateALotOfAssets(multiplier = 5) {
return Array.from({ length: multiplier }, (_, i) =>
assets.map((a: Asset) => ({ ...a, name: `${a.name} ${i}` }))
).flat();
@@ -121,25 +122,22 @@ function generateALotOfAssets(multiplier = 5): Asset[] {
* @and Saving the rule
* @then The When-Then rule should appear in the rule list
*/
-test("Create a When-Then rule for an asset with a trigger and action", async ({ page, manager, shared }) => {
+test("Create a When-Then rule for an asset with a trigger and action", async ({ page, manager, rulesPage, shared }) => {
await manager.setup("smartcity", { assets });
await manager.goToRealmStartPage("smartcity");
- await manager.navigateToTab("Rules");
- await page.click(".mdi-plus >> nth=0");
- await page.getByRole("menuitem", { name: "When-Then", exact: true }).click();
- await page.getByRole("textbox", { name: "Rule name" }).fill(energyRule.name);
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
// When clause
const when = page.locator("or-rule-when");
- 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();
- await when.getByRole("option", { name: energyRule.attribute_when, exact: true }).click();
- await when.getByRole("combobox", { name: "Operator", exact: true }).click();
- await when.getByRole("option", { name: "Less than or equal to", exact: true }).click();
- await when.getByRole("spinbutton", { name: "Energy level" }).fill(energyRule.value.toString());
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
// Then clause
const then = page.locator("or-rule-then-otherwise");
@@ -167,12 +165,12 @@ test("Create a When-Then rule for an asset with a trigger and action", async ({
* @and Saving the rule
* @then The When-Then rule should appear in the rule list
*/
-test("Create a When-Then rule by searching for an asset", async ({ page, manager, shared }) => {
+test("Create a When-Then rule by searching for an asset", async ({ page, manager, rulesPage, shared }) => {
const multiplier = 200; // Using a multiplier above 100, which is the default querying limit
const aLotOfAssets = generateALotOfAssets(multiplier);
await manager.setup("smartcity", { assets: aLotOfAssets });
await manager.goToRealmStartPage("smartcity");
- await manager.navigateToTab("Rules");
+ await rulesPage.goto();
// Make sure the correct amount assets are set up, and the variables for this rule are adjusted
expect(manager.assets.length).toBe(multiplier * assets.length);
@@ -181,21 +179,18 @@ test("Create a When-Then rule by searching for an asset", async ({ page, manager
expect(firstAssetName).toContain(energyRule.asset);
expect(lastAssetName).toContain(energyRule.asset);
- await page.click(".mdi-plus >> nth=0");
- await page.getByRole("menuitem", { name: "When-Then", exact: true }).click();
- await page.getByRole("textbox", { name: "Rule name" }).fill(energyRule.name);
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
// Select asset type of the When clause, search for the last asset in the list, and select the attribute
const when = page.locator("or-rule-when");
- 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);
- await when.getByRole("option", { name: energyRule.attribute_when, exact: true }).click();
- await when.getByRole("combobox", { name: "Operator", exact: true }).fill("Less than or");
- await when.getByRole("option", { name: "Less than or equal to", exact: true }).click();
- await when.getByRole("spinbutton", { name: "Energy level" }).fill(energyRule.value.toString());
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: lastAssetName,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
// Configure Then clause
const then = page.locator("or-rule-then-otherwise");
@@ -215,6 +210,351 @@ test("Create a When-Then rule by searching for an asset", async ({ page, manager
await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
});
+/**
+ * @when Creating a When-Then rule
+ * @and Naming the rule
+ * @and Configuring a When condition on the asset
+ * @and Configuring a Then action with an email notification
+ * @and Saving the rule
+ * @then The When-Then rule should appear in the rule list
+ */
+test("Create a When-Then rule for an asset with a email notification action", async ({
+ page,
+ manager,
+ rulesPage,
+ shared,
+}) => {
+ await manager.setup("smartcity", { assets });
+ await manager.goToRealmStartPage("smartcity");
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
+
+ // When clause
+ const when = page.locator("or-rule-when");
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
+ await expect(page.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
+
+ // Then clause
+ const then = page.locator("or-rule-then-otherwise");
+ await then.getByRole("menuitem", { name: "Add action" }).click();
+ await then.getByRole("menuitem", { name: "Email" }).click();
+ await expect(page.getByRole("button", { name: "Save", exact: true })).not.toBeDisabled();
+
+ await then.getByRole("combobox", { name: "Recipients", exact: true }).click();
+ await then.getByRole("option", { name: "Users", exact: true }).click();
+ await then.getByRole("combobox", { name: "Users", exact: true }).click();
+ await then.getByRole("option", { name: "Linked", exact: true }).click();
+ await then.getByRole("button", { name: "Message", exact: true }).click();
+
+ // Set up notification message in dialog
+ const overlay = rulesPage.actionDialogOverlay(then);
+ await expect(overlay).toBeVisible();
+ await then.getByRole("textbox", { name: "Subject", exact: true }).clear();
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Subject", exact: true })).toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
+
+ await then.getByRole("textbox", { name: "Subject", exact: true }).fill("Email notification");
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Subject", exact: true })).not.toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ await then
+ .getByRole("textbox", { name: "Body", exact: true })
+ .fill("Assets that have been impacted: %TRIGGER_ASSETS%");
+ await then.getByRole("button", { name: "OK", exact: true }).click();
+
+ await shared.interceptResponse<number>("**/rules/realm", (rule) => {
+ if (rule) manager.rules.push(rule);
+ });
+
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+ await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
+});
+
+/**
+ * @when Creating a When-Then rule
+ * @and Naming the rule
+ * @and Configuring a When condition on the asset
+ * @and Configuring a Then action with an push notification
+ * @and Saving the rule
+ * @then The When-Then rule should appear in the rule list
+ */
+test("Create a When-Then rule for an asset with a push notification action", async ({
+ page,
+ manager,
+ rulesPage,
+ shared,
+}) => {
+ await manager.setup("smartcity", { assets });
+ await manager.goToRealmStartPage("smartcity");
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
+
+ // When clause
+ const when = page.locator("or-rule-when");
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
+ await expect(page.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
+
+ // Then clause
+ const then = page.locator("or-rule-then-otherwise");
+ await then.getByRole("menuitem", { name: "Add action" }).click();
+ await then.getByRole("menuitem", { name: "Push notification" }).click();
+ await expect(page.getByRole("button", { name: "Save", exact: true })).not.toBeDisabled();
+
+ await then.getByRole("button", { name: "Message", exact: true }).click();
+
+ // Set up notification message in dialog
+ const overlay = rulesPage.actionDialogOverlay(then);
+ await expect(overlay).toBeVisible();
+ await then.getByRole("textbox", { name: "Title", exact: true }).fill("Push notification");
+ await then.getByRole("textbox", { name: "Body", exact: true }).clear();
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Body", exact: true })).toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
+
+ await then.getByRole("textbox", { name: "Body", exact: true }).fill("Impacted assets: %TRIGGER_ASSETS%");
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Body", exact: true })).not.toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ // Fill in website URL
+ await then.getByRole("textbox", { name: "Website to be opened", exact: true }).fill("https://openremote.io");
+ await expect(then.getByRole("textbox", { name: "Body", exact: true })).not.toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ // Toggle the switch for opening in browser
+ await then.getByRole("switch", { name: "Open in browser (for external websites)", exact: true }).click();
+ await expect(then.getByRole("textbox", { name: "Body", exact: true })).not.toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ await then.getByRole("button", { name: "OK", exact: true }).click();
+
+ await shared.interceptResponse<number>("**/rules/realm", (rule) => {
+ if (rule) manager.rules.push(rule);
+ });
+
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+ await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
+});
+
+/**
+ * @when Creating a When-Then rule
+ * @and Naming the rule
+ * @and Configuring a When condition on the asset
+ * @and Configuring a Then action with an push notification
+ * @and Saving the rule
+ * @then The When-Then rule should appear in the rule list
+ */
+test("Create a When-Then rule for an asset with a alarm action", async ({ page, manager, rulesPage, shared }) => {
+ await manager.setup("smartcity", { assets });
+ await manager.goToRealmStartPage("smartcity");
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
+
+ // When clause
+ const when = page.locator("or-rule-when");
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
+ await expect(page.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
+
+ // Then clause
+ const then = page.locator("or-rule-then-otherwise");
+ await then.getByRole("menuitem", { name: "Add action" }).click();
+ await then.getByRole("menuitem", { name: "Alarm" }).click();
+ await expect(page.getByRole("button", { name: "Save", exact: true })).not.toBeDisabled();
+
+ await then.getByRole("button", { name: "Severity" }).click();
+ await then.getByRole("option", { name: "High", exact: true }).click();
+ await then.getByRole("button", { name: "Settings", exact: true }).click();
+
+ // Set up notification message in dialog
+ const overlay = rulesPage.actionDialogOverlay(then);
+ await expect(overlay).toBeVisible();
+ await then.getByRole("textbox", { name: "Title", exact: true }).fill("High priority alarm");
+ await then.getByRole("textbox", { name: "Content", exact: true }).clear();
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Content", exact: true })).toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
+
+ await then.getByRole("textbox", { name: "Content", exact: true }).fill("Warning: %TRIGGER_ASSETS%");
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("textbox", { name: "Content", exact: true })).not.toHaveAttribute("invalid");
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ // Adjust assignee
+ await then.getByRole("combobox", { name: "Assignee", exact: true }).click();
+ await then.getByRole("option", { name: "smartcity", exact: true }).click();
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+ await then.getByRole("button", { name: "OK", exact: true }).click();
+
+ await shared.interceptResponse<number>("**/rules/realm", (rule) => {
+ if (rule) manager.rules.push(rule);
+ });
+
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+ await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
+});
+
+/**
+ * @given A When-Then rule with an alarm action
+ * @when Setting the alarm severity, which sits outside the settings dialog
+ * @and Editing the alarm title inside the dialog and cancelling
+ * @then The severity should be kept, and the saved rule should not contain the cancelled edit
+ */
+test("Cancelling the alarm settings dialog discards only the changes made inside it", async ({
+ page,
+ manager,
+ rulesPage,
+ shared,
+}) => {
+ await manager.setup("smartcity", { assets });
+ await manager.goToRealmStartPage("smartcity");
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
+
+ // When clause
+ const when = page.locator("or-rule-when");
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
+
+ // Then clause, with an alarm that is filled in and confirmed
+ const then = page.locator("or-rule-then-otherwise");
+ await then.getByRole("menuitem", { name: "Add action" }).click();
+ await then.getByRole("menuitem", { name: "Alarm" }).click();
+ await then.getByRole("button", { name: "Settings", exact: true }).click();
+ await then.getByRole("textbox", { name: "Title", exact: true }).fill("Kept title");
+ await then.getByRole("textbox", { name: "Content", exact: true }).fill("Kept content");
+ await rulesPage.blurActiveField(then);
+ await then.getByRole("button", { name: "OK", exact: true }).click();
+
+ // Severity is edited outside of the dialog
+ await then.getByRole("button", { name: "Severity" }).click();
+ await then.getByRole("option", { name: "High", exact: true }).click();
+
+ // Reopen the dialog, edit the title, and back out again
+ await then.getByRole("button", { name: "Settings", exact: true }).click();
+ await then.getByRole("textbox", { name: "Title", exact: true }).fill("Discarded title");
+ await rulesPage.blurActiveField(then);
+ await then.getByRole("button", { name: "Cancel", exact: true }).click();
+
+ // Cancel used to restore a snapshot of the whole action, undoing the severity picked outside it
+ await expect(then.getByRole("button", { name: "Severity" })).toContainText("High");
+
+ let saved: RealmRuleset | undefined;
+ await shared.interceptResponse<number>("**/rules/realm", (rule, request) => {
+ if (rule) manager.rules.push(rule);
+ saved = request?.postDataJSON();
+ });
+
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+ await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
+
+ // Cancel used to swap the element's own action reference, leaving the rule holding the edit
+ const action = JSON.parse(saved!.rules!).rules[0].then[0];
+ expect(action.alarm.title).toBe("Kept title");
+ expect(action.alarm.severity).toBe("HIGH");
+});
+
+/**
+ * @when Creating a When-Then rule
+ * @and Naming the rule
+ * @and Configuring a When condition on the asset
+ * @and Configuring a Then action with an push notification
+ * @and Saving the rule
+ * @then The When-Then rule should appear in the rule list
+ */
+test("Create a When-Then rule for an asset with a webhook action", async ({ page, manager, rulesPage, shared }) => {
+ await manager.setup("smartcity", { assets });
+ await manager.goToRealmStartPage("smartcity");
+ await rulesPage.goto();
+ await rulesPage.createRule("When-Then");
+ await rulesPage.setRuleName(energyRule.name);
+
+ // When clause
+ const when = page.locator("or-rule-when");
+ await rulesPage.configureAttributeWhenClause(when, {
+ assetType: energyRule.asset_type,
+ asset: energyRule.asset,
+ attribute: energyRule.attribute_when,
+ operator: "Less than or equal to",
+ value: energyRule.value.toString(),
+ });
+ await expect(page.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
+
+ // Then clause
+ const then = page.locator("or-rule-then-otherwise");
+ await then.getByRole("menuitem", { name: "Add action" }).click();
+ await then.getByRole("menuitem", { name: "Webhook" }).click();
+ await then.getByRole("button", { name: "Message", exact: true }).click();
+
+ // Set up notification message in dialog
+ const overlay = rulesPage.actionDialogOverlay(then);
+ await expect(overlay).toBeVisible();
+ await expect(then.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
+ await then.getByRole("button", { name: "Method" }).first().click();
+ await then.getByRole("option", { name: "PUT", exact: true }).click();
+ await expect(then.getByRole("button", { name: "OK", exact: true })).toBeDisabled();
+ await then.getByRole("textbox", { name: "Web URL", exact: true }).fill("https://localhost");
+ await rulesPage.blurActiveField(then);
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+
+ // Add request header
+ await then.getByRole("button", { name: "Add Request Header" }).click();
+ await then.getByRole("textbox", { name: "Header", exact: true }).fill("key");
+ await then.getByRole("textbox", { name: "Value", exact: true }).fill("value");
+
+ // Add authorization info
+ await then.getByRole("switch", { name: "Requires Authorization", exact: true }).click();
+ await then.getByRole("button", { name: "Method" }).last().click();
+ await then.getByRole("option", { name: "oauth Client Credentials Grant", exact: true }).click();
+ await then.getByRole("textbox", { name: "Token URL", exact: true }).fill("https://localhost/token");
+ await then.getByRole("textbox", { name: "Client ID", exact: true }).fill("client");
+ await then.getByRole("textbox", { name: "Client secret", exact: true }).fill("secret");
+
+ // Remove body
+ await then.getByRole("switch", { name: "Include body in Request", exact: true }).click();
+ await expect(then.locator("or-vaadin-text-area")).not.toBeVisible(); // The payload is the form's only text area
+
+ // Close the dialog
+ await expect(page.getByRole("button", { name: "Save", exact: true })).toBeDisabled();
+ await expect(then.getByRole("button", { name: "OK", exact: true })).not.toBeDisabled();
+ await then.getByRole("button", { name: "OK", exact: true }).click();
+
+ await shared.interceptResponse<number>("**/rules/realm", (rule) => {
+ if (rule) manager.rules.push(rule);
+ });
+
+ await page.getByRole("button", { name: "Save", exact: true }).click();
+ await expect(page.locator(`text=${energyRule.name}`)).toHaveCount(1);
+});
+
/**
* @when Creating a Flow rule
* @and Naming the rule
@@ -224,13 +564,12 @@ test("Create a When-Then rule by searching for an asset", async ({ page, manager
* @and Saving the rule
* @then The Flow rule should appear in the rule list
*/
-test("Create a Flow rule for an asset with logic connections", async ({ page, shared, manager }) => {
+test("Create a Flow rule for an asset with logic connections", async ({ page, shared, rulesPage, manager }) => {
await manager.setup("smartcity", { assets });
await manager.goToRealmStartPage("smartcity");
- await manager.navigateToTab("Rules");
- await page.click(".mdi-plus >> nth=0");
- await page.getByRole("menuitem", { name: "Flow", exact: true }).click();
- await page.getByRole("textbox", { name: "Rule name" }).fill("Solar panel");
+ await rulesPage.goto();
+ await rulesPage.createRule("Flow");
+ await rulesPage.setRuleName("Solar panel");
await page.locator(".node-item.input-node", { hasText: "Attribute value" }).hover();
await shared.drag(450, 250);
@@ -362,7 +701,7 @@ test("Groups containing legacy JavaScript rules cannot be renamed", async ({ pag
await expect(page.locator("or-rule-tree").getByText("Legacy JS group", { exact: true })).toHaveCount(1);
await page.locator("or-rule-tree").getByText("Legacy JS group", { exact: true }).click();
await page.getByRole("textbox", { name: "Group name" }).fill("Renamed JS group");
- await page.getByRole("button", { name: "Save" }).isDisabled();
+ await page.getByRole("button", { name: "Save" }).click();
expect(api.putRequests).toBe(0);
});
@@ -382,7 +721,7 @@ test("Dragging a legacy JavaScript rule is blocked", async ({ page, manager }) =
await expect(page.locator("or-rule-tree").getByText(legacyJavascriptRule.name!)).toHaveCount(1);
const dispatchSucceeded = await page.locator("or-rules").evaluate((element, ruleName) => {
- const tree = element.shadowRoot?.querySelector("or-rule-tree") as any;
+ const tree = element.shadowRoot?.querySelector("or-rule-tree") as OrRuleTree;
const rule = tree?.rules?.find((candidate: any) => candidate.name === ruleName);
if (!rule) {
diff --git a/ui/component/or-asset-tree/src/style.ts b/ui/component/or-asset-tree/src/style.ts
index 3981f7790..a908cd4f4 100644
--- a/ui/component/or-asset-tree/src/style.ts
+++ b/ui/component/or-asset-tree/src/style.ts
@@ -62,6 +62,7 @@ export const style = css`
var(--or-app-color5, ${unsafeCSS(DefaultColor5)})
);
+ position: relative;
display: flex;
flex-direction: column;
height: 100%;
@@ -330,7 +331,7 @@ export const style = css`
background-color: var(--internal-or-asset-tree-background-color);
top: calc(var(--internal-or-asset-tree-header-height) + var(--internal-or-header-height, 50px) - 1px);
display: none;
- width: 300px;
+ width: 100%;
z-index: 100;
box-shadow: rgb(0 0 0 / 21%) 0px 1px 3px 0px;
box-sizing: border-box;
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-alarm.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-alarm.ts
index 3512ea5f7..3df3c73c1 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-alarm.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-alarm.ts
@@ -19,20 +19,24 @@
import { html, css } from "lit";
import { OrElement } from "@openremote/or-element";
import { customElement, property } from "lit/decorators.js";
-import "@openremote/or-mwc-components/or-mwc-input";
import type { RuleActionAlarm, Alarm, User } from "@openremote/model";
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
import { i18next } from "@openremote/or-translate";
-import type { OrVaadinSelect } from "@openremote/or-vaadin-components/or-vaadin-select";
+import "@openremote/or-vaadin-components/or-vaadin-combo-box";
+import type { OrVaadinComboBox } from "@openremote/or-vaadin-components/or-vaadin-combo-box";
+import { isFormValid, type OrRuleForm } from "./or-rule-form";
@customElement("or-rule-form-alarm")
-export class OrRuleFormAlarm extends OrElement {
+export class OrRuleFormAlarm extends OrElement implements OrRuleForm {
@property({ type: Object, attribute: false })
public action!: RuleActionAlarm;
@property()
public users: User[] = [];
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
static get styles() {
return css`
#form-container {
@@ -46,6 +50,10 @@ export class OrRuleFormAlarm extends OrElement {
`;
}
+ checkValidity(): boolean {
+ return isFormValid(this.renderRoot);
+ }
+
protected render() {
const alarm: Alarm | undefined = this.action.alarm as Alarm;
const options: { value: string | undefined; label: string | undefined }[] = this.users
@@ -60,6 +68,7 @@ export class OrRuleFormAlarm extends OrElement {
<or-vaadin-text-field
value=${alarm?.title}
required
+ ?readonly=${this.readonly}
@change=${(ev: Event) => this.setActionAlarmName((ev.currentTarget as HTMLInputElement).value, "title")}
>
<or-translate slot="label" value="alarm.title"></or-translate>
@@ -67,36 +76,40 @@ export class OrRuleFormAlarm extends OrElement {
<or-vaadin-text-area
value=${alarm?.content}
required
+ ?readonly=${this.readonly}
style="min-height: 200px;"
@change=${(ev: Event) => this.setActionAlarmName((ev.currentTarget as HTMLInputElement).value, "content")}
>
<or-translate slot="label" value="alarm.content"></or-translate>
</or-vaadin-text-area>
- <or-vaadin-select
- value=${this.action.assigneeId}
- required
+ <or-vaadin-combo-box
.items=${options}
- @change=${(ev: Event) => {
- const value = (ev.currentTarget as OrVaadinSelect).value;
- this.action.assigneeId = value;
- this.setActionAlarmName(value, undefined);
+ .selectedItem=${options.find((o) => o.value === this.action.assigneeId)}
+ ?readonly=${this.readonly}
+ @change=${(ev: CustomEvent) => {
+ // The 'none' option carries no value, which clears the assignee
+ this.setActionAssignee((ev.currentTarget as OrVaadinComboBox).selectedItem?.value);
}}
>
<or-translate slot="label" value="alarm.assignee"></or-translate>
- </or-vaadin-select>
+ </or-vaadin-combo-box>
</div>
`;
}
- protected setActionAlarmName(value: string | undefined, key?: string) {
- if (key && this.action.alarm) {
+ protected setActionAlarmName(value: string | undefined, key: string) {
+ if (this.action.alarm) {
const alarm: any = this.action.alarm;
alarm[key] = value;
this.action.alarm = { ...alarm };
}
- if (!key) {
- this.action.assigneeId = this.users.filter((obj) => obj.username === value).map((obj) => obj.id)[0];
- }
+
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
+ this.requestUpdate();
+ }
+
+ protected setActionAssignee(assigneeId: string | undefined) {
+ this.action.assigneeId = assigneeId;
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
this.requestUpdate();
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-email-message.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-email-message.ts
index 06bf6a75c..87e347696 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-email-message.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-email-message.ts
@@ -22,14 +22,16 @@ import { customElement, property } from "lit/decorators.js";
import { i18next, translate } from "@openremote/or-translate";
import type { EmailNotificationMessage } from "@openremote/model";
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
-import "@openremote/or-mwc-components/or-mwc-input";
-import { OrVaadinTextField } from "@openremote/or-vaadin-components/or-vaadin-text-field";
+import { isFormValid, type OrRuleForm } from "./or-rule-form";
@customElement("or-rule-form-email-message")
-export class OrRuleFormEmailMessage extends translate(i18next)(OrElement) {
+export class OrRuleFormEmailMessage extends translate(i18next)(OrElement) implements OrRuleForm {
@property({ type: Object })
public message?: EmailNotificationMessage;
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
static get styles() {
return css`
#form-container {
@@ -43,6 +45,10 @@ export class OrRuleFormEmailMessage extends translate(i18next)(OrElement) {
`;
}
+ checkValidity(): boolean {
+ return isFormValid(this.renderRoot);
+ }
+
protected render() {
if (!this.message) {
return html`<or-translate .value="${"errorOccurred"}"></or-translate>`;
@@ -53,6 +59,7 @@ export class OrRuleFormEmailMessage extends translate(i18next)(OrElement) {
<or-vaadin-text-field
value=${this.message?.subject}
required
+ ?readonly=${this.readonly}
@change=${(ev: Event) => this.setActionNotificationName((ev.currentTarget as HTMLInputElement).value, "subject")}
>
<or-translate slot="label" value="subject"></or-translate>
@@ -60,6 +67,7 @@ export class OrRuleFormEmailMessage extends translate(i18next)(OrElement) {
<or-vaadin-text-area
value=${this.message?.html}
required
+ ?readonly=${this.readonly}
style="min-height: 200px;"
@change=${(ev: Event) => this.setActionNotificationName((ev.currentTarget as HTMLInputElement).value, "html")}
>
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-localized.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-localized.ts
index b600108b2..a3a99f23f 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-localized.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-localized.ts
@@ -31,9 +31,10 @@ import "./or-rule-form-push-notification";
import ISO6391 from "iso-639-1";
import { DefaultColor6 } from "@openremote/core";
import type { SelectItem } from "@openremote/or-vaadin-components/or-vaadin-select";
+import { isFormValid, type OrRuleForm } from "./or-rule-form";
@customElement("or-rule-form-localized")
-export class OrRuleFormLocalized extends translate(i18next)(OrElement) {
+export class OrRuleFormLocalized extends translate(i18next)(OrElement) implements OrRuleForm {
@property({ type: Object })
public message?: LocalizedNotificationMessage;
@@ -49,6 +50,9 @@ export class OrRuleFormLocalized extends translate(i18next)(OrElement) {
@property()
public wrongLanguage = false;
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
@state()
protected _selectedLanguage = "en";
@@ -78,12 +82,16 @@ export class OrRuleFormLocalized extends translate(i18next)(OrElement) {
this._selectedLanguage = this.defaultLang;
}
+ checkValidity(): boolean {
+ return isFormValid(this.renderRoot) && this.isValid();
+ }
+
protected render() {
return html`
<div>
${when(this.wrongLanguage, () => until(this._getWrongLanguageTemplate()))}
${guard(
- [this.message, this._selectedLanguage, this.languages, this.type],
+ [this.message, this._selectedLanguage, this.languages, this.type, this.readonly],
() => html`
${until(this._getLanguageSelectForm(this._selectedLanguage, this.languages), html`Loading...`)}
${until(this._getNotificationForm(this.message, this._selectedLanguage), html`Loading...`)}
@@ -103,7 +111,11 @@ export class OrRuleFormLocalized extends translate(i18next)(OrElement) {
*/
protected async _getWrongLanguageTemplate(): Promise<TemplateResult> {
return html`
- <or-vaadin-button style="width: 100%; margin: 10px 0;" @click=${() => this._fixDefaultLanguage()}>
+ <or-vaadin-button
+ style="width: 100%; margin: 10px 0;"
+ ?disabled=${this.readonly}
+ @click=${() => this._fixDefaultLanguage()}
+ >
<or-translate value="defaultLanguageChangedError"></or-translate>
</or-vaadin-button>
`;
@@ -174,9 +186,13 @@ export class OrRuleFormLocalized extends translate(i18next)(OrElement) {
const msg = message.languages[lang];
if (msg.type === "push") {
- return html` <or-rule-form-push-notification .message="${msg}"></or-rule-form-push-notification> `;
+ return html`
+ <or-rule-form-push-notification .message="${msg}" ?readonly=${this.readonly}></or-rule-form-push-notification>
+ `;
} else if (msg.type === "email") {
- return html` <or-rule-form-email-message .message="${msg}"></or-rule-form-email-message> `;
+ return html`
+ <or-rule-form-email-message .message="${msg}" ?readonly=${this.readonly}></or-rule-form-email-message>
+ `;
} else {
return html` <or-translate .value="${"errorOccurred"}"></or-translate> `;
}
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
index 4a757311c..6627dd7ce 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-push-notification.ts
@@ -25,12 +25,17 @@ import type { PushNotificationMessage, PushNotificationButton } from "@openremot
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
import { until } from "lit/directives/until.js";
import { when } from "lit/directives/when.js";
+import "@openremote/or-vaadin-components/or-vaadin-toggle";
+import { isFormValid, type OrRuleForm } from "./or-rule-form";
@customElement("or-rule-form-push-notification")
-export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
+export class OrRuleFormPushNotification extends translate(i18next)(OrElement) implements OrRuleForm {
@property({ type: Object })
public message?: PushNotificationMessage;
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
@query("#push-title")
protected _pushTitleElem?: HTMLInputElement;
@@ -40,6 +45,9 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
@query("#push-url")
protected _pushUrlElem?: HTMLInputElement;
+ @query("#push-browser-toggle")
+ protected _pushBrowserToggleElem?: HTMLInputElement;
+
@query("#push-button1")
protected _pushButton1Elem?: HTMLInputElement;
@@ -53,7 +61,8 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
}
or-vaadin-text-field,
- or-vaadin-text-area {
+ or-vaadin-text-area,
+ or-vaadin-toggle {
margin-bottom: 20px;
min-width: 420px;
width: 100%;
@@ -66,6 +75,10 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
`;
}
+ checkValidity(): boolean {
+ return isFormValid(this.renderRoot);
+ }
+
protected render() {
return html`
${when(
@@ -85,11 +98,12 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
onchange = async (ev: Event, msg?: PushNotificationMessage) => msg!
): Promise<TemplateResult> {
return html`
- <form style="display:grid">
+ <form id="form-container" style="display:grid">
<or-vaadin-text-field
id="push-title"
value=${message.title}
required
+ ?readonly=${this.readonly}
@change=${(ev: Event) => onchange(ev, message).then((msg) => this._onTitleChange(this._pushTitleElem!, msg))}
>
<or-translate slot="label" value="title"></or-translate>
@@ -98,6 +112,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
id="push-body"
value=${message.body}
required
+ ?readonly=${this.readonly}
style="min-height: 200px;"
@change=${(ev: Event) => onchange(ev, message).then((msg) => this._onBodyChange(this._pushBodyElem!, msg))}
>
@@ -110,6 +125,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
error-message="${i18next.t("invalidUrl")}"
placeholder="https://example.com"
value=${message.action?.url}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => onchange(ev, message).then((msg) => this._onActionUrlChange(this._pushUrlElem!, msg))}
>
<or-translate slot="label" value="openWebsiteUrl"></or-translate>
@@ -129,6 +145,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
id="push-button1"
value=${message.buttons?.[0]?.title}
class="input-small"
+ ?readonly=${this.readonly}
@change=${(ev: Event) => onchange(ev, message).then((msg) => this._onButtonTitleChange(this._pushButton1Elem!, 0, msg))}
>
<or-translate slot="label" value="buttonTextConfirm"></or-translate>
@@ -137,6 +154,7 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
id="push-button2"
value=${message.buttons?.[1]?.title}
class="input-small"
+ ?readonly=${this.readonly}
@change=${(ev: Event) => onchange(ev, message).then((msg) => this._onButtonTitleChange(this._pushButton2Elem!, 1, msg))}
>
<or-translate slot="label" value="buttonTextDecline"></or-translate>
@@ -150,31 +168,25 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
* HTML callback function when the subject of a notification message has changed.
*/
protected _onTitleChange(elem: HTMLInputElement, message: PushNotificationMessage) {
- if (elem.checkValidity()) {
- message.title = elem.value;
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
- }
+ message.title = elem.checkValidity() ? elem.value : undefined;
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
}
/**
* HTML callback function when the body of a notification message has changed.
*/
protected _onBodyChange(elem: HTMLInputElement, message: PushNotificationMessage) {
- if (elem.checkValidity()) {
- message.body = elem.value;
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
- }
+ message.body = elem.checkValidity() ? elem.value : undefined;
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
}
/**
* HTML callback function when the "click here to open URL" of a notification has changed.
*/
protected _onActionUrlChange(elem: HTMLInputElement, message: PushNotificationMessage) {
- if (elem.checkValidity()) {
- message.action = message.action || {};
- message.action.url = elem.value;
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
- }
+ message.action ??= {};
+ message.action.url = elem.checkValidity() ? elem.value : undefined;
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
}
/**
@@ -191,13 +203,15 @@ export class OrRuleFormPushNotification extends translate(i18next)(OrElement) {
* HTML callback function when any button text of the notification has changed.
*/
protected _onButtonTitleChange(elem: HTMLInputElement, key: number, message: PushNotificationMessage) {
+ message.buttons ??= [];
if (elem.checkValidity()) {
- message.buttons = message.buttons || [];
message.buttons[key] = {
title: elem.value,
action: key === 0 ? message.action : undefined,
} as PushNotificationButton;
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
+ } else {
+ message.buttons[key] = {};
}
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
}
}
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-webhook.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-webhook.ts
index 4622f5004..4872eefd0 100644
--- a/ui/component/or-rules/src/json-viewer/forms/or-rule-form-webhook.ts
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form-webhook.ts
@@ -23,7 +23,6 @@ import {
type Webhook,
type OAuthPasswordGrant,
} from "@openremote/model";
-import type { OrVaadinToggle } from "@openremote/or-vaadin-components/or-vaadin-toggle";
import { i18next } from "@openremote/or-translate";
import { css, html, type TemplateResult } from "lit";
import { OrElement } from "@openremote/or-element";
@@ -32,6 +31,9 @@ import { when } from "lit/directives/when.js";
import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
import type { OrVaadinSelect, SelectItem } from "@openremote/or-vaadin-components/or-vaadin-select";
import type { OrVaadinTextField } from "@openremote/or-vaadin-components/or-vaadin-text-field";
+import { isFormValid, type OrRuleForm } from "./or-rule-form";
+import "@openremote/or-vaadin-components/or-vaadin-toggle";
+import type { OrVaadinToggle } from "@openremote/or-vaadin-components/or-vaadin-toggle";
// language=css
const styling = css`
@@ -41,10 +43,13 @@ const styling = css`
`;
@customElement("or-rule-form-webhook")
-export class OrRuleFormWebhook extends OrElement {
+export class OrRuleFormWebhook extends OrElement implements OrRuleForm {
@property({ type: Object })
protected webhook!: Webhook;
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
@state()
protected loading: boolean = false;
@@ -59,6 +64,10 @@ export class OrRuleFormWebhook extends OrElement {
return [styling];
}
+ checkValidity(): boolean {
+ return isFormValid(this.renderRoot);
+ }
+
/* --------------------------- */
// Lifecycle methods
@@ -112,6 +121,7 @@ export class OrRuleFormWebhook extends OrElement {
value=${this.webhook.httpMethod}
.items=${this.httpMethodOptions.map((o) => ({ value: o, label: o }))}
required
+ ?readonly=${this.readonly}
style="flex: 0 0 100px;"
@change=${(ev: Event) => {
this.webhook.httpMethod = (ev.currentTarget as OrVaadinSelect).value as HTTPMethod;
@@ -124,6 +134,7 @@ export class OrRuleFormWebhook extends OrElement {
type="url"
value=${this.webhook.url}
required
+ ?readonly=${this.readonly}
style="flex: 1;"
@change=${(ev: Event) => {
this.webhook.url = (ev.currentTarget as OrVaadinTextField).value;
@@ -142,6 +153,7 @@ export class OrRuleFormWebhook extends OrElement {
() => html` ${this.getHeadersTemplate(this.webhook.headers!, false)} `
)}
<or-vaadin-button
+ ?disabled=${this.readonly}
@click=${() => {
if ((this.webhook.headers ? this.webhook.headers[""] : undefined) != undefined) {
this.webhook.headers![""].push("");
@@ -160,7 +172,8 @@ export class OrRuleFormWebhook extends OrElement {
style="display: flex; flex-direction: column; gap: 10px; margin-bottom: ${this.webhook.oAuthGrant || this.webhook.usernamePassword ? "28px" : "0"};"
>
<or-vaadin-toggle
- ?checked="${this.webhook.oAuthGrant || this.webhook.usernamePassword}"
+ ?checked="${!!this.webhook.oAuthGrant || !!this.webhook.usernamePassword}"
+ ?readonly=${this.readonly}
@change="${(ev: Event) => {
this.webhook.usernamePassword = (ev.currentTarget as OrVaadinToggle).checked
? {
@@ -182,6 +195,7 @@ export class OrRuleFormWebhook extends OrElement {
<or-vaadin-select
value=${this.webhook.oAuthGrant?.grant_type ?? values[0].value}
.items=${values}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
this.webhook.oAuthGrant = this.getOAuthGrant((ev.currentTarget as OrVaadinSelect).value);
this.notifyWebhookUpdate();
@@ -200,6 +214,7 @@ export class OrRuleFormWebhook extends OrElement {
() => html`
<or-vaadin-toggle
?checked="${this.webhook.payload != undefined}"
+ ?readonly=${this.readonly}
@change="${(ev: Event) => {
this.webhook.payload = (ev.currentTarget as OrVaadinToggle).checked
? JSON.stringify(
@@ -220,6 +235,7 @@ export class OrRuleFormWebhook extends OrElement {
return html`
<or-vaadin-text-area
value=${this.webhook.payload}
+ ?readonly=${this.readonly}
style="min-height: 200px;"
@change=${(ev: Event) => {
this.webhook.payload = (ev.currentTarget as HTMLInputElement).value;
@@ -248,6 +264,7 @@ export class OrRuleFormWebhook extends OrElement {
<or-vaadin-text-field
value=${key}
?disabled=${loading}
+ ?readonly=${this.readonly}
style="flex: 1;"
@change=${(ev: Event) => {
const inputValue = (ev.currentTarget as HTMLInputElement).value;
@@ -266,6 +283,7 @@ export class OrRuleFormWebhook extends OrElement {
<or-vaadin-text-field
value=${value}
?disabled=${loading}
+ ?readonly=${this.readonly}
style="flex: 1;"
@change=${(ev: Event) => {
this.webhook.headers![key][valueIndex] = (ev.currentTarget as HTMLInputElement).value;
@@ -276,7 +294,7 @@ export class OrRuleFormWebhook extends OrElement {
</or-vaadin-text-field>
<or-vaadin-button
theme="icon"
- ?disabled=${loading}
+ ?disabled=${loading || this.readonly}
@click=${() => {
values.splice(valueIndex, 1);
this.reloadHeaders();
@@ -297,6 +315,7 @@ export class OrRuleFormWebhook extends OrElement {
<div style="display: flex; flex-direction: column; gap: 10px;">
<or-vaadin-text-field
value=${webhook.usernamePassword?.username}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
this.webhook.usernamePassword ??= {};
this.webhook.usernamePassword.username = (ev.currentTarget as HTMLInputElement).value;
@@ -307,6 +326,7 @@ export class OrRuleFormWebhook extends OrElement {
</or-vaadin-text-field>
<or-vaadin-password-field
value=${webhook.usernamePassword?.password}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
this.webhook.usernamePassword ??= {};
this.webhook.usernamePassword.password = (ev.currentTarget as HTMLInputElement).value;
@@ -325,6 +345,7 @@ export class OrRuleFormWebhook extends OrElement {
type="url"
value=${authGrant.tokenEndpointUri}
required
+ ?readonly=${this.readonly}
style="flex: 1;"
@change=${(ev: Event) => {
authGrant.tokenEndpointUri = (ev.currentTarget as HTMLInputElement).value;
@@ -341,6 +362,7 @@ export class OrRuleFormWebhook extends OrElement {
return html`
<or-vaadin-text-field
value=${grant.client_id}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
grant.client_id = (ev.currentTarget as HTMLInputElement).value;
this.notifyWebhookUpdate();
@@ -350,6 +372,7 @@ export class OrRuleFormWebhook extends OrElement {
</or-vaadin-text-field>
<or-vaadin-password-field
value=${grant.client_secret}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
grant.client_secret = (ev.currentTarget as HTMLInputElement).value;
this.notifyWebhookUpdate();
@@ -364,6 +387,7 @@ export class OrRuleFormWebhook extends OrElement {
return html`
<or-vaadin-text-field
value=${grant.username}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
grant.username = (ev.currentTarget as HTMLInputElement).value;
this.notifyWebhookUpdate();
@@ -373,6 +397,7 @@ export class OrRuleFormWebhook extends OrElement {
</or-vaadin-text-field>
<or-vaadin-password-field
value=${grant.password}
+ ?readonly=${this.readonly}
@change=${(ev: Event) => {
grant.password = (ev.currentTarget as HTMLInputElement).value;
this.notifyWebhookUpdate();
diff --git a/ui/component/or-rules/src/json-viewer/forms/or-rule-form.ts b/ui/component/or-rules/src/json-viewer/forms/or-rule-form.ts
new file mode 100644
index 000000000..5c2457d5d
--- /dev/null
+++ b/ui/component/or-rules/src/json-viewer/forms/or-rule-form.ts
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2026, OpenRemote Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+export interface OrRuleForm {
+ checkValidity(): boolean;
+}
+
+/**
+ * Returns whether every element within {@link root} that can validate itself reports being valid.
+ * Elements without a `checkValidity` function are skipped, so this covers the Vaadin fields as well
+ * as any nested component implementing {@link OrRuleForm}, wherever they sit in the template.
+ */
+export function isFormValid(root: ParentNode | null | undefined): boolean {
+ if (!root) {
+ return false;
+ }
+ const elements = Array.from(root.querySelectorAll("*")) as Partial<HTMLInputElement>[];
+ return elements.every((elem) => typeof elem.checkValidity !== "function" || elem.checkValidity());
+}
diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-alarm-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-alarm-modal.ts
deleted file mode 100644
index 0b87dae4d..000000000
--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-alarm-modal.ts
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * Copyright 2024, OpenRemote Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-import { css, html, type PropertyValues } from "lit";
-import { OrElement } from "@openremote/or-element";
-import { customElement, property } from "lit/decorators.js";
-import { type RuleActionAlarm, type AssetQuery, AlarmSeverity } from "@openremote/model";
-
-import "@openremote/or-mwc-components/or-mwc-input";
-import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";
-import { i18next, translate } from "@openremote/or-translate";
-import {
- type DialogAction,
- type OrMwcDialog,
- OrMwcDialogOpenedEvent,
-} from "@openremote/or-mwc-components/or-mwc-dialog";
-import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
-import type { OrVaadinSelect, SelectItem } from "@openremote/or-vaadin-components/or-vaadin-select";
-
-const checkValidity = (form: HTMLElement | null, dialog: OrMwcDialog) => {
- if (form) {
- const inputs = form.querySelectorAll("or-mwc-input");
- const elements = Array.prototype.slice.call(inputs);
-
- const valid = elements.every((element) => {
- if (element.shadowRoot) {
- const input = element.shadowRoot.querySelector("input, textarea") as any;
-
- if (element.type === InputType.SELECT) {
- return true;
- }
-
- if (input && input.checkValidity()) {
- return true;
- } else {
- element._mdcComponent.valid = false;
- element._mdcComponent.helperTextContent = "required";
-
- return false;
- }
- } else {
- return false;
- }
- });
- if (valid) {
- dialog.close();
- }
- }
-};
-
-// language=CSS
-const style = css`
- :host {
- display: flex;
- align-items: baseline;
- }
- :host > * {
- margin: 0 3px 6px;
- }
- .min-width {
- flex: 0 0 240px;
- }
-`;
-
-@customElement("or-rule-alarm-modal")
-export class OrRuleAlarmModal extends translate(i18next)(OrElement) {
- static get styles() {
- return style;
- }
-
- @property({ type: Object, attribute: false })
- public action!: RuleActionAlarm;
-
- @property({ type: String })
- public title = "settings";
-
- @property({ type: Object })
- public query?: AssetQuery;
-
- constructor() {
- super();
- this.addEventListener(OrMwcDialogOpenedEvent.NAME, this.initDialog);
- }
-
- initDialog() {
- const modal = this.shadowRoot!.getElementById("alarm-modal");
- if (!modal) return;
- }
-
- renderDialogHTML(action: RuleActionAlarm) {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("alarm-modal") as OrMwcDialog;
- if (!this.shadowRoot) return;
-
- const slot: HTMLSlotElement | null = this.shadowRoot.querySelector(".alarm-form-slot");
- if (dialog && slot) {
- const container = document.createElement("div");
- slot.assignedNodes({ flatten: true }).forEach((child) => {
- if (child instanceof HTMLElement) {
- container.appendChild(child);
- }
- });
- dialog.content = html`${container}`;
- dialog.dismissAction = null;
- this.requestUpdate();
- }
- }
-
- firstUpdated(changedProperties: PropertyValues) {
- if (changedProperties.has("action")) {
- this.renderDialogHTML(this.action);
- }
- }
-
- checkForm() {
- const dialog: OrMwcDialog = this.shadowRoot!.host as OrMwcDialog;
-
- if (this.shadowRoot) {
- const alarmConfig = this.shadowRoot.querySelector("or-rule-form-alarm");
-
- if (alarmConfig && alarmConfig.shadowRoot) {
- const form = alarmConfig.shadowRoot.querySelector("form");
- return checkValidity(form, dialog);
- }
- }
- }
-
- protected render() {
- if (!this.action) return html``;
-
- const alarmPickerModalActions: DialogAction[] = [
- {
- actionName: "cancel",
- content: html`<or-mwc-input
- class="button"
- .type="${InputType.BUTTON}"
- .label="${i18next.t("cancel")}"
- ></or-mwc-input>`,
- action: (dialog) => {},
- },
- {
- actionName: "",
- content: html`<or-mwc-input
- class="button"
- .type="${InputType.BUTTON}"
- .label="${i18next.t("ok")}"
- @or-mwc-input-changed="${this.checkForm}"
- ></or-mwc-input>`,
- },
- ];
-
- const alarmPickerModalOpen = () => {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("alarm-modal") as OrMwcDialog;
- if (dialog) {
- dialog.open();
- }
- };
-
- const severityOptions: SelectItem[] = [
- { value: AlarmSeverity.LOW, label: i18next.t("alarm.severity_LOW") },
- { value: AlarmSeverity.MEDIUM, label: i18next.t("alarm.severity_MEDIUM") },
- { value: AlarmSeverity.HIGH, label: i18next.t("alarm.severity_HIGH") },
- ];
-
- return html`
- <or-vaadin-select
- value=${this.action.alarm?.severity}
- .items=${severityOptions}
- style="width: 240px;"
- @change=${(ev: Event) => this.setActionAlarmSeverity((ev.currentTarget as OrVaadinSelect).value)}
- >
- <or-translate slot="label" value="alarm.severity"></or-translate>
- </or-vaadin-select>
- <or-vaadin-button @click=${() => alarmPickerModalOpen()}>
- <or-translate value="settings"></or-translate>
- </or-vaadin-button>
- <or-mwc-dialog id="alarm-modal" heading="${this.title}" .actions="${alarmPickerModalActions}"></or-mwc-dialog>
- <slot class="alarm-form-slot"></slot>
- `;
- }
-
- protected setActionAlarmSeverity(value: string | undefined) {
- if (value && this.action.alarm) {
- const alarm: any = this.action.alarm;
- alarm.severity = value;
- this.action.alarm = { ...alarm };
- }
-
- this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
- this.requestUpdate();
- }
-}
diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts
deleted file mode 100644
index f7ac5678c..000000000
--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright 2026, OpenRemote Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-import { html, type PropertyValues } from "lit";
-import { OrElement } from "@openremote/or-element";
-import { customElement, property, query } from "lit/decorators.js";
-import type { RuleActionNotification, AssetQuery } from "@openremote/model";
-
-import "@openremote/or-mwc-components/or-mwc-input";
-import { InputType } from "@openremote/or-mwc-components/or-mwc-input";
-import { i18next, translate } from "@openremote/or-translate";
-
-import {
- type DialogAction,
- type DialogActionBase,
- type OrMwcDialog,
- OrMwcDialogOpenedEvent,
-} from "@openremote/or-mwc-components/or-mwc-dialog";
-import type { OrRuleFormLocalized } from "../forms/or-rule-form-localized";
-import { OrRulesJsonRuleChangedEvent } from "../or-rule-json-viewer";
-
-const checkValidity = (form: HTMLElement | null) => {
- if (form) {
- const inputs = form.querySelectorAll("or-mwc-input");
- const elements = Array.prototype.slice.call(inputs);
-
- return elements.every((element) => {
- if (element.shadowRoot) {
- const input = element.shadowRoot.querySelector("input, textarea, select") as any;
-
- if (input && input.checkValidity()) {
- return true;
- } else {
- if (element._mdcComponent) {
- element._mdcComponent.valid = false;
- element._mdcComponent.helperTextContent = "required";
- }
-
- return false;
- }
- } else {
- return false;
- }
- });
- }
-};
-
-export class OrRulesNotificationModalCancelEvent extends CustomEvent<void> {
- public static readonly NAME = "or-rules-notification-modal-cancel";
-
- constructor() {
- super(OrRulesNotificationModalCancelEvent.NAME, {
- bubbles: true,
- composed: true,
- });
- }
-}
-
-export class OrRulesNotificationModalOkEvent extends CustomEvent<void> {
- public static readonly NAME = "or-rules-notification-modal-ok";
-
- constructor() {
- super(OrRulesNotificationModalOkEvent.NAME, {
- bubbles: true,
- composed: true,
- });
- }
-}
-
-@customElement("or-rule-notification-modal")
-export class OrRuleNotificationModal extends translate(i18next)(OrElement) {
- @property({ type: Object })
- public action!: RuleActionNotification;
-
- @property({ type: String })
- public title = "message";
-
- @property({ type: Object })
- public query?: AssetQuery;
-
- @property({ type: Boolean })
- public readonly = false;
-
- @query("#notification-modal")
- protected _orMwcDialog?: OrMwcDialog;
-
- constructor() {
- super();
- this.addEventListener(OrMwcDialogOpenedEvent.NAME, this.initDialog);
- }
-
- connectedCallback() {
- this.addEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
- return super.connectedCallback();
- }
-
- disconnectedCallback() {
- this.removeEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onJsonRuleChanged);
- return super.disconnectedCallback();
- }
-
- protected _onJsonRuleChanged() {
- this.validateForm();
- }
-
- initDialog() {
- if (!this._orMwcDialog) return;
- }
-
- renderDialogHTML(action: RuleActionNotification) {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("notification-modal") as OrMwcDialog;
- if (!this.shadowRoot) return;
-
- const slot: HTMLSlotElement | null = this.shadowRoot.querySelector(".notification-form-slot");
- if (dialog && slot) {
- const container = document.createElement("div");
- slot.assignedNodes({ flatten: true }).forEach((child) => {
- if (child instanceof HTMLElement) {
- container.appendChild(child);
- }
- });
- dialog.content = html`${container}`;
- dialog.dismissAction = null;
- this.requestUpdate();
- }
- }
-
- firstUpdated(changedProperties: PropertyValues) {
- if (changedProperties.has("action")) {
- this.renderDialogHTML(this.action);
- }
- // Possibly, a render is triggered by renderDialogHTML(), so we await the pending update. (if there is any)
- this.getUpdateComplete().finally(() => {
- this.validateForm();
- });
- }
-
- validateForm() {
- const valid = this.checkForm();
- this._orMwcDialog?.setActions(
- this._orMwcDialog?.actions?.map((action) => {
- if (action.actionName === "ok") {
- action.disabled = !valid;
- }
- return action;
- })
- );
- }
-
- checkForm() {
- if (this.shadowRoot) {
- const dialog = this._orMwcDialog;
- const root = dialog?.shadowRoot;
- if (dialog && root) {
- const messageNotification = root.querySelector("or-rule-form-email-message");
- const pushNotification = root.querySelector("or-rule-form-push-notification");
- const localizedNotification = root.querySelector("or-rule-form-localized");
-
- if (pushNotification?.shadowRoot) {
- const form = pushNotification.shadowRoot.querySelector("form");
- return checkValidity(form);
- } else if (messageNotification?.shadowRoot) {
- const form = messageNotification.shadowRoot.querySelector("form");
- return checkValidity(form);
- } else if (localizedNotification?.shadowRoot) {
- return (localizedNotification as OrRuleFormLocalized).isValid();
- }
- }
- }
- }
-
- protected render() {
- const onCancel = () => {
- this.dispatchEvent(new OrRulesNotificationModalCancelEvent());
- };
-
- const onOk = () => {
- this.dispatchEvent(new OrRulesNotificationModalOkEvent());
- };
-
- const dismissAction: DialogActionBase = {
- actionName: "cancel",
- action: onCancel,
- };
-
- const actions: DialogAction[] = [
- {
- actionName: "cancel",
- content: html`<or-mwc-input class="button" .type="${InputType.BUTTON}" label="cancel"></or-mwc-input>`,
- action: onCancel,
- },
- {
- actionName: "ok",
- content: "ok",
- disabled: true, // (by default, can be changed in checkForm())
- action: onOk,
- },
- ];
-
- const styles = html`
- <style>
- .mdc-dialog__actions {
- justify-content: space-between !important;
- }
- </style>
- `;
-
- const notificationPickerModalOpen = () => {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("notification-modal") as OrMwcDialog;
- if (dialog) {
- dialog.open();
- }
- };
-
- return html`
- <or-vaadin-button ?disabled=${this.readonly} @click=${() => notificationPickerModalOpen()}>
- <or-translate value="message"></or-translate>
- </or-vaadin-button>
- <or-mwc-dialog
- id="notification-modal"
- .heading="${this.title}"
- .dismissAction="${dismissAction}"
- .actions="${actions}"
- .styles="${styles}"
- ></or-mwc-dialog>
- <slot class="notification-form-slot"></slot>
- `;
- }
-}
diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-webhook-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-webhook-modal.ts
deleted file mode 100644
index d588c2ea7..000000000
--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-webhook-modal.ts
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright 2026, OpenRemote Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <https://www.gnu.org/licenses/>.
- *
- * SPDX-License-Identifier: AGPL-3.0-or-later
- */
-import type { RuleActionWebhook } from "@openremote/model";
-import { InputType, type OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";
-import type { DialogAction, OrMwcDialog } from "@openremote/or-mwc-components/or-mwc-dialog";
-import { i18next } from "@openremote/or-translate";
-import { html, type PropertyValues } from "lit";
-import { OrElement } from "@openremote/or-element";
-import { customElement, property } from "lit/decorators.js";
-
-@customElement("or-rule-webhook-modal")
-export class OrRuleWebhookModal extends OrElement {
- @property({ type: Object })
- protected action!: RuleActionWebhook;
-
- @property({ type: String })
- public title: string = i18next.t("message");
-
- constructor() {
- super();
- }
-
- /* ----------------------- */
-
- firstUpdated(changedProperties: PropertyValues) {
- if (changedProperties.has("action")) {
- this.renderDialogHTML(this.action);
- }
- }
-
- renderDialogHTML(action: RuleActionWebhook) {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("webhook-modal") as OrMwcDialog;
- if (!this.shadowRoot) return;
-
- const slot: HTMLSlotElement | null = this.shadowRoot.querySelector(".webhook-form-slot");
- if (dialog && slot) {
- const container = document.createElement("div");
- slot.assignedNodes({ flatten: true }).forEach((child) => {
- if (child instanceof HTMLElement) {
- container.appendChild(child);
- }
- });
- dialog.content = html`${container}`;
- dialog.dismissAction = null;
- this.requestUpdate();
- }
- }
-
- closeForm(event: OrInputChangedEvent) {
- const dialog: OrMwcDialog = this.shadowRoot!.host as OrMwcDialog;
- dialog.close();
- }
-
- render() {
- if (!this.action) {
- return html`${i18next.t("errorOccurred")}`;
- }
- const webhookModalActions: DialogAction[] = [
- {
- actionName: "",
- content: html` <or-mwc-input
- .type="${InputType.BUTTON}"
- label="ok"
- @or-mwc-input-changed="${this.closeForm}"
- ></or-mwc-input>`,
- },
- ];
- const webhookModalOpen = () => {
- const dialog: OrMwcDialog = this.shadowRoot!.getElementById("webhook-modal") as OrMwcDialog;
- if (dialog) {
- dialog.open();
- }
- };
- return html`
- <or-vaadin-button @click=${() => webhookModalOpen()}>
- <or-translate value="message"></or-translate>
- </or-vaadin-button>
- <or-mwc-dialog id="webhook-modal" heading="${this.title}" .actions="${webhookModalActions}"></or-mwc-dialog>
- <slot class="webhook-form-slot"></slot>
- `;
- }
-}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-alarm.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-alarm.ts
index 37be45564..c175e3493 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-alarm.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-alarm.ts
@@ -16,17 +16,39 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import { html, type TemplateResult } from "lit";
+import { css, html } from "lit";
import { OrElement } from "@openremote/or-element";
-import { customElement, property } from "lit/decorators.js";
+import { customElement, property, query } from "lit/decorators.js";
import type { ActionType, RulesConfig } from "../index";
-import type { JsonRule, RuleActionAlarm, User, UserQuery } from "@openremote/model";
-import "./modals/or-rule-alarm-modal";
+import { AlarmSeverity, type JsonRule, type RuleActionAlarm, type User, type UserQuery } from "@openremote/model";
+import "@openremote/or-vaadin-components/or-vaadin-select";
+import "./or-rule-json-dialog";
import "./forms/or-rule-form-alarm";
+import type { OrRuleFormAlarm } from "./forms/or-rule-form-alarm";
import manager from "@openremote/core";
+import type { OrRulesActionDialogCancelEvent, OrRulesActionDialogOkEvent } from "./or-rule-json-dialog";
+import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
+import type { OrVaadinSelect, SelectItem } from "@openremote/or-vaadin-components/or-vaadin-select";
+import { i18next } from "@openremote/or-translate";
+
+// language=CSS
+const style = css`
+ :host {
+ display: flex;
+ align-items: baseline;
+ }
+
+ :host > * {
+ margin: 0 3px 6px;
+ }
+`;
@customElement("or-rule-action-alarm")
export class OrRuleActionAlarm extends OrElement {
+ static get styles() {
+ return style;
+ }
+
@property({ type: Object, attribute: false })
public rule!: JsonRule;
@@ -36,14 +58,20 @@ export class OrRuleActionAlarm extends OrElement {
@property({ type: String, attribute: false })
public actionType!: ActionType;
+ @property({ type: Boolean })
public readonly?: boolean;
@property({ type: Object })
public config?: RulesConfig;
+ @query("or-rule-form-alarm")
+ protected _formElem?: OrRuleFormAlarm;
+
+ protected _initialAction?: RuleActionAlarm;
protected _loadedUsers: User[] = [];
async connectedCallback(): Promise<void> {
+ this._initialAction = structuredClone(this.action);
await this.loadUsers();
super.connectedCallback();
}
@@ -65,18 +93,72 @@ export class OrRuleActionAlarm extends OrElement {
return html``;
}
- const alarm = this.action.alarm;
+ // When 'cancel' is pressed, reset ACTION to the initial state (all changes get removed)
+ const onModalCancel = (_ev: OrRulesActionDialogCancelEvent) => {
+ if (this._initialAction?.alarm && this.action.alarm) {
+ // Severity is edited outside of the dialog, so it is kept rather than rolled back
+ const initialAlarm = { ...structuredClone(this._initialAction.alarm), severity: this.action.alarm.severity };
+ console.debug("Rolling back the alarm to former state...");
+
+ // Check if anything in the alarm has changed
+ if (
+ JSON.stringify(this.action.alarm) !== JSON.stringify(initialAlarm) ||
+ this.action.assigneeId !== this._initialAction.assigneeId
+ ) {
+ // Assign into the existing action, as the rule holds a reference to it
+ this.action.alarm = initialAlarm;
+ this.action.assigneeId = this._initialAction.assigneeId;
+ this._formElem?.requestUpdate();
+ this.requestUpdate("action");
+ } else {
+ console.debug("Rolling back was not necessary, as no changes have been done.");
+ }
+ } else {
+ console.warn("Could not rollback alarm form.");
+ }
+ };
+
+ const onModalOk = (_ev: OrRulesActionDialogOkEvent) => {
+ this._initialAction = structuredClone(this.action); // update initial action for opening the modal in the future
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
+ };
- let modalTemplate: TemplateResult | string = ``;
+ const severityOptions: SelectItem[] = [
+ { value: AlarmSeverity.LOW, label: i18next.t("alarm.severity_LOW") },
+ { value: AlarmSeverity.MEDIUM, label: i18next.t("alarm.severity_MEDIUM") },
+ { value: AlarmSeverity.HIGH, label: i18next.t("alarm.severity_HIGH") },
+ ];
+
+ return html`
+ <or-vaadin-select
+ value=${this.action.alarm?.severity}
+ .items=${severityOptions}
+ ?readonly=${this.readonly}
+ style="width: 240px;"
+ @change=${(ev: Event) => this.setActionAlarmSeverity((ev.currentTarget as OrVaadinSelect).value)}
+ >
+ <or-translate slot="label" value="alarm.severity"></or-translate>
+ </or-vaadin-select>
+ <or-rule-json-dialog ?readonly=${this.readonly} @cancel="${onModalCancel}" @ok="${onModalOk}">
+ <or-translate slot="button" value="settings"></or-translate>
+ <or-translate slot="title" value="alarm."></or-translate>
+ <or-rule-form-alarm
+ .users="${this._loadedUsers}"
+ .action="${this.action}"
+ ?readonly=${this.readonly}
+ ></or-rule-form-alarm>
+ </or-rule-json-dialog>
+ `;
+ }
- if (alarm) {
- modalTemplate = html`
- <or-rule-alarm-modal title="alarm." .action="${this.action}">
- <or-rule-form-alarm .users="${this._loadedUsers}" .action="${this.action}"></or-rule-form-alarm>
- </or-rule-alarm-modal>
- `;
+ protected setActionAlarmSeverity(value: string | undefined) {
+ if (value && this.action.alarm) {
+ const alarm: any = this.action.alarm;
+ alarm.severity = value;
+ this.action.alarm = { ...alarm };
}
- return html`${modalTemplate}`;
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
+ this.requestUpdate();
}
}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
index e952ad332..e3b26abc8 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts
@@ -36,17 +36,14 @@ import {
type LocalizedNotificationMessage,
} from "@openremote/model";
import { getTargetTypeMap, OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
-import "./modals/or-rule-notification-modal";
+import "./or-rule-json-dialog";
import "./forms/or-rule-form-email-message";
import "./forms/or-rule-form-push-notification";
import "./forms/or-rule-form-localized";
import "./or-rule-action-attribute";
import { i18next } from "@openremote/or-translate";
import manager, { Util } from "@openremote/core";
-import type {
- OrRulesNotificationModalCancelEvent,
- OrRulesNotificationModalOkEvent,
-} from "./modals/or-rule-notification-modal";
+import type { OrRulesActionDialogCancelEvent, OrRulesActionDialogOkEvent } from "./or-rule-json-dialog";
import type { OrVaadinComboBox } from "@openremote/or-vaadin-components/or-vaadin-combo-box";
// language=CSS
@@ -421,7 +418,7 @@ export class OrRuleActionNotification extends OrElement {
}
// When 'cancel' is pressed, reset ACTION to the initial state (all changes get removed)
- const onModalCancel = (ev: OrRulesNotificationModalCancelEvent) => {
+ const onModalCancel = (_ev: OrRulesActionDialogCancelEvent) => {
if (this._initialAction && this.action.notification) {
const newAction = structuredClone(this._initialAction);
@@ -438,7 +435,7 @@ export class OrRuleActionNotification extends OrElement {
}
};
- const onModalOk = (ev: OrRulesNotificationModalOkEvent) => {
+ const onModalOk = (_ev: OrRulesActionDialogOkEvent) => {
this._initialAction = structuredClone(this.action); // update initial action for opening the modal in the future
this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
};
@@ -446,29 +443,25 @@ export class OrRuleActionNotification extends OrElement {
if (message) {
if (messageType === "push") {
modalTemplate = html`
- <or-rule-notification-modal
- title="push-notification"
- .action="${this.action}"
- ?readonly=${this.readonly}
- @or-rules-notification-modal-cancel="${onModalCancel}"
- @or-rules-notification-modal-ok="${onModalOk}"
- >
+ <or-rule-json-dialog ?readonly=${this.readonly} @cancel="${onModalCancel}" @ok="${onModalOk}">
+ <or-translate slot="button" value="message"></or-translate>
+ <or-translate slot="title" value="push-notification"></or-translate>
<or-rule-form-push-notification
.message="${message as PushNotificationMessage}"
+ ?readonly=${this.readonly}
></or-rule-form-push-notification>
- </or-rule-notification-modal>
+ </or-rule-json-dialog>
`;
} else if (messageType === "email") {
modalTemplate = html`
- <or-rule-notification-modal
- title="email"
- .action="${this.action}"
- ?readonly=${this.readonly}
- @or-rules-notification-modal-cancel="${onModalCancel}"
- @or-rules-notification-modal-ok="${onModalOk}"
- >
- <or-rule-form-email-message .message="${message as EmailNotificationMessage}"></or-rule-form-email-message>
- </or-rule-notification-modal>
+ <or-rule-json-dialog ?readonly=${this.readonly} @cancel="${onModalCancel}" @ok="${onModalOk}">
+ <or-translate slot="button" value="message"></or-translate>
+ <or-translate slot="title" value="email"></or-translate>
+ <or-rule-form-email-message
+ .message="${message as EmailNotificationMessage}"
+ ?readonly=${this.readonly}
+ ></or-rule-form-email-message>
+ </or-rule-json-dialog>
`;
} else if (messageType === "localized") {
const notificationConfig =
@@ -487,21 +480,18 @@ export class OrRuleActionNotification extends OrElement {
const type = this.actionType === ActionType.EMAIL_LOCALIZED ? "email" : "push";
const title = this.actionType === ActionType.EMAIL_LOCALIZED ? "email" : "push-notification";
modalTemplate = html`
- <or-rule-notification-modal
- title="${title}"
- .action="${this.action}"
- ?readonly=${this.readonly}
- @or-rules-notification-modal-cancel="${onModalCancel}"
- @or-rules-notification-modal-ok="${onModalOk}"
- >
+ <or-rule-json-dialog ?readonly=${this.readonly} @cancel="${onModalCancel}" @ok="${onModalOk}">
+ <or-translate slot="button" value="message"></or-translate>
+ <or-translate slot="title" value=${title}></or-translate>
<or-rule-form-localized
.message="${message}"
.type="${type}"
.languages="${languages}"
.defaultLang="${defaultLang}"
.wrongLanguage="${defaultLangHasChanged}"
+ ?readonly=${this.readonly}
></or-rule-form-localized>
- </or-rule-notification-modal>
+ </or-rule-json-dialog>
`;
}
}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-webhook.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-webhook.ts
index c6e1ca54f..fe9fc7b7b 100644
--- a/ui/component/or-rules/src/json-viewer/or-rule-action-webhook.ts
+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-webhook.ts
@@ -16,12 +16,14 @@
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import type { JsonRule, RuleActionWebhook } from "@openremote/model";
+import type { JsonRule, RuleActionWebhook, Webhook } from "@openremote/model";
import { css, html } from "lit";
import { OrElement } from "@openremote/or-element";
import { customElement, property } from "lit/decorators.js";
-import "./modals/or-rule-webhook-modal";
+import "./or-rule-json-dialog";
import "./forms/or-rule-form-webhook";
+import type { OrRulesActionDialogCancelEvent, OrRulesActionDialogOkEvent } from "./or-rule-json-dialog";
+import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
// language=CSS
const style = css`
@@ -51,15 +53,48 @@ export class OrRuleActionWebhook extends OrElement {
@property({ type: Object, attribute: false })
public action!: RuleActionWebhook;
+ @property({ type: Boolean })
+ public readonly?: boolean;
+
+ protected _initialWebhook?: Webhook;
+
+ override connectedCallback() {
+ this._initialWebhook = structuredClone(this.action.webhook);
+ super.connectedCallback();
+ }
+
/* ---------------------- */
- render() {
+ override render() {
+ // When 'cancel' is pressed, reset ACTION to the initial state (all changes get removed)
+ const onModalCancel = (_ev: OrRulesActionDialogCancelEvent) => {
+ if (this._initialWebhook && this.action.webhook) {
+ const initialWebhook = structuredClone(this._initialWebhook);
+ console.debug("Rolling back the webhook to former state...");
+
+ // Check if anything in the message has changed
+ if (JSON.stringify(this.action.webhook) !== JSON.stringify(initialWebhook)) {
+ this.action.webhook = initialWebhook;
+ this.requestUpdate("action");
+ } else {
+ console.debug("Rolling back was not necessary, as no changes have been done.");
+ }
+ } else {
+ console.warn("Could not rollback webhook form.");
+ }
+ };
+
+ const onModalOk = (_ev: OrRulesActionDialogOkEvent) => {
+ this._initialWebhook = structuredClone(this.action.webhook); // update initial action for opening the modal in the future
+ this.dispatchEvent(new OrRulesJsonRuleChangedEvent());
+ };
+
return html`
- <div style="display: flex; align-items: center; height: 100%;">
- <or-rule-webhook-modal .action="${this.action}">
- <or-rule-form-webhook .webhook="${this.action.webhook}"></or-rule-form-webhook>
- </or-rule-webhook-modal>
- </div>
+ <or-rule-json-dialog ?readonly=${this.readonly} @cancel="${onModalCancel}" @ok="${onModalOk}">
+ <or-translate slot="button" value="message"></or-translate>
+ <or-translate slot="title" value="message"></or-translate>
+ <or-rule-form-webhook .webhook="${this.action.webhook}" ?readonly=${this.readonly}></or-rule-form-webhook>
+ </or-rule-json-dialog>
`;
}
}
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-condition.ts b/ui/component/or-rules/src/json-viewer/or-rule-condition.ts
index 37cc3aeb8..664cfead1 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
@@ -67,7 +67,7 @@ export function getWhenTypesMenu(
component: createMenuBarItem(html`
<div style="display: flex; align-items: center; gap: 6px;">
<or-icon
- style=${color ? `--or-icon-fill: #${color}` : undefined}
+ style="--or-icon-fill: ${color ? "#" + color : "unset"}"
icon=${icon || AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET)}
></or-icon>
<span>${Util.getAssetTypeLabel(assetTypeInfo.assetDescriptor!)}</span>
diff --git a/ui/component/or-rules/src/json-viewer/or-rule-json-dialog.ts b/ui/component/or-rules/src/json-viewer/or-rule-json-dialog.ts
new file mode 100644
index 000000000..5b739d760
--- /dev/null
+++ b/ui/component/or-rules/src/json-viewer/or-rule-json-dialog.ts
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2026, OpenRemote Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ */
+import { OrElement } from "@openremote/or-element";
+import { customElement, property, query, queryAssignedElements, state } from "lit/decorators.js";
+import { html } from "lit";
+import "@openremote/or-vaadin-components/or-vaadin-button";
+import "@openremote/or-vaadin-components/or-vaadin-dialog";
+import type { OrVaadinDialog } from "@openremote/or-vaadin-components/or-vaadin-dialog";
+import type { OrRuleForm } from "./forms/or-rule-form";
+import { OrRulesJsonRuleChangedEvent } from "./or-rule-json-viewer";
+
+export class OrRulesActionDialogCancelEvent extends CustomEvent<void> {
+ public static readonly NAME = "cancel";
+
+ constructor() {
+ super(OrRulesActionDialogCancelEvent.NAME, {
+ bubbles: false,
+ composed: true,
+ });
+ }
+}
+
+export class OrRulesActionDialogOkEvent extends CustomEvent<void> {
+ public static readonly NAME = "ok";
+
+ constructor() {
+ super(OrRulesActionDialogOkEvent.NAME, {
+ bubbles: false,
+ composed: true,
+ });
+ }
+}
+
+/**
+ * @fires {OrRulesActionDialogCancelEvent} cancel - Fires on pressing 'cancel' in the dialog
+ * @fires {OrRulesActionDialogOkEvent} ok - Fires on pressing 'OK' in the dialog
+ */
+@customElement("or-rule-json-dialog")
+export class OrRuleJsonDialog extends OrElement {
+ @property({ type: Boolean })
+ public readonly = false;
+
+ @state()
+ protected _invalid = false;
+
+ @queryAssignedElements({ slot: undefined })
+ protected _childNodes?: Array<HTMLElement>;
+
+ @query("or-vaadin-dialog")
+ protected _dialog?: OrVaadinDialog;
+
+ override render() {
+ return html`
+ <or-vaadin-button @click=${() => this._openDialog()}>
+ <slot name="button"></slot>
+ </or-vaadin-button>
+ <or-vaadin-dialog width="768px" no-close-on-esc no-close-on-outside-click @closed=${() => this._onClose()}>
+ <h2 slot="header-content">
+ <slot name="title"></slot>
+ </h2>
+ <slot></slot>
+ <div slot="footer">
+ <or-vaadin-button @click=${() => this._onCancel()}>
+ <or-translate value="cancel"></or-translate>
+ </or-vaadin-button>
+ <or-vaadin-button theme="primary" ?disabled=${this.readonly || this._invalid} @click=${() => this._onOk()}>
+ <or-translate value="ok"></or-translate>
+ </or-vaadin-button>
+ </div>
+ </or-vaadin-dialog>
+ `;
+ }
+
+ protected _openDialog() {
+ this._dialog?.open();
+ this._subscribeToValueChanges();
+ }
+
+ protected _subscribeToValueChanges() {
+ this.addEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onFormValueChange);
+ this._onFormValueChange(); // Check validity once upon subscribing
+ }
+
+ protected _unsubscribeFromValueChanges() {
+ this.removeEventListener(OrRulesJsonRuleChangedEvent.NAME, this._onFormValueChange);
+ }
+
+ protected _onFormValueChange(ev?: OrRulesJsonRuleChangedEvent) {
+ ev?.stopPropagation(); // Don't make parent elements aware of form changes; only upon closing the dialog.
+ this._invalid =
+ (this._childNodes
+ ?.map((c) => c as unknown as OrRuleForm | HTMLInputElement)
+ .filter((c) => c && c.checkValidity)
+ .filter((c) => !c.checkValidity()).length ?? 0) > 0;
+ }
+
+ protected _onCancel() {
+ this._dialog?.close();
+ this.dispatchEvent(new OrRulesActionDialogCancelEvent());
+ }
+
+ protected _onOk() {
+ this._dialog?.close();
+ this.dispatchEvent(new OrRulesActionDialogOkEvent());
+ }
+
+ protected _onClose() {
+ this._unsubscribeFromValueChanges();
+ }
+}
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.ts
index c6732f977..6476be3a2 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
@@ -99,7 +99,7 @@ function getActionTypesMenu(config?: RulesConfig, assetInfos?: AssetTypeInfo[],
createMenuBarItem(html`
<div style="display: flex; align-items: center; gap: 6px;">
<or-icon
- style=${color ? `--or-icon-fill: #${color}` : undefined}
+ style="--or-icon-fill: ${color ? "#" + color : "unset"}"
icon=${icon || AssetModelUtil.getAssetDescriptorIcon(WellknownAssets.THINGASSET)}
></or-icon>
${when(
@@ -441,6 +441,7 @@ class OrRuleThenOtherwise extends translate(i18next)(OrElement) {
.rule="${this.rule}"
.action="${action}"
.actionType="${ActionType.WEBHOOK}"
+ .readonly="${this.readonly}"
></or-rule-action-webhook>`;
break;
case ActionType.ALARM:
@@ -448,6 +449,7 @@ class OrRuleThenOtherwise extends translate(i18next)(OrElement) {
.rule="${this.rule}"
.action="${action}"
.actionType="${ActionType.ALARM}"
+ .readonly="${this.readonly}"
></or-rule-action-alarm>`;
break;
default:
diff --git a/ui/component/or-vaadin-components/src/or-vaadin-checkbox-group.ts b/ui/component/or-vaadin-components/src/or-vaadin-checkbox-group.ts
index 5d4cc8e8d..63e39e1e3 100644
--- a/ui/component/or-vaadin-components/src/or-vaadin-checkbox-group.ts
+++ b/ui/component/or-vaadin-components/src/or-vaadin-checkbox-group.ts
@@ -31,7 +31,7 @@ export class OrVaadinCheckboxGroup extends CheckboxGroup implements OrVaadinComp
* check, so wrapped children (`or-vaadin-checkbox`, `or-vaadin-toggle`) would never register: the
* group's `value`, its validation and its disabled/readonly propagation would all ignore them.
* Accept any `Checkbox` subclass instead. This overrides a private Vaadin API, so re-check it when
- * upgrading Vaadin (verified against 25.2.4).
+ * upgrading Vaadin (verified against v25).
*/
private __filterCheckboxes(nodes: Node[]): Checkbox[] {
return nodes.filter((node): node is Checkbox => node instanceof Checkbox);
diff --git a/ui/component/or-vaadin-components/src/or-vaadin-dialog.ts b/ui/component/or-vaadin-components/src/or-vaadin-dialog.ts
index 41cf4a3c8..689289210 100644
--- a/ui/component/or-vaadin-components/src/or-vaadin-dialog.ts
+++ b/ui/component/or-vaadin-components/src/or-vaadin-dialog.ts
@@ -19,7 +19,8 @@
import { Dialog } from "@vaadin/dialog";
import type { OrVaadinComponent } from "./util";
import { customElement } from "lit/decorators.js";
-import { type LitElement, css } from "lit";
+import { type LitElement, type TemplateResult, css, render } from "lit";
+import { Util } from "@openremote/core";
/**
* Vaadin uses custom directives for rendering the dialog content.
@@ -37,6 +38,32 @@ export {
type WithLit<T> = T & typeof LitElement;
+/**
+ * Helper function for rendering the `<or-vaadin-dialog>` dynamically, to "show a dialog on command".
+ * This saves initial render time for components, and prevents state handling on the consumer side.
+ * `showDialog()` appends (and updates) dialogs to the host element when called,
+ * and automatically removes the element upon closing the dialog.
+ * @param host - Host element (often shadow root) to append the dialog container as a child.
+ * @param dialog - A {@link TemplateResult} to render. It is required to contain a `<or-vaadin-dialog>` tag.
+ */
+export function showDialog(host: Node, dialog: TemplateResult): OrVaadinDialog | undefined {
+ const container = document.createElement("div");
+ container.id = `dialog-${Util.generateUniqueUUID()}`;
+ render(dialog, container); // Render Lit template inside the container
+
+ const dialogElem = container.querySelector("or-vaadin-dialog") as OrVaadinDialog | null;
+ if (dialogElem) {
+ dialogElem.open();
+ dialogElem.addEventListener("closed", () => container.remove());
+ } else {
+ // As no or-vaadin-dialog is present, we can remove the HTMLElement
+ container.remove();
+ return;
+ }
+ host.appendChild(container);
+ return dialogElem;
+}
+
@customElement("or-vaadin-dialog")
export class OrVaadinDialog extends (Dialog as new () => Dialog & LitElement) implements OrVaadinComponent {
static get styles() {