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
3 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>
|
||||
|
|
|
|||
|
|
@ -37,11 +37,6 @@ export const OUTCOME_TONE: Record<BuildOutcome, BadgeTone> = {
|
|||
error: "warning",
|
||||
};
|
||||
|
||||
/** Where an old `/builds` link goes: the jobs page, keeping its query. */
|
||||
export function jobsHref(search: string): string {
|
||||
return search === "" ? "/jobs" : `/jobs?${search}`;
|
||||
}
|
||||
|
||||
/** The run a `?run=<id>` query names, or `null` when it names none. */
|
||||
export function wantedRun(search: string): string | null {
|
||||
const id = new URLSearchParams(search).get("run");
|
||||
|
|
|
|||
|
|
@ -27,3 +27,22 @@ export function visibleNavItems<T extends { href: string }>(
|
|||
if (!hideDeveloper) return items;
|
||||
return items.filter((item) => !DEVELOPER_ROUTES.includes(item.href));
|
||||
}
|
||||
|
||||
// Tabs that were folded into another one. Each old address redirects to its
|
||||
// new tab, so a bookmark or a link made before the move still lands. The
|
||||
// builds page's `?run=` query rides along, which a swarm-builder commit
|
||||
// status link relies on.
|
||||
export const MOVED_ROUTES: Readonly<Record<string, string>> = {
|
||||
"/alerts": "/reports",
|
||||
"/issues": "/reports",
|
||||
"/builds": "/jobs",
|
||||
"/review": "/jobs",
|
||||
"/schedules": "/messages",
|
||||
};
|
||||
|
||||
/** Where an old address goes, keeping its query; `null` for any other path. */
|
||||
export function movedHref(path: string, search: string): string | null {
|
||||
const to = MOVED_ROUTES[path];
|
||||
if (to === undefined) return null;
|
||||
return search === "" ? to : `${to}?${search}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue