Skip to content

Commit

Permalink
fix: improvements for rendering of Array and Function blocks
Browse files Browse the repository at this point in the history
This also fixes a few other small rendering issues.

Signed-off-by: Nick Mitchell <[email protected]>
  • Loading branch information
starpit committed Jan 24, 2025
1 parent 11f94fc commit 47d6fd3
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 60 deletions.
5 changes: 5 additions & 0 deletions pdl-live-react/src/view/breadcrumbs/BreadcrumbBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
--pdl-block-color-1: #fce3e3;
--pdl-block-color-2: var(--pf-t--global--color--nonstatus--red--default);
}
&[data-detail="lastOf"],
&[data-detail="text"],
&[data-detail="array"] {
--pdl-bb-color: var(--pf-t--global--icon--color--disabled);
}

--pdl-bb-color: var(--pdl-block-color-1);
&.pdl-breadcrumb-bar-item--def {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function BreadcrumbBarForBlock({ id, block }: Props) {
.map((part, idx, A) => (
<BreadcrumbBarItem
key={part + idx}
detail={part}
className={
idx === A.length - 1 ? "pdl-breadcrumb-bar-item--kind" : ""
}
Expand Down
22 changes: 2 additions & 20 deletions pdl-live-react/src/view/detail/BlockNotFound.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
import type Model from "../timeline/model"

export default function BlockNotFound({
id,
model,
}: {
id: string
model: Model
}) {
return (
<>
<div>
Block not found{" "}
<strong>
<pre>{id}</pre>
</strong>
</div>
<div className="pdl-wrap">
<code>{model.map((_) => _.id).join(", ")}</code>
</div>
</>
)
export default function BlockNotFound(_props: { id: string; model: Model }) {
return <div>Block not found</div>
}
4 changes: 3 additions & 1 deletion pdl-live-react/src/view/detail/SummaryTabContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import CodeItems from "./kind/Code"
import DataItems from "./kind/Data"
import ReadItems from "./kind/Read"
import ModelItems from "./kind/Model"
import FunctionItems from "./kind/Function"

import type Model from "../timeline/model"

Expand All @@ -21,7 +22,8 @@ function descriptionItems(block: import("../../helpers").NonScalarPdlBlock) {
.with({ kind: "call" }, (block) => <CallItems block={block} />)
.with({ kind: "code" }, (block) => <CodeItems block={block} />)
.with({ kind: "data" }, (block) => <DataItems block={block} />)
.with({ kind: "model" }, (block) => <ModelItems block={block} />)
.with({ kind: "read" }, (block) => <ReadItems block={block} />)
.with({ kind: "model" }, (block) => <ModelItems block={block} />)
.with({ kind: "function" }, (block) => <FunctionItems block={block} />)
.otherwise(() => <>This is a {block.kind} block</>)
}
18 changes: 18 additions & 0 deletions pdl-live-react/src/view/detail/kind/Function.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { stringify } from "yaml"

import Group from "../Group"
import CodeGroup from "../../transcript/CodeGroup"

export default function FunctionItems({
block: { def, function: func, return: retrn },
}: {
block: import("../../../pdl_ast").FunctionBlock
}) {
return (
<>
{def && <Group description={def} term="Name" />}
<CodeGroup code={stringify(func)} term="Parameters" />
<CodeGroup code={stringify(retrn)} term="Body" />
</>
)
}
13 changes: 3 additions & 10 deletions pdl-live-react/src/view/transcript/Array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,7 @@ type Props = {
}

export default function Array({ array, ctx }: Props) {
return (
<>
<pre>{"["}</pre>
{array.flatMap((block, idx) => [
<Block key={idx} data={block} ctx={withIter(ctx, idx)} />,
idx < array.length - 1 && <pre>,</pre>,
])}
<pre>{"]"}</pre>
</>
)
return array.map((block, idx) => [
<Block key={idx} data={block} ctx={withIter(ctx, idx)} />,
])
}
14 changes: 5 additions & 9 deletions pdl-live-react/src/view/transcript/Block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ import { type DescriptionListProps } from "@patternfly/react-core"

import ArrayUI from "./Array"
import Defs from "./Defs"
import Function from "./Function"
import LastOf from "./LastOf"
import ObjectUI from "./Object"
import Output from "./Output"
import Query from "./Query"
import ResultOrCode from "./ResultOrCode"
import Text from "./Text"
import TranscriptItem from "./TranscriptItem"

import LoopTrace from "./LoopTrace"
Expand Down Expand Up @@ -99,27 +97,25 @@ export default function Block({ data, ctx }: Props): ReactNode {
<ResultOrCode block={data} />
),
}))
.with({ kind: "function" }, (data) => ({
.with({ kind: "function" }, () => ({
C: ["pdl_function"],
B: <Function f={data} ctx={withParent(ctx, data.kind)} />,
B: <></>,
}))
.with({ kind: "call" }, () => ({
C: ["pdl_call"],
B: <></>,
}))
.with({ kind: "text" }, (data) => ({
.with({ kind: "text" }, () => ({
C: ["pdl_text"],
B: data.text && (
<Text blocks={data.text} ctx={withParent(ctx, data.kind)} />
),
B: <></>,
}))
.with({ kind: "lastOf" }, (data) => ({
C: ["pdl_lastOf"],
S: <LastOf blocks={data.lastOf} ctx={withParent(ctx, data.kind)} />,
}))
.with({ kind: "array" }, (data) => ({
C: ["pdl_array"],
B: <ArrayUI array={data.array} ctx={withParent(ctx, data.kind)} />,
S: <ArrayUI array={data.array} ctx={withParent(ctx, data.kind)} />,
}))
.with({ kind: "object" }, (data) => ({
C: ["pdl_object"],
Expand Down
19 changes: 0 additions & 19 deletions pdl-live-react/src/view/transcript/Function.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion pdl-live-react/src/view/transcript/QAV.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.pdl-qav {
display: flex;
align-items: center;
align-items: baseline;
}

.pdl-qav-label {
Expand Down

0 comments on commit 47d6fd3

Please sign in to comment.