Skip to content

Commit

Permalink
Control info dialogs from URL (#201)
Browse files Browse the repository at this point in the history
* Control info dialogs from URL

* Tweak redirect from /
  • Loading branch information
annavik authored Aug 10, 2023
1 parent 63f8852 commit bcf915e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
13 changes: 12 additions & 1 deletion ui/src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ export const App = () => {
<main className={styles.main}>
<div className={styles.content}>
<Routes>
<Route path="/" element={<Navigate to="/overview" />} />
<Route
path="/"
element={
<Navigate
to={{
pathname: '/overview',
search: location.search,
}}
replace={true}
/>
}
/>
<Route path="/overview" element={<Overview />} />
<Route path="/jobs/:id?" element={<Jobs />} />
<Route path="/deployments/:id?" element={<Deployments />} />
Expand Down
7 changes: 6 additions & 1 deletion ui/src/components/info-dialog/info-dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import { Button, ButtonTheme } from 'design-system/components/button/button'
import * as Dialog from 'design-system/components/dialog/dialog'
import { STRING, translate } from 'utils/language'
import styles from './info-dialog.module.scss'
import { useActivePage } from './useActivePage'

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

return (
<Dialog.Root>
<Dialog.Root
open={activePage === slug}
onOpenChange={(open) => setActivePage(open ? slug : undefined)}
>
<Dialog.Trigger>
<Button label={name} theme={ButtonTheme.Plain} />
</Dialog.Trigger>
Expand Down
19 changes: 19 additions & 0 deletions ui/src/components/info-dialog/useActivePage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { useSearchParams } from 'react-router-dom'

const SEARCH_PARAM_KEY = 'page'

export const useActivePage = () => {
const [searchParams, setSearchParams] = useSearchParams()

const activePage = searchParams.get(SEARCH_PARAM_KEY) ?? undefined

const setActivePage = (pageSlug?: string) => {
searchParams.delete(SEARCH_PARAM_KEY)
if (pageSlug?.length) {
searchParams.set(SEARCH_PARAM_KEY, pageSlug)
}
setSearchParams(searchParams)
}

return { activePage, setActivePage }
}

0 comments on commit bcf915e

Please sign in to comment.