Edit JSON node settings in a dialog from a one-line preview

A free setting typed json and a declared object or array setting (a Switch
node's rules, HTTP headers) show one line of their value; clicking opens a
Monaco JSON editor in a dialog that saves only once the text parses.
Declared object settings were not shown at all before. Escape in a dialog
opened from a side panel no longer closes the panel too.
This commit is contained in:
2026-10-05 23:49:42 +02:00
parent 6fe59347e0
commit 5a145b8f59
6 changed files with 192 additions and 14 deletions
+35 -4
View File
@@ -46,6 +46,7 @@ import useCustomToast from "@/hooks/useCustomToast"
import { inCodeEditor, useShortcuts } from "@/lib/shortcuts"
import { cn } from "@/lib/utils"
import { DtypeValue } from "./FlowBoundary"
import { JsonField } from "./JsonField"
import { MessageSparkline } from "./MessageSparkline"
import {
flavorsQueryOptions,
@@ -496,9 +497,10 @@ function castTo(type: FreeType, raw: string): unknown {
if (type === "on/off") return raw === "true"
if (type === "json") {
try {
return JSON.parse(raw)
// An empty setting turned into JSON starts as an empty object.
return JSON.parse(raw || "{}")
} catch {
// Half-typed JSON is normal while editing; keep the text until it parses.
// Text that is not JSON stays text, and the type select says so.
return raw
}
}
@@ -615,6 +617,13 @@ function FreeParamsForm({
onChange({ ...params, [key]: checked })
}
/>
) : type === "json" ? (
<JsonField
value={value}
label={key}
className="flex-1"
onChange={(next) => onChange({ ...params, [key]: next })}
/>
) : (
<Input
value={asText(value)}
@@ -891,8 +900,30 @@ function ParamsForm({
)
}
if (property.type === "object" || property.type === "array") {
return null
if (
property.type === "object" ||
property.type === "array" ||
(value !== null && typeof value === "object")
) {
// An inject's per-port payloads are the fields drawn above.
if (type === "inject" && key === "payloads") return null
return (
<div key={key} className="grid gap-1.5">
<FieldLabel htmlFor={`param-${key}`} help={property.description}>
{label}
</FieldLabel>
<JsonField
id={`param-${key}`}
value={
params[key] ??
property.default ??
(property.type === "array" ? [] : {})
}
label={label}
onChange={(next) => set(key, next)}
/>
</div>
)
}
const numeric =