fix(ui): merge folder parent routes so nav shows labels; drop dead legacy redirects

This commit is contained in:
sam committed 2026-11-27 16:38:02 +11:00
1 parent 0d267170c6
commit a8628de625
4 files changed
+43 -66

No files matched your search

+3 -3
View File
@@ -164,7 +164,7 @@ func providerAlerts(providers map[string]config.Provider) []alert.Input {
Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("Provider %q has no usable credential", name),
Body: "Key unresolved; its models cannot run. Check the binding.",
Link: "/settings/credential-bindings",
Link: "/settings/credentials",
})
}
return out
@@ -218,7 +218,7 @@ func unboundAlerts(cfg config.Config) map[org.OrgID][]alert.Input {
Key: key, Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("%q is granted but has no credential binding", service),
Body: "Runs cannot authenticate. Bind a credential.",
Link: "/settings/credential-bindings",
Link: "/settings/credentials",
})
}
}
@@ -445,7 +445,7 @@ func (w *credentialWatch) observe(ctx context.Context, orgName, service string,
Key: key, Severity: alert.SeverityAction, Condition: true,
Title: fmt.Sprintf("The credential bound to %q is not working", service),
Body: "Secret unresolved; runs cannot authenticate. Check the binding.",
Link: "/settings/credential-bindings",
Link: "/settings/credentials",
})
}()
}
+21 -4
View File
@@ -49,18 +49,35 @@ export function flattenRoutes(
list: NavRouteNode[],
parent = "",
): NavRouteNode[] {
return mergeSamePath(flatten(list, parent));
}
function flatten(list: NavRouteNode[], parent: string): NavRouteNode[] {
return list.flatMap((route) => {
const joined = route.path.startsWith("/")
? route.path
: `${parent}/${route.path}`.replace(/\/+/g, "/");
const path = joined.length > 1 ? joined.replace(/\/$/, "") : joined;
return [
{ ...route, path },
...flattenRoutes(route.children ?? [], path),
];
return [{ ...route, path }, ...flatten(route.children ?? [], path)];
});
}
// File-based routing wraps a folder's index page in a parent route with no
// meta of its own (runs/ holds index.vue and [id].vue), and a layout route
// shares its address with its index child. Both answer at one address, so
// they merge into one entry; the earlier route's fields win.
function mergeSamePath(routes: NavRouteNode[]): NavRouteNode[] {
const byPath = new Map<string, NavRouteNode>();
for (const route of routes) {
const seen = byPath.get(route.path);
byPath.set(
route.path,
seen ? { ...route, ...seen, meta: { ...route.meta, ...seen.meta } } : route,
);
}
return [...byPath.values()];
}
export type NavSpec =
| { kind: "link"; path: string; label?: string }
| {
+1 -58
View File
@@ -1,38 +1,4 @@
import type { RouteLocationGeneric, RouteRecordRaw } from "vue-router";
const legacyRedirects: Record<string, string> = {
// The old unified Access area and the org-owned settings that used to sit
// under Settings resolve to the Organisation destination (or Account for
// personal tokens, which were never the org's).
"/access": "/org",
"/access/authentication": "/settings/authentication",
"/access/agents": "/org/agents",
"/access/workspaces": "/org/workspaces",
"/access/policies": "/org/policies",
"/access/models": "/org/models",
"/access/tokens": "/account",
"/settings/identities": "/org/agents",
"/settings/access-policies": "/org/policies",
"/settings/connections": "/org/connections",
"/settings/repositories": "/org/repositories",
"/settings/credential-bindings": "/org/credential-bindings",
"/settings/soul": "/org/instructions",
"/org/soul": "/org/instructions",
"/settings/schedules": "/org/schedules",
"/settings/playbooks": "/org/playbooks",
"/settings/scheduling-policy": "/org/scheduling-policy",
"/settings/appearance": "/account/appearance",
// Paths from before Settings existed, kept for bookmarks and chat history.
"/system/status": "/settings/status",
"/system/appearance": "/account/appearance",
"/system/tasks": "/settings/task-execution",
"/system/models": "/settings/models",
"/system/repos": "/settings/repositories",
"/system/identities": "/org/agents",
"/channels": "/org/channels",
"/skills": "/settings/skills",
"/curators": "/settings/curators",
};
import type { RouteRecordRaw } from "vue-router";
/**
* Redirect-only routes that do not correspond to a page component under
@@ -115,27 +81,4 @@ export const redirects: RouteRecordRaw[] = [
description: "Workflows and the events that start them.",
},
},
{
path: "/settings/history",
redirect: (to: RouteLocationGeneric) => ({
path: "/org/audit",
query: to.query,
hash: to.hash,
}),
meta: { nav: false },
},
{
path: "/settings/audit",
redirect: (to: RouteLocationGeneric) => ({
path: "/org/audit",
query: to.query,
hash: to.hash,
}),
meta: { nav: false },
},
...Object.entries(legacyRedirects).map(([path, redirect]) => ({
path,
redirect,
meta: { nav: false },
})),
];
+18 -1
View File
@@ -90,7 +90,7 @@ test("a nav spec names the address the browser visits, not the child's own path"
]);
assert.deepEqual(
flat.map((r) => r.path),
["/org", "/org", "/org/agents", "/org/settings/keys", "/org/settings/keys/new", "/absolute", "/absolute/child"],
["/org", "/org/agents", "/org/settings/keys", "/org/settings/keys/new", "/absolute", "/absolute/child"],
);
});
@@ -123,3 +123,20 @@ test("an unlabelled section marks its first item with an empty divider", () => {
],
);
});
// Guards the sidebar showing "/runs" instead of "Runs": file-based routing
// wraps a folder's index page in a parent route that carries no meta.
test("a metaless folder route merges with its index page", () => {
const flat = flattenRoutes([
{
path: "/runs",
children: [
{ path: "", meta: { label: "Runs", description: "All runs" } },
{ path: ":id", meta: { label: "Run" } },
],
},
]);
const runs = flat.filter((r) => r.path === "/runs");
assert.equal(runs.length, 1);
assert.equal(runs[0].meta?.label, "Runs");
});