feat(web): regroup console nav into 7 groups, split downloads/plans/tasks, add legacy redirects
- Sidebar: 概览/资源/订阅/下载/整理/Agent/系统, 18 items (+ 定时任务); single active item via findNavItem; 待处理 badge; collapsed rail groups; mobile drawer shares NAV_GROUPS. - New pages: /downloads (queue + cache watermark header), /downloads/plans, /downloads/:id, /tasks (business tasks only) + /tasks/:id detail, /rules. - Legacy links: ?tab= on tasks/subscriptions/sources redirect via clientLoader; /tasks/:downloadId falls back to /downloads/:id. - List filters in URL query; settingsPath() helper for settings deep links. - Copy per glossary (待处理, 收录策略, 引擎面板, 文件管理, 版本目标). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
5843527317
commit
909cd2ad49
31 files changed
+1247
-609
No files matched your search
@@ -1,23 +1,76 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { consolePath, findNavItem, NAV_ITEMS } from "./nav.ts";
|
||||
import { LEGACY_REDIRECTS, legacyRedirect } from "../../routes/console/redirects.ts";
|
||||
import { consolePath, findNavItem, NAV_GROUPS, NAV_ITEMS, settingsPath } from "./nav.ts";
|
||||
|
||||
/** routes.ts 里登记的控制台路由(相对 /console) */
|
||||
const ROUTE_PATTERNS = [
|
||||
"",
|
||||
...[...readFileSync(new URL("../../routes.ts", import.meta.url), "utf8").matchAll(/route\("([^"*]+)",/g)].map(
|
||||
(m) => m[1] as string,
|
||||
),
|
||||
];
|
||||
const matchesRoute = (pathname: string) => {
|
||||
const rest = pathname.replace(/^\/console\/?/, "");
|
||||
return ROUTE_PATTERNS.some((p) => new RegExp(`^${p.replace(/:[^/]+/g, "[^/]+")}$`).test(rest));
|
||||
};
|
||||
|
||||
describe("控制台导航", () => {
|
||||
it("12 个工作区 + 定时任务 + 引擎面板 + 审计,路径唯一且都在 /console 下", () => {
|
||||
expect(NAV_ITEMS).toHaveLength(16);
|
||||
expect(new Set(NAV_ITEMS.map((i) => i.to)).size).toBe(16);
|
||||
it("7 组 18 项(另加系统组的定时任务),路径唯一且都在 /console 下", () => {
|
||||
expect(NAV_GROUPS.map((g) => g.title)).toEqual(["概览", "资源", "订阅", "下载", "整理", "Agent", "系统"]);
|
||||
const core = NAV_ITEMS.filter((i) => i.to !== "/console/schedules");
|
||||
expect(core).toHaveLength(18);
|
||||
expect(new Set(NAV_ITEMS.map((i) => i.to)).size).toBe(NAV_ITEMS.length);
|
||||
expect(NAV_ITEMS.every((i) => i.to.startsWith("/console"))).toBe(true);
|
||||
for (const g of NAV_GROUPS) expect(g.items.length).toBeLessThanOrEqual(4);
|
||||
});
|
||||
|
||||
it("每个导航项都有路由", () => {
|
||||
for (const i of NAV_ITEMS) expect(matchesRoute(i.to), i.to).toBe(true);
|
||||
});
|
||||
|
||||
it("按最长前缀匹配当前项", () => {
|
||||
expect(findNavItem("/console")?.label).toBe("首页");
|
||||
expect(findNavItem("/console/")?.label).toBe("首页");
|
||||
expect(findNavItem("/console/library/abc")?.label).toBe("媒体库");
|
||||
expect(findNavItem("/console/engine/r1")?.label).toBe("工作流引擎");
|
||||
expect(findNavItem("/console/engine/r1")?.label).toBe("引擎面板");
|
||||
expect(findNavItem("/console/downloads")?.label).toBe("下载队列");
|
||||
expect(findNavItem("/console/downloads/plans")?.label).toBe("下载计划");
|
||||
expect(findNavItem("/console/downloads/abc")?.label).toBe("下载队列");
|
||||
expect(findNavItem("/console/tasks/abc")?.label).toBe("业务任务");
|
||||
expect(findNavItem("/console/sites/abc")?.label).toBe("站点工作台");
|
||||
expect(findNavItem("/nope")).toBeUndefined();
|
||||
});
|
||||
|
||||
it("consolePath 拼路径并编码", () => {
|
||||
expect(consolePath()).toBe("/console");
|
||||
expect(consolePath("library", "a b")).toBe("/console/library/a%20b");
|
||||
expect(consolePath("downloads", "plans")).toBe("/console/downloads/plans");
|
||||
});
|
||||
|
||||
it("settingsPath 只认新分区名", () => {
|
||||
expect(settingsPath("automation", "cache").startsWith("/console/settings")).toBe(true);
|
||||
expect(settingsPath("agent").startsWith("/console/settings")).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("旧链接重定向", () => {
|
||||
it.each(LEGACY_REDIRECTS)("$from → $to", ({ from, to }) => {
|
||||
const u = new URL(from, "http://x");
|
||||
expect(legacyRedirect(u.pathname, u.search)).toBe(to);
|
||||
});
|
||||
|
||||
it("新地址都有路由,且不会再次跳转", () => {
|
||||
for (const { to } of LEGACY_REDIRECTS) {
|
||||
const u = new URL(to, "http://x");
|
||||
expect(matchesRoute(u.pathname), to).toBe(true);
|
||||
if (u.pathname !== "/console/sites/abc") expect(legacyRedirect(u.pathname, u.search)).toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
it("不相关的 query 不跳转", () => {
|
||||
expect(legacyRedirect("/console/tasks", "?kind=submitDownload")).toBeNull();
|
||||
expect(legacyRedirect("/console/subscriptions", "")).toBeNull();
|
||||
expect(legacyRedirect("/console/sources", "?health=failing")).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
Activity,
|
||||
Bot,
|
||||
CalendarClock,
|
||||
ClipboardList,
|
||||
Download,
|
||||
FileStack,
|
||||
Fingerprint,
|
||||
@@ -10,6 +11,8 @@ import {
|
||||
House,
|
||||
Inbox,
|
||||
Library,
|
||||
ListChecks,
|
||||
ListTodo,
|
||||
type LucideIcon,
|
||||
Rss,
|
||||
ScrollText,
|
||||
@@ -18,7 +21,14 @@ import {
|
||||
Timer,
|
||||
} from "lucide-react";
|
||||
|
||||
export type NavItem = { to: string; label: string; icon: LucideIcon; description: string };
|
||||
export type NavItem = {
|
||||
to: string;
|
||||
label: string;
|
||||
icon: LucideIcon;
|
||||
description: string;
|
||||
/** 侧栏角标的数据来源 */
|
||||
badge?: "decisions";
|
||||
};
|
||||
export type NavGroup = { title: string; items: NavItem[] };
|
||||
|
||||
/** 控制台路由前缀 */
|
||||
@@ -30,7 +40,10 @@ export function consolePath(...segments: (string | number)[]): string {
|
||||
return rest ? `${CONSOLE_BASE}/${rest}` : CONSOLE_BASE;
|
||||
}
|
||||
|
||||
/** 控制台 12 个工作区(任务书 §3.1 第 10 条 / REQ §13.1)+ 引擎面板与审计两个运维页 */
|
||||
/**
|
||||
* 侧栏 7 组(docs/design/console-ia.md §3.2),按业务流程排:概览 → 资源 → 订阅 → 下载 → 整理 → Agent → 系统。
|
||||
* 移动端抽屉用同一份表。
|
||||
*/
|
||||
export const NAV_GROUPS: NavGroup[] = [
|
||||
{
|
||||
title: "概览",
|
||||
@@ -39,89 +52,123 @@ export const NAV_GROUPS: NavGroup[] = [
|
||||
to: "/console",
|
||||
label: "首页",
|
||||
icon: House,
|
||||
description: "自动化概览、当前工作、需要我处理、缓存与保留、来源健康、最近产出",
|
||||
description: "自动化概览、当前工作、待处理、缓存、来源健康、最近产出",
|
||||
},
|
||||
{
|
||||
to: "/console/inbox",
|
||||
label: "待处理中心",
|
||||
label: "待处理",
|
||||
icon: Inbox,
|
||||
description: "按作品与根因合并的待决定事项,Agent 已先行调查",
|
||||
description: "按作品和问题类型合并的待处理事项",
|
||||
badge: "decisions",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "媒体",
|
||||
title: "资源",
|
||||
items: [
|
||||
{ to: "/console/library", label: "媒体库", icon: Library, description: "作品、内容单元、版本目标与实际路径" },
|
||||
{
|
||||
to: "/console/identity",
|
||||
label: "身份与元数据",
|
||||
icon: Fingerprint,
|
||||
description: "外部身份映射、待识别池与元数据来源",
|
||||
to: "/console/sites",
|
||||
label: "站点工作台",
|
||||
icon: Globe,
|
||||
description: "站点、站点账号、快照与 Feed",
|
||||
},
|
||||
{
|
||||
to: "/console/organize",
|
||||
label: "整理记录",
|
||||
icon: FileStack,
|
||||
description: "Copy/Move 入库前后路径与逐文件结果",
|
||||
},
|
||||
{
|
||||
to: "/console/files",
|
||||
label: "文件",
|
||||
icon: FolderTree,
|
||||
description: "浏览已登记的库根与下载目录,改名、移动、删除与批量整理",
|
||||
to: "/console/sources",
|
||||
label: "来源健康",
|
||||
icon: Rss,
|
||||
description: "全部 Feed 与站点的抓取状态",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "获取",
|
||||
title: "订阅",
|
||||
items: [
|
||||
{
|
||||
to: "/console/subscriptions",
|
||||
label: "订阅与收录规则",
|
||||
label: "订阅",
|
||||
icon: CalendarClock,
|
||||
description: "单次收录与持续追踪,版本目标与预算",
|
||||
description: "单次收录与持续追踪",
|
||||
},
|
||||
{
|
||||
to: "/console/rules",
|
||||
label: "收录策略",
|
||||
icon: ListChecks,
|
||||
description: "新作品收录条件、默认版本目标与策略版本",
|
||||
},
|
||||
{
|
||||
to: "/console/preferences",
|
||||
label: "偏好标签",
|
||||
icon: Tags,
|
||||
description: "软偏好与硬规则,手动取消的偏好不会被自动加回",
|
||||
},
|
||||
{
|
||||
to: "/console/sites",
|
||||
label: "PT 站点工作台",
|
||||
icon: Globe,
|
||||
description: "统一格式浏览、搜索站点资源并关联本地库存",
|
||||
},
|
||||
{
|
||||
to: "/console/sources",
|
||||
label: "来源 / Feed / 快照",
|
||||
icon: Rss,
|
||||
description: "RSS 与站点快照的抓取状态、新鲜度与健康",
|
||||
},
|
||||
{
|
||||
to: "/console/tasks",
|
||||
label: "下载与任务",
|
||||
icon: Download,
|
||||
description: "下载、整理、核验的业务时间线与子任务",
|
||||
description: "软偏好影响排序,硬规则直接排除",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "助手与系统",
|
||||
title: "下载",
|
||||
items: [
|
||||
{
|
||||
to: "/console/downloads",
|
||||
label: "下载队列",
|
||||
icon: Download,
|
||||
description: "下载任务与缓存水位",
|
||||
},
|
||||
{
|
||||
to: "/console/downloads/plans",
|
||||
label: "下载计划",
|
||||
icon: ClipboardList,
|
||||
description: "选中候选后生成的计划与空间预留",
|
||||
},
|
||||
{
|
||||
to: "/console/tasks",
|
||||
label: "业务任务",
|
||||
icon: ListTodo,
|
||||
description: "提交下载、核验入库、清理缓存等后台任务",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "整理",
|
||||
items: [
|
||||
{ to: "/console/library", label: "媒体库", icon: Library, description: "作品、季 / 集、版本目标与实际路径" },
|
||||
{
|
||||
to: "/console/organize",
|
||||
label: "整理记录",
|
||||
icon: FileStack,
|
||||
description: "每次整理的前后路径与逐文件结果",
|
||||
},
|
||||
{
|
||||
to: "/console/files",
|
||||
label: "文件管理",
|
||||
icon: FolderTree,
|
||||
description: "浏览登记目录,改名、移动、删除与整理",
|
||||
},
|
||||
{
|
||||
to: "/console/identity",
|
||||
label: "身份与元数据",
|
||||
icon: Fingerprint,
|
||||
description: "外部身份、待识别资源与别名",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "Agent",
|
||||
items: [
|
||||
{
|
||||
to: "/console/agent",
|
||||
label: "Agent 会话",
|
||||
icon: Bot,
|
||||
description: "用自然语言交代目标,Agent 在授权内执行并汇报",
|
||||
description: "交代目标,Agent 在授权内执行并汇报",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
title: "系统",
|
||||
items: [
|
||||
{
|
||||
to: "/console/settings",
|
||||
label: "系统设置",
|
||||
label: "设置",
|
||||
icon: Settings,
|
||||
description: "下载器与媒体服务器实例、路径映射、API Key、Pi 上游与自动化开关",
|
||||
description: "下载器、媒体服务器、库根、站点账号、Agent 上游与自动化",
|
||||
},
|
||||
{
|
||||
to: "/console/schedules",
|
||||
@@ -131,9 +178,9 @@ export const NAV_GROUPS: NavGroup[] = [
|
||||
},
|
||||
{
|
||||
to: "/console/engine",
|
||||
label: "工作流引擎",
|
||||
label: "引擎面板",
|
||||
icon: Activity,
|
||||
description: "持久任务引擎的运行记录、步骤尝试与信号(只读诊断,仅管理员)",
|
||||
description: "排查用,业务进度看业务任务。仅管理员",
|
||||
},
|
||||
{
|
||||
to: "/console/audit",
|
||||
@@ -147,6 +194,35 @@ export const NAV_GROUPS: NavGroup[] = [
|
||||
|
||||
export const NAV_ITEMS = NAV_GROUPS.flatMap((g) => g.items);
|
||||
|
||||
/**
|
||||
* 设置页深链。IA-2 把设置改为 /console/settings/:section 之前,先落到现有 ?tab=;
|
||||
* 调用方只认新分区名,切换时只改这里。
|
||||
*/
|
||||
export type SettingsSection =
|
||||
| "automation"
|
||||
| "sites"
|
||||
| "downloaders"
|
||||
| "library"
|
||||
| "media-servers"
|
||||
| "metadata"
|
||||
| "agent"
|
||||
| "api-keys"
|
||||
| "account";
|
||||
const SETTINGS_LEGACY_TAB: Partial<Record<SettingsSection, string>> = {
|
||||
automation: "automation",
|
||||
sites: "site-credentials",
|
||||
downloaders: "downloaders",
|
||||
library: "library-roots",
|
||||
"media-servers": "media-servers",
|
||||
agent: "pi",
|
||||
"api-keys": "api-keys",
|
||||
};
|
||||
export function settingsPath(section: SettingsSection, anchor?: string): string {
|
||||
// 缓存阈值现在在"缓存与入库"页签,IA-2 后归到 automation#cache
|
||||
const tab = section === "automation" && anchor === "cache" ? "storage" : SETTINGS_LEGACY_TAB[section];
|
||||
return tab ? `${CONSOLE_BASE}/settings?tab=${tab}` : `${CONSOLE_BASE}/settings`;
|
||||
}
|
||||
|
||||
/** 按路径找当前导航项(最长前缀匹配) */
|
||||
export function findNavItem(pathname: string): NavItem | undefined {
|
||||
return (
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useCallback } from "react";
|
||||
import { useSearchParams } from "react-router";
|
||||
|
||||
/**
|
||||
* 列表页筛选状态写进 URL query(docs/design/console-ia.md §3.6),刷新和分享链接不丢筛选。
|
||||
* const f = useQueryState(["status", "managed"]);
|
||||
* f.values.status; f.set("status", "paused"); f.reset();
|
||||
*/
|
||||
export function useQueryState<K extends string>(keys: readonly K[]) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const values = Object.fromEntries(keys.map((k) => [k, params.get(k) ?? ""])) as Record<K, string>;
|
||||
const set = useCallback(
|
||||
(key: K, value: string) =>
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
),
|
||||
[setParams],
|
||||
);
|
||||
const keyList = keys.join(",");
|
||||
const reset = useCallback(
|
||||
() =>
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
for (const k of keyList.split(",")) next.delete(k);
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
),
|
||||
[setParams, keyList],
|
||||
);
|
||||
const active = keys.some((k) => !!values[k]);
|
||||
return { values, set, reset, active };
|
||||
}
|
||||
Reference in new issue
Block a user