Fix active cookie jar and improve routing

This commit is contained in:
Gregory Schier
2024-10-28 10:06:43 -07:00
parent 4a52095033
commit 6d2c3712c0
19 changed files with 95 additions and 71 deletions

View File

@@ -1,6 +1,6 @@
import { lazy } from 'react';
import { createBrowserRouter, Navigate, RouterProvider, useParams } from 'react-router-dom';
import { routePaths, useAppRoutes } from '../hooks/useAppRoutes';
import { paths, useAppRoutes } from '../hooks/useAppRoutes';
import { DefaultLayout } from './DefaultLayout';
import { RedirectToLatestWorkspace } from './RedirectToLatestWorkspace';
import RouteError from './RouteError';
@@ -19,19 +19,23 @@ const router = createBrowserRouter([
element: <RedirectToLatestWorkspace />,
},
{
path: routePaths.workspaces(),
path: paths.workspaces(),
element: <RedirectToLatestWorkspace />,
},
{
path: routePaths.workspace({
path: paths.workspace({
workspaceId: ':workspaceId',
environmentId: null,
cookieJarId: null,
}),
element: <LazyWorkspace />,
},
{
path: routePaths.request({
path: paths.request({
workspaceId: ':workspaceId',
requestId: ':requestId',
environmentId: null,
cookieJarId: null,
}),
element: <LazyWorkspace />,
},
@@ -40,8 +44,10 @@ const router = createBrowserRouter([
element: <RedirectLegacyEnvironmentURLs />,
},
{
path: routePaths.workspaceSettings({
path: paths.workspaceSettings({
workspaceId: ':workspaceId',
environmentId: null,
cookieJarId: null,
}),
element: <LazySettings />,
},
@@ -64,13 +70,13 @@ function RedirectLegacyEnvironmentURLs() {
workspaceId?: string;
environmentId?: string;
}>();
const environmentId = rawEnvironmentId === '__default__' ? undefined : rawEnvironmentId;
const environmentId = (rawEnvironmentId === '__default__' ? undefined : rawEnvironmentId) ?? null;
let to;
if (workspaceId != null && requestId != null) {
to = routes.paths.request({ workspaceId, environmentId, requestId });
to = routes.paths.request({ workspaceId, environmentId, requestId, cookieJarId: null });
} else if (workspaceId != null) {
to = routes.paths.workspace({ workspaceId, environmentId });
to = routes.paths.workspace({ workspaceId, environmentId, cookieJarId: null });
} else {
to = routes.paths.workspaces();
}