( param: Parameter, value: unknown, variables: Record<string, Variable>, channelLabels?: Record<string, string>, memoryLabels?: Record<string, string>, modelLabels?: Record<string, string>, )
| 17 | |
| 18 | /** Format a non-expression parameter value for inline display on the node. */ |
| 19 | export function formatParamDisplay( |
| 20 | param: Parameter, |
| 21 | value: unknown, |
| 22 | variables: Record<string, Variable>, |
| 23 | channelLabels?: Record<string, string>, |
| 24 | memoryLabels?: Record<string, string>, |
| 25 | modelLabels?: Record<string, string>, |
| 26 | ): ParamDisplayResult { |
| 27 | switch (param.type) { |
| 28 | case "variableSelect": { |
| 29 | const ref = value as Reference | undefined; |
| 30 | if (!ref?.varId) return { text: "" }; |
| 31 | const v = variables[refToLookupKey(ref)]; |
| 32 | return v ? { text: v.name } : { text: "unknown", isInvalid: true }; |
| 33 | } |
| 34 | case "bool": |
| 35 | return { text: (value as boolean) ? "true" : "false" }; |
| 36 | case "weekdays": { |
| 37 | const days = value as string[] | undefined; |
| 38 | return { text: !days?.length ? "every day" : days.join(", ") }; |
| 39 | } |
| 40 | case "selection": { |
| 41 | const option = param.options.find((o) => o.value === value); |
| 42 | return { text: option?.label ?? String(value ?? "") }; |
| 43 | } |
| 44 | case "memorySelect": { |
| 45 | const memoryId = value as string | undefined; |
| 46 | if (!memoryId) return { text: "" }; |
| 47 | return memoryLabels?.[memoryId] ? { text: memoryLabels[memoryId] } : { text: "unknown", isInvalid: true }; |
| 48 | } |
| 49 | case "channelSelect": { |
| 50 | const channelId = value as string | undefined; |
| 51 | if (!channelId) return { text: "" }; |
| 52 | return channelLabels?.[channelId] ? { text: channelLabels[channelId] } : { text: "unknown", isInvalid: true }; |
| 53 | } |
| 54 | case "modelSelect": { |
| 55 | // `modelLabels` covers catalog ∪ declared models, so a miss is the same |
| 56 | // staleness computeNodeDiagnostics flags — render it like every other |
| 57 | // dangling reference rather than printing a bare id. |
| 58 | const modelId = value as string | undefined; |
| 59 | if (!modelId) return { text: "" }; |
| 60 | return modelLabels?.[modelId] ? { text: modelLabels[modelId] } : { text: "unknown", isInvalid: true }; |
| 61 | } |
| 62 | default: |
| 63 | return { text: String(value ?? "") }; |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** Format an expression for display by replacing variable-reference placeholders with their names. */ |
| 68 | export function displayValue(expr: ResolvedExpr): string { |
no test coverage detected