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:
parent
c7e3e486b9
commit
269316887e
2 changed files with 38 additions and 1 deletions
|
|
@ -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: [
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue