mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-20 17:13:49 +00:00
Resolve the selected group from /admin/groups/{groupId}, validate console paths, and use browser history for back navigation. Keep Groups active and let an active mobile-tab tap return to the list. Scope pending route loads to their group and retain the count beside long headings.
28 lines
1.1 KiB
TypeScript
28 lines
1.1 KiB
TypeScript
/** Top-level pages of the admin console. */
|
|
export type AdminView = "overview" | "groups" | "logs" | "audit" | "metrics";
|
|
|
|
const VIEWS: readonly string[] = ["overview", "groups", "logs", "audit", "metrics"];
|
|
|
|
/**
|
|
* Read the console page from the segments after /admin: `[]` (overview),
|
|
* `["groups"]`, `["groups", groupId]` (that group's routes), `["logs"]`,
|
|
* `["audit"]`, `["metrics"]`. Anything else is no console page (null → 404).
|
|
*/
|
|
export function parseAdminPath(
|
|
slug: string | string[] | undefined,
|
|
): { view: AdminView; groupId: string | null } | null {
|
|
// A trailing slash adds an empty segment.
|
|
const [view, groupId, ...rest] = (Array.isArray(slug) ? slug : slug ? [slug] : []).filter(
|
|
Boolean,
|
|
);
|
|
if (!view) return { view: "overview", groupId: null };
|
|
if (!VIEWS.includes(view) || rest.length) return null;
|
|
// Only groups have sub-pages.
|
|
if (groupId !== undefined && view !== "groups") return null;
|
|
return { view: view as AdminView, groupId: groupId ?? null };
|
|
}
|
|
|
|
export function adminGroupPath(groupId: string): string {
|
|
return `/admin/groups/${encodeURIComponent(groupId)}`;
|
|
}
|