Skip to content

Commit 35a0c4b

Browse files
committed
Update UI
Signed-off-by: Louis Mandel <[email protected]>
1 parent e46669e commit 35a0c4b

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

pdl-live-react/src/helpers.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type {
99
PdlModelInput,
1010
LocalizedExpression,
1111
} from "./pdl_ast"
12+
import { match, P } from "ts-pattern"
1213

1314
/** Re-export for convenience */
1415
export type { PdlBlock } from "./pdl_ast"
@@ -325,10 +326,23 @@ function isExpr(e: unknown): e is LocalizedExpression {
325326
)
326327
}
327328

328-
export function extractModel({ model }: ModelBlock): string {
329-
return typeof model === "string"
330-
? model
331-
: isExpr(model)
332-
? String(model.pdl__result)
333-
: "unknown"
329+
function getValue<T>(expr: ExpressionT<T>) {
330+
if (isExpr(expr)) {
331+
if (expr.pdl__result === undefined) {
332+
return expr.pdl__expr
333+
} else {
334+
return expr.pdl__result
335+
}
336+
} else {
337+
return expr
338+
}
339+
}
340+
341+
export function extractModel(block: ModelBlock): string {
342+
return match(block)
343+
.with({ model: P._ }, (block) => stringify(getValue(block.model)))
344+
.with({processor: {model: P._}}, (block) => stringify(getValue(block.processor.model)))
345+
.with({processor: {type: P._}}, (block) => stringify(getValue(block.processor.type)))
346+
.with({processor: P._}, (block) => stringify(getValue(block.processor)))
347+
.exhaustive()
334348
}

pdl-live-react/src/pdl_ast_utils.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function map_block_children(
9797
}
9898
},
9999
)
100-
.with({ kind: "model" }, (block) => {
100+
.with({ kind: "model", model: P._ }, (block) => {
101101
const model = f_expr(block.model)
102102
const input = block.input ? f_block(block.input) : undefined
103103
const parameters = block.parameters ? f_expr(block.parameters) : undefined
@@ -109,6 +109,15 @@ export function map_block_children(
109109
parameters,
110110
}
111111
})
112+
.with({ kind: "model", }, (block) => {
113+
const input = block.input ? f_block(block.input) : undefined
114+
const parameters = block.parameters ? f_expr(block.parameters) : undefined
115+
return {
116+
...block,
117+
input,
118+
parameters,
119+
}
120+
})
112121
.with({ kind: "code" }, (block) => {
113122
if (isArgs(block)) {
114123
const args = block.args.map((arg) => f_expr(arg))

0 commit comments

Comments
 (0)