Skip to content

Commit 957ab2b

Browse files
committed
fix: in ui, Context tab can show raw json strings
This also adds placeholder text for context messages with no defsite. Signed-off-by: Nick Mitchell <[email protected]>
1 parent 55056fb commit 957ab2b

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

pdl-live-react/src/view/Markdown.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.pf-v6-c-panel__main > .pdl-markdown {
1+
.pdl-masonry-tile .pf-v6-c-panel__main > .pdl-markdown {
22
padding: 1em;
33
}
44

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

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1+
import Code from "./code/Code"
12
import Markdown from "./Markdown"
23

34
type Props = { children: number | string | unknown }
45

6+
function isJson(s: string) {
7+
try {
8+
JSON.parse(s)
9+
return true
10+
} catch (_err) {
11+
return false
12+
}
13+
}
14+
515
export default function Value({ children: s }: Props) {
6-
return (
7-
<>
8-
{typeof s === "number" ? (
9-
s
10-
) : typeof s === "string" ? (
11-
<Markdown>{s === "\n" ? "*<newline>*" : s.trim()}</Markdown>
12-
) : (
13-
JSON.stringify(s, undefined, 2)
14-
)}
15-
</>
16+
return typeof s === "number" ? (
17+
s
18+
) : typeof s === "string" ? (
19+
isJson(s) ? (
20+
<Code block={s} language="json" />
21+
) : (
22+
<Markdown>{s === "\n" ? "*<newline>*" : s.trim()}</Markdown>
23+
)
24+
) : (
25+
JSON.stringify(s, undefined, 2)
1626
)
1727
}

pdl-live-react/src/view/detail/ContextTabContent.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
DescriptionListGroup,
55
DescriptionListDescription,
66
Divider,
7+
Panel,
8+
PanelMain,
79
} from "@patternfly/react-core"
810

911
import Result from "../Result"
@@ -22,7 +24,11 @@ export default function ContextTabContent({ block }: Props) {
2224
{c.role[0].toUpperCase() + c.role.slice(1)}
2325
</DescriptionListTerm>
2426
<DescriptionListDescription>
25-
<Result result={c.content} term="" />
27+
<Panel isScrollable>
28+
<PanelMain>
29+
<Result result={c.content} term="" />
30+
</PanelMain>
31+
</Panel>
2632
</DescriptionListDescription>
2733
</DescriptionListGroup>,
2834

@@ -31,7 +37,11 @@ export default function ContextTabContent({ block }: Props) {
3137
Where was this value defined?
3238
</DescriptionListTerm>
3339
<DescriptionListDescription>
34-
{c.defsite && <BreadcrumbBarForBlockId id={c.defsite} />}
40+
{c.defsite ? (
41+
<BreadcrumbBarForBlockId id={c.defsite} />
42+
) : (
43+
"The origin of this data is not known"
44+
)}
3545
</DescriptionListDescription>
3646
</DescriptionListGroup>,
3747

0 commit comments

Comments
 (0)