Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: pdl-live-react improve ui of top-level q&a #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions pdl-live-react/src/view/transcript/PrettyKind.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,16 @@ export default function PrettyKind({
typeof block.input === "string" &&
block.input.length > 0 && (
<>
<QAV q="Q">{block.input}</QAV>
<QAV q="Q" kind="dialog">
{block.input}
</QAV>
</>
)}
{hasScalarResult(block) && <QAV q="A">{block.result}</QAV>}
{hasScalarResult(block) && (
<QAV q="A" kind="dialog">
{block.result}
</QAV>
)}
</>
)
case "function":
Expand Down Expand Up @@ -76,12 +82,26 @@ export default function PrettyKind({
case "error":
return `${firstLineOf(block.msg)}`
case "code":
return <>{hasScalarResult(block) && <QAV q="A">{block.result}</QAV>}</>
return (
<>
{hasScalarResult(block) && (
<QAV q="A" kind="code">
{block.result}
</QAV>
)}
</>
)
case "read":
return (
<>
<QAV q="Q">{block.message ?? "Prompt user for input"}</QAV>
{hasScalarResult(block) && <QAV q="A">{block.result}</QAV>}
<QAV q="Q" kind="dialog">
{block.message ?? "Prompt user for input"}
</QAV>
{hasScalarResult(block) && (
<QAV q="A" kind="dialog">
{block.result}
</QAV>
)}
</>
)
case "if":
Expand Down
2 changes: 1 addition & 1 deletion pdl-live-react/src/view/transcript/QAV.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
.pdl-qav-label {
font-weight: bold;
font-size: 0.75em;
padding-right: 0.5em;
padding-right: 0.375em;
}
30 changes: 25 additions & 5 deletions pdl-live-react/src/view/transcript/QAV.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,51 @@ import { Tooltip, Truncate } from "@patternfly/react-core"

import { firstLineOf } from "../../helpers"

import ChevronLeftIcon from "@patternfly/react-icons/dist/esm/icons/chevron-left-icon"
import ChevronRightIcon from "@patternfly/react-icons/dist/esm/icons/chevron-right-icon"

import "./QAV.css"

type Props = {
kind?: "code" | "dialog"
q: "Q" | "A" | "V"
children: import("react").ReactNode
}

/** Render the Q: A: V: UI */
export default function QAV({ q, children }: Props) {
export default function QAV({ q, kind, children }: Props) {
const tip =
q === "Q"
? "Question posed"
? kind === "dialog"
? "Question posed"
: "Code executed"
: q === "A"
? "The result"
? kind === "dialog"
? "The answer"
: "The execution result"
: "Result is assigned to this variable"

const content = <Truncate content={firstLineOf(String(children))} />

return (
<div className="pdl-qav">
<Tooltip content={tip}>
<span className="pdl-qav-label">{q}</span>
<span className="pdl-qav-label">
{q === "Q" ? (
<ChevronRightIcon />
) : q === "A" ? (
<ChevronLeftIcon />
) : (
<></>
)}
</span>
</Tooltip>{" "}
{isValidElement(children) ? (
children
) : kind === "dialog" ? (
<i>{content}</i>
) : (
<Truncate content={firstLineOf(String(children))} />
<code>{content}</code>
)}
</div>
)
Expand Down
Loading