100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
Render JSON Forms for multidimensional supported well known types (#3107)
Koen954761ff9c86
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex dad6e6ff9..62dda55ff 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -145,7 +145,9 @@ async function getSchema(valueDescriptor: ValueDescriptor) {}export const jsonFormsInputTemplateProvider: (fallback: ValueInputProvider, clear?: boolean) => ValueInputProviderGenerator = (fallback, clear) => (assetDescriptor, valueHolder, valueHolderDescriptor, valueDescriptor, valueChangeNotifier, options) => {- if (Util.isComplexValueDescriptor(valueDescriptor) && !SUPPORTED_WELLKNOWN_VALUE_TYPES.includes(valueDescriptor.name as SupportedWellknownValueTypes)) {+ if (Util.isComplexValueDescriptor(valueDescriptor) && !(+ SUPPORTED_WELLKNOWN_VALUE_TYPES.includes(valueDescriptor.name as SupportedWellknownValueTypes) && !valueDescriptor?.arrayDimensions+ )) {const disabled = !!(options && options.disabled);const readonly = !!(options && options.readonly);const label = options.label;diff --git a/ui/component/or-attribute-input/test/fixtures/provider-probe.js b/ui/component/or-attribute-input/test/fixtures/provider-probe.jsnew file mode 100644index 000000000..cbc9f8134--- /dev/null+++ b/ui/component/or-attribute-input/test/fixtures/provider-probe.js@@ -0,0 +1,53 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * 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 <http://www.gnu.org/licenses/>.+ */+// Plain JS on purpose: the component-test bundle compiles .ts files against ui/test's tsconfig+// (rootDir ui/test), so TS component sources outside that dir fail the build. jsonFormsInputTemplateProvider+// pulls in browser-only modules, so it can only run in the browser via a mounted fixture, not the Node test body.+import { html, LitElement } from "lit";+import { jsonFormsInputTemplateProvider } from "@openremote/or-attribute-input";++/**+ * Reports which template jsonFormsInputTemplateProvider picks for a value descriptor:+ * "json-forms" when it builds its own editor, "fallback" when it defers to the fallback provider.+ */+export class ProviderProbe extends LitElement {+ static properties = { descriptor: { type: Object } };++ render() {+ if (!this.descriptor) {+ return html``;+ }++ // A sentinel fallback: an identity check against it tells the two branches apart+ // without rendering either template (so no schema request is made).+ const fallback = {+ templateFunction: () => html``,+ supportsHelperText: true,+ supportsLabel: true,+ supportsSendButton: true,+ };+ const provider = jsonFormsInputTemplateProvider(fallback)(+ "TestAsset", undefined, undefined, this.descriptor, () => {}, {}+ );+ const result = provider === fallback ? "fallback" : "json-forms";+ return html`<div role="status">${result}</div>`;+ }+}+customElements.define("test-provider-probe", ProviderProbe);diff --git a/ui/component/or-attribute-input/test/input-provider.test.ts b/ui/component/or-attribute-input/test/input-provider.test.tsnew file mode 100644index 000000000..fa03e3630--- /dev/null+++ b/ui/component/or-attribute-input/test/input-provider.test.ts@@ -0,0 +1,60 @@+/*+ * Copyright 2026, OpenRemote Inc.+ *+ * See the CONTRIBUTORS.txt file in the distribution for a+ * full listing of individual contributors.+ *+ * 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 <http://www.gnu.org/licenses/>.+ */+import { ct, expect } from "@openremote/test";++import { ProviderProbe } from "./fixtures/provider-probe.js";++// WellknownValueTypes string values, inlined to keep @openremote/model out of the Node test body.+const NUMBER = "number";+const TEXT = "text";+const JSON_OBJECT = "JSONObject";++/** Mounts the probe for a descriptor and returns the routing decision it reports. */+async function route(mount: any, descriptor: Record<string, unknown>) {+ const component = await mount(ProviderProbe, { props: { descriptor } });+ return component.getByRole("status");+}++ct("should route a multidimensional supported type to the JSON Forms editor", async ({ mount }) => {+ // A one-dimensional array of a supported type is not handled by the simple input.+ const status = await route(mount, { name: NUMBER, jsonType: "number", arrayDimensions: 1 });+ await expect(status).toHaveText("json-forms");+});++ct("should route a nested multidimensional supported type to the JSON Forms editor", async ({ mount }) => {+ const status = await route(mount, { name: NUMBER, jsonType: "number", arrayDimensions: 2 });+ await expect(status).toHaveText("json-forms");+});++ct("should keep a scalar supported complex type on the fallback input", async ({ mount }) => {+ // A plain (non-array) JSONObject is a supported type, so it stays on the simple JSON input.+ const status = await route(mount, { name: JSON_OBJECT, jsonType: "object" });+ await expect(status).toHaveText("fallback");+});++ct("should route an unsupported complex type to the JSON Forms editor", async ({ mount }) => {+ const status = await route(mount, { name: "customStruct", jsonType: "object" });+ await expect(status).toHaveText("json-forms");+});++ct("should keep a primitive type on the fallback input", async ({ mount }) => {+ const status = await route(mount, { name: TEXT, jsonType: "string" });+ await expect(status).toHaveText("fallback");+});