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 b1a6317
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
18 changes: 18 additions & 0 deletions app/pages/lookups.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { redirect, type LoaderFunctionArgs } from 'react-router-dom'

import { apiQueryClient } from '@oxide/api'

import { trigger404 } from 'app/components/ErrorBoundary'
import { pb } from 'app/util/path-builder'

export async function instanceLookupLoader({ 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 }))
}
2 changes: 2 additions & 0 deletions app/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import DeviceAuthSuccessPage from './pages/DeviceAuthSuccessPage'
import DeviceAuthVerifyPage from './pages/DeviceAuthVerifyPage'
import { LoginPage } from './pages/LoginPage'
import { LoginPageSaml } from './pages/LoginPageSaml'
import { instanceLookupLoader } from './pages/lookups'
import {
DisksPage,
ImagesPage,
Expand Down Expand Up @@ -229,6 +230,7 @@ export const routes = createRoutesFromElements(
loader={SiloUtilizationPage.loader}
handle={{ crumb: 'Utilization' }}
/>
<Route path="instances/:instance" element={null} loader={instanceLookupLoader} />
<Route loader={ProjectsPage.loader} element={<ProjectsPage />}>
<Route path="projects" handle={{ crumb: 'Projects' }} element={null} />
<Route
Expand Down

0 comments on commit b1a6317

Please sign in to comment.