From b1a63174783c41b29ddec67d12f9b3582adeb820 Mon Sep 17 00:00:00 2001 From: David Crespo Date: Wed, 7 Feb 2024 21:39:55 -0600 Subject: [PATCH] /instances/:id looks up instance and redirects to project instance route --- app/pages/lookups.ts | 18 ++++++++++++++++++ app/routes.tsx | 2 ++ 2 files changed, 20 insertions(+) create mode 100644 app/pages/lookups.ts diff --git a/app/pages/lookups.ts b/app/pages/lookups.ts new file mode 100644 index 0000000000..1816965a81 --- /dev/null +++ b/app/pages/lookups.ts @@ -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 })) +} diff --git a/app/routes.tsx b/app/routes.tsx index 55f1095323..d67623fa2c 100644 --- a/app/routes.tsx +++ b/app/routes.tsx @@ -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, @@ -229,6 +230,7 @@ export const routes = createRoutesFromElements( loader={SiloUtilizationPage.loader} handle={{ crumb: 'Utilization' }} /> + }>