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>
This commit is contained in:
Copilot 2026-04-13 17:09:14 +02:00 • committed by GitHub
parent c7e3e486b9
commit 269316887e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 38 additions and 1 deletions

View file

@ -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: [

View file

@ -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);