|
8 | 8 | import cn from 'classnames' |
9 | 9 | import { Link } from 'react-router-dom' |
10 | 10 |
|
11 | | -import { useApiQuery, type Project } from '@oxide/api' |
12 | | -import { |
13 | | - Folder16Icon, |
14 | | - SelectArrows6Icon, |
15 | | - Success12Icon, |
16 | | -} from '@oxide/design-system/icons/react' |
| 11 | +import { SelectArrows6Icon, Success12Icon } from '@oxide/design-system/icons/react' |
17 | 12 |
|
18 | | -import { |
19 | | - useInstanceSelector, |
20 | | - useIpPoolSelector, |
21 | | - useSiloSelector, |
22 | | - useSledParams, |
23 | | - useVpcRouterSelector, |
24 | | - useVpcSelector, |
25 | | -} from '~/hooks/use-params' |
26 | 13 | import { useCurrentUser } from '~/layouts/AuthenticatedLayout' |
27 | | -import { PAGE_SIZE } from '~/table/QueryTable' |
28 | 14 | import { buttonStyle } from '~/ui/lib/Button' |
29 | 15 | import * as DropdownMenu from '~/ui/lib/DropdownMenu' |
30 | 16 | import { Identicon } from '~/ui/lib/Identicon' |
@@ -124,10 +110,10 @@ const TopBarPicker = (props: TopBarPickerProps) => { |
124 | 110 | to={to} |
125 | 111 | className={cn({ 'is-selected': isSelected })} |
126 | 112 | > |
127 | | - <span className="flex w-full items-center gap-2"> |
128 | | - {label} |
| 113 | + <div className="flex w-full items-center gap-2"> |
| 114 | + <div className="flex-grow">{label}</div> |
129 | 115 | {isSelected && <Success12Icon className="-mr-3 block" />} |
130 | | - </span> |
| 116 | + </div> |
131 | 117 | </DropdownMenu.LinkItem> |
132 | 118 | ) |
133 | 119 | }) |
@@ -207,162 +193,3 @@ export function SiloSystemPicker({ value }: { value: 'silo' | 'system' }) { |
207 | 193 | /> |
208 | 194 | ) |
209 | 195 | } |
210 | | - |
211 | | -/** Used when drilling down into a silo from the System view. */ |
212 | | -export function SiloPicker() { |
213 | | - // picker only shows up when a silo is in scope |
214 | | - const { silo: siloName } = useSiloSelector() |
215 | | - const { data } = useApiQuery('siloList', { query: { limit: PAGE_SIZE } }) |
216 | | - const items = (data?.items || []).map((silo) => ({ |
217 | | - label: silo.name, |
218 | | - to: pb.silo({ silo: silo.name }), |
219 | | - })) |
220 | | - |
221 | | - return ( |
222 | | - <TopBarPicker |
223 | | - aria-label="Switch silo" |
224 | | - category="Silo" |
225 | | - icon={<BigIdenticon name={siloName} />} |
226 | | - current={siloName} |
227 | | - items={items} |
228 | | - noItemsText="No silos found" |
229 | | - /> |
230 | | - ) |
231 | | -} |
232 | | - |
233 | | -/** Used when drilling down into a pool from the System/Networking view. */ |
234 | | -export function IpPoolPicker() { |
235 | | - // picker only shows up when a pool is in scope |
236 | | - const { pool: poolName } = useIpPoolSelector() |
237 | | - const { data } = useApiQuery('ipPoolList', { query: { limit: PAGE_SIZE } }) |
238 | | - const items = (data?.items || []).map((pool) => ({ |
239 | | - label: pool.name, |
240 | | - to: pb.ipPool({ pool: pool.name }), |
241 | | - })) |
242 | | - |
243 | | - return ( |
244 | | - <TopBarPicker |
245 | | - aria-label="Switch pool" |
246 | | - category="IP Pools" |
247 | | - current={poolName} |
248 | | - items={items} |
249 | | - noItemsText="No IP pools found" |
250 | | - /> |
251 | | - ) |
252 | | -} |
253 | | - |
254 | | -/** Used when drilling down into a VPC from the Silo view. */ |
255 | | -export function VpcPicker() { |
256 | | - // picker only shows up when a VPC is in scope |
257 | | - const { project, vpc } = useVpcSelector() |
258 | | - const { data } = useApiQuery('vpcList', { query: { project, limit: PAGE_SIZE } }) |
259 | | - const items = (data?.items || []).map((v) => ({ |
260 | | - label: v.name, |
261 | | - to: pb.vpc({ project, vpc: v.name }), |
262 | | - })) |
263 | | - |
264 | | - return ( |
265 | | - <TopBarPicker |
266 | | - aria-label="Switch VPC" |
267 | | - category="VPC" |
268 | | - current={vpc} |
269 | | - items={items} |
270 | | - noItemsText="No VPCs found" |
271 | | - to={pb.vpc({ project, vpc })} |
272 | | - /> |
273 | | - ) |
274 | | -} |
275 | | - |
276 | | -/** Used when drilling down into a VPC Router from the Silo view. */ |
277 | | -export function VpcRouterPicker() { |
278 | | - // picker only shows up when a router is in scope |
279 | | - const { project, vpc, router } = useVpcRouterSelector() |
280 | | - const { data } = useApiQuery('vpcRouterList', { |
281 | | - query: { project, vpc, limit: PAGE_SIZE }, |
282 | | - }) |
283 | | - const items = (data?.items || []).map((r) => ({ |
284 | | - label: r.name, |
285 | | - to: pb.vpcRouter({ vpc, project, router: r.name }), |
286 | | - })) |
287 | | - |
288 | | - return ( |
289 | | - <TopBarPicker |
290 | | - aria-label="Switch router" |
291 | | - category="router" |
292 | | - current={router} |
293 | | - items={items} |
294 | | - noItemsText="No routers found" |
295 | | - /> |
296 | | - ) |
297 | | -} |
298 | | - |
299 | | -const NoProjectLogo = () => ( |
300 | | - <div className="flex h-[34px] w-[34px] items-center justify-center rounded text-secondary bg-secondary"> |
301 | | - <Folder16Icon /> |
302 | | - </div> |
303 | | -) |
304 | | - |
305 | | -export function ProjectPicker({ project }: { project?: Project }) { |
306 | | - const { data: projects } = useApiQuery('projectList', { query: { limit: 200 } }) |
307 | | - const items = (projects?.items || []).map(({ name }) => ({ |
308 | | - label: name, |
309 | | - to: pb.project({ project: name }), |
310 | | - })) |
311 | | - |
312 | | - return ( |
313 | | - <TopBarPicker |
314 | | - aria-label="Switch project" |
315 | | - icon={project ? undefined : <NoProjectLogo />} |
316 | | - category="Project" |
317 | | - current={project?.name} |
318 | | - to={project ? pb.project({ project: project.name }) : undefined} |
319 | | - items={items} |
320 | | - noItemsText="No projects found" |
321 | | - /> |
322 | | - ) |
323 | | -} |
324 | | - |
325 | | -export function InstancePicker() { |
326 | | - // picker only shows up when an instance is in scope |
327 | | - const instanceSelector = useInstanceSelector() |
328 | | - const { project, instance } = instanceSelector |
329 | | - const { data: instances } = useApiQuery('instanceList', { |
330 | | - query: { project, limit: PAGE_SIZE }, |
331 | | - }) |
332 | | - const items = (instances?.items || []).map(({ name }) => ({ |
333 | | - label: name, |
334 | | - to: pb.instance({ project, instance: name }), |
335 | | - })) |
336 | | - return ( |
337 | | - <TopBarPicker |
338 | | - aria-label="Switch instance" |
339 | | - category="Instance" |
340 | | - current={instance} |
341 | | - to={pb.instance({ project, instance })} |
342 | | - items={items} |
343 | | - noItemsText="No instances found" |
344 | | - /> |
345 | | - ) |
346 | | -} |
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 | | -} |
0 commit comments