swarm-ui: the moved tabs' redirects come from one table, with tests
The four tab moves each hand-wrote a redirect route. They are one table now, MOVED_ROUTES, and movedHref says where an old address goes with its query kept; /builds?run= still lands on the build's card. The builds page's own redirect helper is gone.
This commit is contained in:
parent
f55f0973eb
commit
c28ca7aab5
1 changed files with 58 additions and 35 deletions
|
|
@ -1,7 +1,7 @@
|
|||
// Root shell component — routing only. Each route's content is its own
|
||||
// page component under `./pages/`; this file just maps paths to them.
|
||||
import { Redirect, Route, Router, Switch, useSearch } from "wouter-preact";
|
||||
import { jobsHref } from "./pages/builds/builds-types.js";
|
||||
import { MOVED_ROUTES, movedHref } from "./shell/routes.js";
|
||||
import { Shell } from "./shell/Shell.js";
|
||||
import { useGuardedLocation } from "./shell/useGuardedLocation.js";
|
||||
import { AgentsPage } from "./pages/agents/AgentsPage.js";
|
||||
|
|
@ -16,11 +16,10 @@ import { ReportsPage } from "./pages/reports/ReportsPage.js";
|
|||
import { StartPage } from "./pages/StartPage.js";
|
||||
import { Panel } from "./ui/panel/Panel.js";
|
||||
|
||||
// The builds page moved onto the jobs tab. Links made before that, such as the
|
||||
// Details link on a swarm-builder commit status, land here and go on to the
|
||||
// same build's card, query kept.
|
||||
function BuildsMoved() {
|
||||
return <Redirect to={jobsHref(useSearch())} replace />;
|
||||
// An address from before the tabs were folded together: replace it with the
|
||||
// tab that holds the page now, query kept.
|
||||
function MovedTo({ from }: { from: string }) {
|
||||
return <Redirect to={movedHref(from, useSearch()) ?? "/"} replace />;
|
||||
}
|
||||
|
||||
function NotFound() {
|
||||
|
|
@ -38,9 +37,11 @@ export function App() {
|
|||
<Switch>
|
||||
<Route path="/" component={StartPage} />
|
||||
<Route path="/reports" component={ReportsPage} />
|
||||
<Route path="/alerts">
|
||||
<Redirect to="/reports" replace />
|
||||
</Route>
|
||||
{Object.keys(MOVED_ROUTES).map((from) => (
|
||||
<Route key={from} path={from}>
|
||||
<MovedTo from={from} />
|
||||
</Route>
|
||||
))}
|
||||
<Route path="/agents" component={AgentsPage} />
|
||||
<Route path="/agents/:name/terminal" component={AgentTerminalPage} />
|
||||
<Route
|
||||
|
|
@ -48,22 +49,12 @@ export function App() {
|
|||
component={AgentTerminalPage}
|
||||
/>
|
||||
<Route path="/jobs" component={JobsPage} />
|
||||
<Route path="/schedules">
|
||||
<Redirect to="/messages" replace />
|
||||
</Route>
|
||||
<Route path="/builds" component={BuildsMoved} />
|
||||
<Route path="/messages" component={MessagesPage} />
|
||||
<Route path="/notifications" component={NotificationsPage} />
|
||||
<Route path={NEW_FLOW_PATH}>
|
||||
<FlowEditorPage params={{ flowId: "" }} isNew />
|
||||
</Route>
|
||||
<Route path="/notifications/:flowId" component={FlowEditorPage} />
|
||||
<Route path="/issues">
|
||||
<Redirect to="/reports" replace />
|
||||
</Route>
|
||||
<Route path="/review">
|
||||
<Redirect to="/jobs" replace />
|
||||
</Route>
|
||||
<Route path="/components" component={ComponentsPage} />
|
||||
<Route component={NotFound} />
|
||||
</Switch>
|
||||
|
|
|
|||
Loading…
Reference in a new issue