Skip to content

Commit bcf915e

Browse files
authored
Control info dialogs from URL (#201)
* Control info dialogs from URL * Tweak redirect from /
1 parent 63f8852 commit bcf915e

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

ui/src/app.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@ export const App = () => {
2525
<main className={styles.main}>
2626
<div className={styles.content}>
2727
<Routes>
28-
<Route path="/" element={<Navigate to="/overview" />} />
28+
<Route
29+
path="/"
30+
element={
31+
<Navigate
32+
to={{
33+
pathname: '/overview',
34+
search: location.search,
35+
}}
36+
replace={true}
37+
/>
38+
}
39+
/>
2940
<Route path="/overview" element={<Overview />} />
3041
<Route path="/jobs/:id?" element={<Jobs />} />
3142
<Route path="/deployments/:id?" element={<Deployments />} />

ui/src/components/info-dialog/info-dialog.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@ import { Button, ButtonTheme } from 'design-system/components/button/button'
33
import * as Dialog from 'design-system/components/dialog/dialog'
44
import { STRING, translate } from 'utils/language'
55
import styles from './info-dialog.module.scss'
6+
import { useActivePage } from './useActivePage'
67

78
export const InfoDialog = ({ name, slug }: { name: string; slug: string }) => {
9+
const { activePage, setActivePage } = useActivePage()
810
const { page, isLoading } = usePageDetails(slug)
911

1012
return (
11-
<Dialog.Root>
13+
<Dialog.Root
14+
open={activePage === slug}
15+
onOpenChange={(open) => setActivePage(open ? slug : undefined)}
16+
>
1217
<Dialog.Trigger>
1318
<Button label={name} theme={ButtonTheme.Plain} />
1419
</Dialog.Trigger>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { useSearchParams } from 'react-router-dom'
2+
3+
const SEARCH_PARAM_KEY = 'page'
4+
5+
export const useActivePage = () => {
6+
const [searchParams, setSearchParams] = useSearchParams()
7+
8+
const activePage = searchParams.get(SEARCH_PARAM_KEY) ?? undefined
9+
10+
const setActivePage = (pageSlug?: string) => {
11+
searchParams.delete(SEARCH_PARAM_KEY)
12+
if (pageSlug?.length) {
13+
searchParams.set(SEARCH_PARAM_KEY, pageSlug)
14+
}
15+
setSearchParams(searchParams)
16+
}
17+
18+
return { activePage, setActivePage }
19+
}

0 commit comments

Comments
 (0)