Skip to content

Commit 649a3f4

Browse files
committed
feat: in react ui, relegate source/raw trace to a single button
Signed-off-by: Nick Mitchell <[email protected]>
1 parent c647248 commit 649a3f4

File tree

9 files changed

+89
-123
lines changed

9 files changed

+89
-123
lines changed

pdl-live-react/src/page/Page.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import DarkModeContext, {
1616

1717
import "./Page.css"
1818

19-
const notFilled = { isFilled: false }
2019
const withPadding = { default: "padding" as const }
2120
const withoutPadding = { default: "noPadding" as const }
2221

@@ -59,8 +58,6 @@ export default function PDLPage(props: Props) {
5958
<Masthead setDarkMode={setDarkMode} />
6059
</DarkModeContext.Provider>
6160
}
62-
groupProps={notFilled /* so breadcrumbs aren't filled */}
63-
isBreadcrumbGrouped
6461
breadcrumb={
6562
<PageBreadcrumbs
6663
breadcrumb1={props.breadcrumb1}

pdl-live-react/src/page/Viewer.tsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
import { useMemo } from "react"
2-
import { useLocation } from "react-router"
32

4-
import { isView } from "../view/masonry/View"
53
import Program from "../view/masonry/MasonryTimelineCombo"
64

75
import "./Viewer.css"
86

97
/** This is the main view component */
108
export default function Viewer({ value }: { value: string }) {
11-
// We will use this to find the current active tab
12-
const { hash } = useLocation()
13-
14-
const activeTabAsSpecified = !hash || hash === "#" ? "program" : hash.slice(1)
15-
const activeTab = isView(activeTabAsSpecified)
16-
? activeTabAsSpecified
17-
: ("program" as const)
18-
199
const data = useMemo(
2010
() => (value ? (JSON.parse(value) as import("../pdl_ast").PdlBlock) : null),
2111
[value],
@@ -24,5 +14,5 @@ export default function Viewer({ value }: { value: string }) {
2414
return "Invalid trace content"
2515
}
2616

27-
return <Program block={data} view={activeTab} />
17+
return <Program block={data} />
2818
}
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
export default function BlockNotFound(props: { id: string; value: string }) {
1+
export default function BlockNotFound(props: {
2+
id: string | null
3+
value: string
4+
}) {
25
console.error("Block not found", props.id, props.value)
36
return <div>Block not found</div>
47
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import {
1111
type TabsProps,
1212
} from "@patternfly/react-core"
1313

14-
import BlockNotFound from "./BlockNotFound"
1514
import drawerContentBody from "./DrawerContentBody"
1615
import BreadcrumbBarForBlock from "../breadcrumbs/BreadcrumbBarForBlock"
1716

@@ -29,6 +28,9 @@ type Props = {
2928

3029
function header(objectType: string) {
3130
switch (objectType) {
31+
case "source":
32+
case "rawtrace":
33+
return "Code"
3234
case "def":
3335
return "Variable Definition"
3436
default:
@@ -81,21 +83,19 @@ export default function DrawerContent({ value }: Props) {
8183
[onCloseDrawer],
8284
)
8385

84-
if (!id || !objectType) {
86+
if (!objectType) {
8587
// Should never happen. TODO error handling?
8688
return <></>
8789
} else if (!value) {
8890
// Nothing to show
8991
return <></>
90-
} else if (!block) {
91-
return <BlockNotFound id={id} value={value} />
9292
}
9393

9494
return (
9595
<Card isPlain isLarge isFullHeight className="pdl-drawer-content">
9696
<CardHeader actions={actions}>
9797
<CardTitle>{header(objectType)}</CardTitle>
98-
{description(block)}
98+
{block && description(block)}
9999
</CardHeader>
100100
<CardBody>
101101
<Tabs
@@ -105,7 +105,7 @@ export default function DrawerContent({ value }: Props) {
105105
mountOnEnter
106106
unmountOnExit
107107
>
108-
{drawerContentBody({ def, objectType, model: block })}
108+
{drawerContentBody({ id, value, def, objectType, model: block })}
109109
</Tabs>
110110
</CardBody>
111111
</Card>

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

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { lazy, Suspense } from "react"
22
import { Tab, TabTitleText } from "@patternfly/react-core"
33

4+
const BlockNotFound = lazy(() => import("./BlockNotFound"))
45
const DefContent = lazy(() => import("./DefContent"))
56
const SourceTabContent = lazy(() => import("./SourceTabContent"))
67
const ContextTabContent = lazy(() => import("./ContextTabContent"))
@@ -13,6 +14,21 @@ import {
1314
type NonScalarPdlBlock as Model,
1415
} from "../../helpers"
1516

17+
function sourceBody(value: string) {
18+
return [
19+
<Tab eventKey={0} title={<TabTitleText>Source</TabTitleText>}>
20+
<Suspense>
21+
<SourceTabContent block={JSON.parse(value)} />
22+
</Suspense>
23+
</Tab>,
24+
<Tab eventKey={1} title={<TabTitleText>Raw Trace</TabTitleText>}>
25+
<Suspense>
26+
<RawTraceTabContent block={JSON.parse(value)} />
27+
</Suspense>
28+
</Tab>,
29+
]
30+
}
31+
1632
function defBody(_def: string | null, block: Model) {
1733
const value = hasResult(block) ? block.result : undefined
1834
return (
@@ -57,16 +73,42 @@ function blockBody(block: Model) {
5773
}
5874

5975
type Props = {
76+
id: string | null
77+
value: string
6078
def: string | null
6179
objectType: string
62-
model: Model
80+
model: Model | null
6381
}
6482

65-
export default function DrawerContentBody({ def, objectType, model }: Props) {
83+
export default function DrawerContentBody({
84+
id,
85+
value,
86+
def,
87+
objectType,
88+
model,
89+
}: Props) {
6690
switch (objectType) {
91+
case "source":
92+
case "rawtrace":
93+
return sourceBody(value)
6794
case "def":
95+
if (!model) {
96+
return (
97+
<Suspense>
98+
<BlockNotFound id={id} value={value} />
99+
</Suspense>
100+
)
101+
}
68102
return defBody(def, model)
69103
default:
104+
if (!model) {
105+
return (
106+
<Suspense>
107+
<BlockNotFound id={id} value={value} />
108+
</Suspense>
109+
)
110+
}
111+
70112
return blockBody(model)
71113
}
72114
}

pdl-live-react/src/view/masonry/MasonryTimelineCombo.tsx

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
1-
import { useNavigate, useSearchParams } from "react-router"
2-
import {
3-
useCallback,
4-
useEffect,
5-
useMemo,
6-
useState,
7-
lazy,
8-
Suspense,
9-
} from "react"
1+
import { useEffect, useMemo, useState } from "react"
102
import { PageSection } from "@patternfly/react-core"
113

124
import Timeline from "../timeline/TimelineFromModel"
13-
const Code = lazy(() => import("../code/Code"))
145

156
import Masonry from "./Masonry"
167
import computeModel from "./model"
17-
import Toolbar, { type As, type SML, type View } from "./Toolbar"
8+
import Toolbar, { type As, type SML } from "./Toolbar"
189

1910
import "./Masonry.css"
2011

2112
type Props = {
22-
view: View
2313
block: import("../../pdl_ast").PdlBlock
2414
}
2515

@@ -39,23 +29,13 @@ function setSMLUserSetting(sml: SML) {
3929
localStorage.setItem(smlLocalStorageKey, sml)
4030
}
4131

42-
export default function MasonryTimelineCombo({ block, view }: Props) {
32+
export default function MasonryTimelineCombo({ block }: Props) {
4333
const [as, setAs] = useState<As>(getAsUserSetting())
4434
const [sml, setSML] = useState<SML>(getSMLUserSetting())
4535

4636
useEffect(() => setAsUserSetting(as), [as])
4737
useEffect(() => setSMLUserSetting(sml), [sml])
4838

49-
const [searchParams] = useSearchParams()
50-
const s = searchParams.toString().length === 0 ? "" : "?" + searchParams
51-
const navigate = useNavigate()
52-
const setView = useCallback(
53-
(view: View) => {
54-
navigate(s + "#" + view)
55-
},
56-
[navigate, s],
57-
)
58-
5939
const { base, masonry, numbering } = useMemo(
6040
() => computeModel(block),
6141
[block],
@@ -64,30 +44,17 @@ export default function MasonryTimelineCombo({ block, view }: Props) {
6444
return (
6545
<>
6646
<PageSection type="subnav">
67-
<Toolbar
68-
as={as}
69-
setAs={setAs}
70-
sml={sml}
71-
setSML={setSML}
72-
view={view}
73-
setView={setView}
74-
/>
47+
<Toolbar as={as} setAs={setAs} sml={sml} setSML={setSML} />
7548
</PageSection>
7649
<PageSection
7750
isFilled
7851
hasOverflowScroll
7952
className="pdl-content-section"
8053
aria-label="PDL Viewer main section"
8154
>
82-
{view === "program" ? (
83-
<Masonry model={masonry} as={as} sml={sml}>
84-
<Timeline model={base} numbering={numbering} />
85-
</Masonry>
86-
) : (
87-
<Suspense>
88-
<Code block={block} limitHeight={false} raw={view === "rawtrace"} />
89-
</Suspense>
90-
)}
55+
<Masonry model={masonry} as={as} sml={sml}>
56+
<Timeline model={base} numbering={numbering} />
57+
</Masonry>
9158
</PageSection>
9259
</>
9360
)

pdl-live-react/src/view/masonry/Toolbar.tsx

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,7 @@ import {
77

88
import ToolbarAsToggle from "./ToolbarAsToggle"
99
import ToolbarSMLToggle from "./ToolbarSMLToggle"
10-
import ToolbarViewToggle from "./ToolbarViewToggle"
11-
12-
import { type View } from "./View"
13-
export { type View }
10+
import ToolbarShowSourceButton from "./ToolbarShowSourceButton"
1411

1512
const alignEnd = { default: "alignEnd" as const }
1613

@@ -23,31 +20,20 @@ export type Props = {
2320

2421
sml: SML
2522
setSML(sml: SML): void
26-
27-
view: View
28-
setView(view: View): void
2923
}
3024

31-
export default function MasonryToolbar({
32-
as,
33-
setAs,
34-
sml,
35-
setSML,
36-
view,
37-
setView,
38-
}: Props) {
25+
export default function MasonryToolbar({ as, setAs, sml, setSML }: Props) {
3926
return (
4027
<Toolbar className="pdl-masonry-toolbar">
4128
<ToolbarContent>
42-
<ToolbarGroup>
29+
<ToolbarGroup align={alignEnd} variant="action-group">
4330
<ToolbarItem>
44-
<ToolbarViewToggle view={view} setView={setView} />
31+
<ToolbarShowSourceButton />
4532
</ToolbarItem>
46-
</ToolbarGroup>
47-
48-
<ToolbarGroup variant="action-group-plain" align={alignEnd}>
4933
<ToolbarItem>
5034
<ToolbarSMLToggle sml={sml} setSML={setSML} />
35+
</ToolbarItem>
36+
<ToolbarItem>
5137
<ToolbarAsToggle as={as} setAs={setAs} />
5238
</ToolbarItem>
5339
</ToolbarGroup>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { useCallback } from "react"
2+
import { useLocation, useNavigate } from "react-router"
3+
4+
import { Button, Tooltip } from "@patternfly/react-core"
5+
6+
import CodeIcon from "@patternfly/react-icons/dist/esm/icons/code-icon"
7+
8+
export default function ToolbarProgramOrSourceToggle() {
9+
const { hash } = useLocation()
10+
const navigate = useNavigate()
11+
12+
const handleClickSource = useCallback(() => {
13+
navigate("?detail&type=source" + hash)
14+
}, [hash, navigate])
15+
16+
return (
17+
<Tooltip content="Show program source">
18+
<Button size="sm" icon={<CodeIcon />} onClick={handleClickSource} />
19+
</Tooltip>
20+
)
21+
}

pdl-live-react/src/view/masonry/ToolbarViewToggle.tsx

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)