From 269316887ee63f87d97bcad648ae59de9f61b04e Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 17:09:14 +0200 Subject: [PATCH] Improve config UI dump key ordering: type before config, template first in config (#29081) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: andig <184815+andig@users.noreply.github.com> --- assets/js/components/Issue/format.test.ts | 37 +++++++++++++++++++++++ assets/js/components/Issue/format.ts | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/assets/js/components/Issue/format.test.ts b/assets/js/components/Issue/format.test.ts index 70dc81d0b..bb237927f 100644 --- a/assets/js/components/Issue/format.test.ts +++ b/assets/js/components/Issue/format.test.ts @@ -56,6 +56,43 @@ describe("formatJson", () => { }`); }); + it("sorts type before config", () => { + const obj = { + name: "db:9", + config: { host: "192.168.1.1" }, + deviceProduct: "RCT Power", + type: "template", + id: 9, + }; + const result = formatJson(obj); + + expect(result).toBe(`{ + "id": 9, + "name": "db:9", + "type": "template", + "config": {"host":"192.168.1.1"}, + "deviceProduct": "RCT Power" +}`); + }); + + it("sorts template first inside config", () => { + const obj = { + other: { gamma: 3 }, + config: { cache: 37000000000, host: "192.168.1.1", template: "rct-power", usage: "pv" }, + }; + const result = formatJson(obj, ["config"]); + + expect(result).toBe(`{ + "config": { + "template": "rct-power", + "cache": 37000000000, + "host": "192.168.1.1", + "usage": "pv" + }, + "other": {"gamma":3} +}`); + }); + it("keeps nested objects in arrays single-lined with sorted keys", () => { const obj = { items: [ diff --git a/assets/js/components/Issue/format.ts b/assets/js/components/Issue/format.ts index 9024f1df1..fdf168ab3 100644 --- a/assets/js/components/Issue/format.ts +++ b/assets/js/components/Issue/format.ts @@ -1,5 +1,5 @@ function sortedEntries(obj: object): [string, any][] { - const firstKeys = ["id", "name"]; + const firstKeys = ["id", "name", "type", "template"]; return Object.entries(obj).sort(([a], [b]) => { const ai = firstKeys.indexOf(a); const bi = firstKeys.indexOf(b);