控制台导航最多两层(侧栏一项 = 一页,页内最多一层页签 / 分段);从列表打开的
记录改成列表页上的右侧抽屉,打开的记录写在 ?open=,刷新、分享、前进后退都能还原,
后退就是关抽屉。标准写在 docs/design/console-ia.md §9,ui-controls.md 引用。
- DetailSheet 加 xl 宽度、标题下操作行;抽屉里再开的 DetailSheet 在同一抽屉里换成子视图(返回 / Esc)
- record-sheet.tsx:useRecordSheet / RecordLink / useOpenRecord / recordPath / taskPath
- 整理记录、订阅、站点(含页签)、下载、日志任务改成抽屉;旧业务任务 / 下载任务 id 在任务抽屉里换算
- 回收站并进文件管理右侧视图(?view=trash);设置左栏只列分区
- 规则组、策略版本、媒体库未识别 / 外部身份、设置实例编辑走 ?open=
- 旧地址 /console/{organize,subscriptions,sites,downloads}/:id、/tasks/:id、/files/trash 跳到列表页抽屉
- 站内链接、铃铛、命令面板、任务时间线改拼新地址;冒烟按 ?open= 检查抽屉
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Cxwgnn2pbzQ7rXv3rq7fei
212 lines
7.4 KiB
TypeScript
212 lines
7.4 KiB
TypeScript
import type { RuleGroup, RuleGroupKind, RuleGroupSource } from "@umt/contracts";
|
|
import { FilePlus2, Plus } from "lucide-react";
|
|
import { useMemo, useRef, useState } from "react";
|
|
import { useSearchParams } from "react-router";
|
|
import { useRuleGroups, useRuleRefs } from "~/api/rules.ts";
|
|
import { FilterBar, FilterSelect } from "~/components/console/filter-bar.tsx";
|
|
import { PageHeader } from "~/components/console/page-header.tsx";
|
|
import { useRecordSheet } from "~/components/console/record-sheet.tsx";
|
|
import { PolicyWorkspace } from "~/components/library/subscriptions-policy.tsx";
|
|
import { RuleGroupEditor } from "~/components/rules/group-editor.tsx";
|
|
import { RuleGroupTable, RuleTags } from "~/components/rules/group-list.tsx";
|
|
import { isTagLike, RULE_KIND, RULE_SOURCE } from "~/components/rules/labels.ts";
|
|
import { AtomsTab, DefaultsTab, SuppressionsTab } from "~/components/rules/tabs.tsx";
|
|
import { Button } from "~/components/ui/button.tsx";
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "~/components/ui/tabs.tsx";
|
|
|
|
// 规则(docs/design/subscriptions.md §6):收录策略 + 偏好标签合一。
|
|
// Tab:规则组(含单条规则的标签形态)/ 自定义条件 / 默认值 / 收录策略 / 抑制记录。
|
|
|
|
export const meta = () => [{ title: "规则 · UHD 媒体自动化控制台" }];
|
|
|
|
const TABS = ["groups", "atoms", "defaults", "policies", "suppressions"] as const;
|
|
type Tab = (typeof TABS)[number];
|
|
|
|
/** 旧 /preferences?origin= 透传过来的来源 */
|
|
const ORIGIN_TO_SOURCE: Record<string, RuleGroupSource> = {
|
|
manual: "manual",
|
|
conversation: "chat",
|
|
agent_inferred: "agent",
|
|
};
|
|
|
|
export default function RulesPage() {
|
|
const [params, setParams] = useSearchParams();
|
|
const tabParam = params.get("tab") ?? "groups";
|
|
const tab: Tab = (TABS as readonly string[]).includes(tabParam) ? (tabParam as Tab) : "groups";
|
|
const setParam = (k: string, v: string) =>
|
|
setParams(
|
|
(p) => {
|
|
if (v) p.set(k, v);
|
|
else p.delete(k);
|
|
return p;
|
|
},
|
|
{ replace: true },
|
|
);
|
|
|
|
const kind = params.get("kind") ?? "";
|
|
const source = params.get("source") ?? ORIGIN_TO_SOURCE[params.get("origin") ?? ""] ?? "";
|
|
const enabled = params.get("enabled") ?? "";
|
|
const [q, setQ] = useState(params.get("q") ?? "");
|
|
const filtered = !!(kind || source || enabled || q.trim());
|
|
|
|
const groups = useRuleGroups({
|
|
kind: (kind || undefined) as RuleGroupKind | undefined,
|
|
source: (source || undefined) as RuleGroupSource | undefined,
|
|
enabled: (enabled || undefined) as "true" | "false" | undefined,
|
|
q: q.trim() || undefined,
|
|
});
|
|
const all = useRuleGroups({});
|
|
const refs = useRuleRefs();
|
|
// 记录抽屉(console-ia.md §9):打开的规则组在 ?open=<id>(「自动收新作品」的策略版本也用 ?open=,各认自己的 id);新建只在本页状态里
|
|
const sheet = useRecordSheet();
|
|
const [creating, setCreating] = useState(false);
|
|
const lastId = useRef<string | null>(null);
|
|
if (sheet.id) lastId.current = sheet.id;
|
|
const editId = sheet.id ?? (creating ? null : lastId.current);
|
|
const [creatingPolicy, setCreatingPolicy] = useState(false);
|
|
|
|
const items = groups.data?.items;
|
|
const tags = useMemo(() => (items ?? []).filter(isTagLike), [items]);
|
|
const rest = useMemo(() => items?.filter((g) => !isTagLike(g)), [items]);
|
|
const editing: RuleGroup | null = editId
|
|
? ((items ?? []).find((g) => g.id === editId) ?? all.data?.items.find((g) => g.id === editId) ?? null)
|
|
: null;
|
|
const open = (g: RuleGroup) => sheet.open(g.id);
|
|
const create = () => {
|
|
lastId.current = null;
|
|
setCreating(true);
|
|
};
|
|
|
|
return (
|
|
<>
|
|
<PageHeader
|
|
title="规则"
|
|
actions={
|
|
tab === "policies" ? (
|
|
<Button onClick={() => setCreatingPolicy(true)}>
|
|
<FilePlus2 />
|
|
新建
|
|
</Button>
|
|
) : (
|
|
<Button onClick={create}>
|
|
<Plus />
|
|
新建规则组
|
|
</Button>
|
|
)
|
|
}
|
|
/>
|
|
|
|
<Tabs
|
|
value={tab}
|
|
onValueChange={(v) =>
|
|
setParams(
|
|
(p) => {
|
|
if (v === "groups") p.delete("tab");
|
|
else p.set("tab", v);
|
|
return p;
|
|
},
|
|
{ replace: true },
|
|
)
|
|
}
|
|
>
|
|
<TabsList aria-label="规则分节">
|
|
<TabsTrigger value="groups">规则组</TabsTrigger>
|
|
<TabsTrigger value="atoms">自定义条件</TabsTrigger>
|
|
<TabsTrigger value="defaults">默认规则</TabsTrigger>
|
|
<TabsTrigger value="policies">自动收新作品</TabsTrigger>
|
|
<TabsTrigger value="suppressions">已忽略</TabsTrigger>
|
|
</TabsList>
|
|
|
|
<TabsContent value="groups">
|
|
<FilterBar
|
|
search={{
|
|
value: q,
|
|
onChange: (v) => {
|
|
setQ(v);
|
|
setParam("q", v);
|
|
},
|
|
placeholder: "搜索名称",
|
|
}}
|
|
onReset={
|
|
filtered
|
|
? () => {
|
|
setQ("");
|
|
setParams(new URLSearchParams(), { replace: true });
|
|
}
|
|
: undefined
|
|
}
|
|
>
|
|
<FilterSelect
|
|
label="类型"
|
|
value={kind}
|
|
onChange={(v) => setParam("kind", v)}
|
|
options={(Object.keys(RULE_KIND) as RuleGroupKind[]).map((k) => ({
|
|
value: k,
|
|
label: RULE_KIND[k].label,
|
|
}))}
|
|
/>
|
|
<FilterSelect
|
|
label="来源"
|
|
value={source}
|
|
onChange={(v) => {
|
|
setParam("origin", "");
|
|
setParam("source", v);
|
|
}}
|
|
options={(Object.keys(RULE_SOURCE) as RuleGroupSource[]).map((k) => ({
|
|
value: k,
|
|
label: RULE_SOURCE[k],
|
|
}))}
|
|
/>
|
|
<FilterSelect
|
|
label="状态"
|
|
value={enabled}
|
|
onChange={(v) => setParam("enabled", v)}
|
|
options={[
|
|
{ value: "true", label: "启用" },
|
|
{ value: "false", label: "停用" },
|
|
]}
|
|
/>
|
|
</FilterBar>
|
|
<div className="space-y-6">
|
|
{groups.isSuccess && (tags.length > 0 || !filtered) ? <RuleTags rows={tags} onOpen={open} /> : null}
|
|
<RuleGroupTable
|
|
rows={rest}
|
|
loading={groups.isPending}
|
|
error={groups.error}
|
|
onRetry={() => groups.refetch()}
|
|
refs={refs.data}
|
|
filtered={filtered}
|
|
onOpen={open}
|
|
onCreate={create}
|
|
/>
|
|
</div>
|
|
</TabsContent>
|
|
|
|
<TabsContent value="atoms">
|
|
<AtomsTab />
|
|
</TabsContent>
|
|
<TabsContent value="defaults">
|
|
<DefaultsTab groups={all.data?.items} />
|
|
</TabsContent>
|
|
<TabsContent value="policies">
|
|
<PolicyWorkspace creating={creatingPolicy} onCreatingChange={setCreatingPolicy} />
|
|
</TabsContent>
|
|
<TabsContent value="suppressions">
|
|
<SuppressionsTab />
|
|
</TabsContent>
|
|
</Tabs>
|
|
|
|
<RuleGroupEditor
|
|
open={creating || (!!sheet.id && !!editing)}
|
|
group={editing}
|
|
defaultKind={(kind || "acquisition") as RuleGroupKind}
|
|
onOpenChange={(o) => {
|
|
if (o) return;
|
|
if (creating) setCreating(false);
|
|
else sheet.close();
|
|
}}
|
|
/>
|
|
</>
|
|
);
|
|
}
|