Skip to content

Commit eb58585

Browse files
committed
fix: in react ui, clicking on demo from welcome page closes sidebar
Signed-off-by: Nick Mitchell <[email protected]>
1 parent 3ca9c93 commit eb58585

File tree

4 files changed

+50
-12
lines changed

4 files changed

+50
-12
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Link } from "react-router"
21
import { Button, Panel, PanelMain } from "@patternfly/react-core"
2+
import { Link, useLocation, useSearchParams } from "react-router"
33

44
import Tile from "./welcome/Tile"
55
import Result from "../view/Result"
@@ -11,7 +11,11 @@ import { hasResult } from "../helpers"
1111

1212
import DemoIcon from "@patternfly/react-icons/dist/esm/icons/sun-icon"
1313

14-
function demoTiles() {
14+
function DemoTiles() {
15+
const { hash } = useLocation()
16+
const [searchParams] = useSearchParams()
17+
const s = searchParams.toString()
18+
1519
return demos.map((demo) => {
1620
// TODO useMemo()
1721
const data = JSON.parse(demo.trace)
@@ -33,7 +37,14 @@ function demoTiles() {
3337
}
3438
>
3539
<Button isInline variant="link">
36-
<Link to={"/demos/" + encodeURIComponent(demo.name)}>
40+
<Link
41+
to={
42+
"/demos/" +
43+
encodeURIComponent(demo.name) +
44+
(s ? `?${s}` : "") +
45+
hash
46+
}
47+
>
3748
Show this Demo
3849
</Link>
3950
</Button>
@@ -47,7 +58,7 @@ export default function Demos() {
4758
<Welcome
4859
breadcrumb1="Demos"
4960
intro="Here are some built-in PDL demos"
50-
tiles={demoTiles()}
61+
tiles={<DemoTiles />}
5162
/>
5263
)
5364
}

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Link } from "react-router"
21
import { Button, Panel, PanelMain } from "@patternfly/react-core"
2+
import { Link, useLocation, useSearchParams } from "react-router"
33

44
import Tile from "./welcome/Tile"
55
import Result from "../view/Result"
@@ -11,7 +11,11 @@ import { nonNullable } from "../helpers"
1111

1212
import MyIcon from "@patternfly/react-icons/dist/esm/icons/user-icon"
1313

14-
function myTiles() {
14+
function MyTiles() {
15+
const { hash } = useLocation()
16+
const [searchParams] = useSearchParams()
17+
const s = searchParams.toString()
18+
1519
return getMyTraces()
1620
.map(({ title, filename, value }) => {
1721
try {
@@ -35,7 +39,11 @@ function myTiles() {
3539
}
3640
>
3741
<Button isInline variant="link">
38-
<Link to={"/my/" + encodeURIComponent(title)}>
42+
<Link
43+
to={
44+
"/my/" + encodeURIComponent(title) + (s ? `?${s}` : "") + hash
45+
}
46+
>
3947
Show this Trace
4048
</Link>
4149
</Button>
@@ -53,7 +61,7 @@ export default function MyTraces() {
5361
<Welcome
5462
breadcrumb1="My Traces"
5563
intro="Here are your recently uploaded traces"
56-
tiles={myTiles()}
64+
tiles={<MyTiles />}
5765
/>
5866
)
5967
}

pdl-live-react/src/page/welcome/tiles/Demos.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { Link } from "react-router"
21
import { Button } from "@patternfly/react-core"
2+
import { Link, useLocation, useSearchParams } from "react-router"
33

44
import Tile from "../Tile"
55
import demos from "../../../demos/demos"
66

77
import DemoIcon from "@patternfly/react-icons/dist/esm/icons/sun-icon"
88

99
export default function Demos() {
10+
const { hash } = useLocation()
11+
const [searchParams] = useSearchParams()
12+
const s = searchParams.toString()
13+
1014
return (
1115
<Tile
1216
title="View a Demo"
@@ -15,7 +19,14 @@ export default function Demos() {
1519
>
1620
{demos.map((demo) => (
1721
<Button key={demo.name} isInline variant="link">
18-
<Link to={"/demos/" + encodeURIComponent(demo.name)}>
22+
<Link
23+
to={
24+
"/demos/" +
25+
encodeURIComponent(demo.name) +
26+
(s ? `?${s}` : "") +
27+
hash
28+
}
29+
>
1930
{demo.name}
2031
</Link>
2132
</Button>

pdl-live-react/src/page/welcome/tiles/MyTraces.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
import { Link } from "react-router"
21
import { Button } from "@patternfly/react-core"
2+
import { Link, useLocation, useSearchParams } from "react-router"
33

44
import Tile from "../Tile"
55
import { getMyTraces } from "../../MyTraces"
66

77
import MyIcon from "@patternfly/react-icons/dist/esm/icons/user-icon"
88

99
export default function MyTraces() {
10+
const { hash } = useLocation()
11+
const [searchParams] = useSearchParams()
12+
const s = searchParams.toString()
13+
1014
const myTraces = getMyTraces()
1115

1216
return (
@@ -17,7 +21,11 @@ export default function MyTraces() {
1721
>
1822
{myTraces.map(({ title, filename }) => (
1923
<Button key={filename} isInline variant="link">
20-
<Link to={"/my/" + encodeURIComponent(title)}>{title}</Link>
24+
<Link
25+
to={"/my/" + encodeURIComponent(title) + (s ? `?${s}` : "") + hash}
26+
>
27+
{title}
28+
</Link>
2129
</Button>
2230
))}
2331
</Tile>

0 commit comments

Comments
 (0)