Skip to content

Commit 48f3bca

Browse files
authored
Add picker to Sled page topbar (#2493)
1 parent 352c802 commit 48f3bca

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

app/components/TopBarPicker.tsx

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
useInstanceSelector,
2020
useIpPoolSelector,
2121
useSiloSelector,
22+
useSledParams,
2223
useVpcRouterSelector,
2324
useVpcSelector,
2425
} from '~/hooks/use-params'
@@ -343,3 +344,25 @@ export function InstancePicker() {
343344
/>
344345
)
345346
}
347+
348+
export function SledPicker() {
349+
// picker only shows up when a sled is in scope
350+
const { sledId } = useSledParams()
351+
const { data: sleds } = useApiQuery('sledList', {
352+
query: { limit: PAGE_SIZE },
353+
})
354+
const items = (sleds?.items || []).map(({ id }) => ({
355+
label: id,
356+
to: pb.sled({ sledId: id }),
357+
}))
358+
return (
359+
<TopBarPicker
360+
aria-label="Switch sled"
361+
category="Sled"
362+
current={sledId}
363+
to={pb.sled({ sledId })}
364+
items={items}
365+
noItemsText="No sleds found"
366+
/>
367+
)
368+
}

app/layouts/SystemLayout.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ import {
1919
import { trigger404 } from '~/components/ErrorBoundary'
2020
import { DocsLinkItem, NavLinkItem, Sidebar } from '~/components/Sidebar'
2121
import { TopBar } from '~/components/TopBar'
22-
import { IpPoolPicker, SiloPicker, SiloSystemPicker } from '~/components/TopBarPicker'
22+
import {
23+
IpPoolPicker,
24+
SiloPicker,
25+
SiloSystemPicker,
26+
SledPicker,
27+
} from '~/components/TopBarPicker'
2328
import { useQuickActions } from '~/hooks/use-quick-actions'
2429
import { Divider } from '~/ui/lib/Divider'
2530
import { pb } from '~/util/path-builder'
@@ -55,7 +60,7 @@ export function SystemLayout() {
5560
// robust way of doing this would be to make a separate layout for the
5661
// silo-specific routes in the route config, but it's overkill considering
5762
// this is a one-liner. Switch to that approach at the first sign of trouble.
58-
const { silo, pool } = useParams()
63+
const { silo, pool, sledId } = useParams()
5964
const navigate = useNavigate()
6065
const { pathname } = useLocation()
6166

@@ -92,6 +97,7 @@ export function SystemLayout() {
9297
<SiloSystemPicker value="system" />
9398
{silo && <SiloPicker />}
9499
{pool && <IpPoolPicker />}
100+
{sledId && <SledPicker />}
95101
</TopBar>
96102
<Sidebar>
97103
<Sidebar.Nav>

0 commit comments

Comments
 (0)