Skip to content

Commit 2de5cfc

Browse files
committed
fix: ui shows numerical results using syntax highlighter
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 0603c7a commit 2de5cfc

File tree

4 files changed

+15
-6
lines changed

4 files changed

+15
-6
lines changed

pdl-live-react/src/view/Result.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ export default function Result({
2424
term = "Result",
2525
limitHeight = false,
2626
}: Props) {
27-
const isCode = !!lang && lang !== "plaintext" && !!result
27+
const isCode =
28+
!!lang &&
29+
lang !== "plaintext" &&
30+
!!result &&
31+
typeof result !== "number" &&
32+
typeof result !== "boolean"
2833

2934
const innerContent = isCode ? (
3035
<Code block={result} language={lang} />

pdl-live-react/src/view/Value.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import Code from "./code/Code"
22
import Markdown from "./Markdown"
33

4-
type Props = { children: number | string | unknown }
4+
type Props = { children: boolean | number | string | unknown }
55

66
function isJson(s: string) {
77
try {
@@ -14,7 +14,7 @@ function isJson(s: string) {
1414

1515
export default function Value({ children: s }: Props) {
1616
return typeof s === "number" ? (
17-
s
17+
<div className="pdl-markdown">{s}</div>
1818
) : typeof s === "string" ? (
1919
isJson(s) ? (
2020
<Code block={s} language="json" />

pdl-live-react/src/view/masonry/Tile.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ type Tile = {
99
timezone?: string
1010

1111
lang?: import("../code/Code").SupportedLanguage
12-
content: string
12+
content: string | number | boolean
1313

1414
footer1Key?: string
1515
footer1Value?: string | number | boolean

pdl-live-react/src/view/masonry/model.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ export default function computeModel(block: import("../../pdl_ast").PdlBlock) {
5454
resultForDisplay:
5555
typeof block.pdl__result === "object"
5656
? stringify(block.pdl__result)
57-
: String(block.pdl__result),
57+
: typeof block.pdl__result === "string" ||
58+
typeof block.pdl__result === "number" ||
59+
typeof block.pdl__result === "boolean"
60+
? block.pdl__result
61+
: String(block.pdl__result),
5862
meta: undefined,
5963
lang:
6064
typeof block.pdl__result === "object"
@@ -153,7 +157,7 @@ function withDefs(block: NonScalarPdlBlock, tiles: Tile[]) {
153157
? "json"
154158
: (v.parser as Tile["lang"])
155159
: undefined,
156-
content: hasScalarResult(v) ? String(v.pdl__result) : "",
160+
content: hasScalarResult(v) ? v.pdl__result : "",
157161
},
158162
)),
159163
...tiles,

0 commit comments

Comments
 (0)