Skip to content

Commit

Permalink
/instances/:id looks up instance and redirects to project instance route
Browse files Browse the repository at this point in the history
  • Loading branch information
david-crespo committed Feb 8, 2024
1 parent cfda163 commit 6c5ac66
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@
*
* Copyright Oxide Computer Company
*/
import { createRoutesFromElements, Navigate, Route } from 'react-router-dom'
import {
createRoutesFromElements,
Navigate,
redirect,
Route,
type LoaderFunctionArgs,
} from 'react-router-dom'

import { apiQueryClient } from '@oxide/api'

import { RouterDataErrorBoundary } from './components/ErrorBoundary'
import { RouterDataErrorBoundary, trigger404 } from './components/ErrorBoundary'
import { NotFound } from './components/ErrorPage'
import { CreateDiskSideModalForm } from './forms/disk-create'
import { CreateIdpSideModalForm } from './forms/idp/create'
Expand Down Expand Up @@ -229,6 +237,21 @@ export const routes = createRoutesFromElements(
loader={SiloUtilizationPage.loader}
handle={{ crumb: 'Utilization' }}
/>
<Route
path="instances/:instance"
element={null}
loader={async ({ params }: LoaderFunctionArgs) => {
const instance = await apiQueryClient.fetchQuery('instanceView', {
path: { instance: params.instance! },
})
if (!instance) throw trigger404
const project = await apiQueryClient.fetchQuery('projectView', {
path: { project: instance.projectId },
})
if (!project) throw trigger404
return redirect(pb.instance({ project: project.name, instance: instance.name }))
}}
/>
<Route loader={ProjectsPage.loader} element={<ProjectsPage />}>
<Route path="projects" handle={{ crumb: 'Projects' }} element={null} />
<Route
Expand Down

0 comments on commit 6c5ac66

Please sign in to comment.