diff --git a/internal/domain/plugins.go b/internal/domain/plugins.go index 246fb795..6e84ef07 100644 --- a/internal/domain/plugins.go +++ b/internal/domain/plugins.go @@ -13,6 +13,9 @@ type PluginNavigationContribution struct { Path string `json:"path"` Icon string `json:"icon,omitempty"` Order int `json:"order,omitempty"` + GroupID string `json:"groupId,omitempty"` + GroupLabel string `json:"groupLabel,omitempty"` + GroupIcon string `json:"groupIcon,omitempty"` RequiredRoles []string `json:"requiredRoles,omitempty"` } diff --git a/internal/plugins/registry.go b/internal/plugins/registry.go index 83c6e267..8bf74242 100644 --- a/internal/plugins/registry.go +++ b/internal/plugins/registry.go @@ -30,11 +30,11 @@ var builtin = map[string]domain.PluginManifest{ {ID: "item", Path: "/plugins/annotation-qa/items/:itemId", Label: "标注任务详情"}, }, Navigation: []domain.PluginNavigationContribution{ - {ID: "annotate", Label: "标注员工作台 · 语义标注", Path: "/plugins/annotation-qa/workflows/all/annotate", Icon: "tags", Order: 10, RequiredRoles: []string{"admin", "annotator"}}, - {ID: "quality", Label: "审核员工作台 · 标注审核", Path: "/plugins/annotation-qa/workflows/all/quality", Icon: "clipboard-check", Order: 20, RequiredRoles: []string{"admin", "quality_reviewer"}}, - {ID: "clip", Label: "剪切员工作台 · 调切/粗切", Path: "/plugins/annotation-qa/workflows/all/clip", Icon: "scissors", Order: 30, RequiredRoles: []string{"admin", "annotator"}}, - {ID: "clip-quality", Label: "标注员工作台 · 剪切审核", Path: "/plugins/annotation-qa/workflows/all/clip-quality", Icon: "shield-check", Order: 40, RequiredRoles: []string{"admin", "quality_reviewer", "annotator"}}, - {ID: "acceptance", Label: "最终验收", Path: "/plugins/annotation-qa/workflows/all/acceptance", Icon: "shield-check", Order: 50, RequiredRoles: []string{"admin", "acceptance_reviewer"}}, + {ID: "annotate", Label: "语义标注", Path: "/plugins/annotation-qa/workflows/all/annotate", Icon: "tags", Order: 10, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "annotator"}}, + {ID: "quality", Label: "标注审核", Path: "/plugins/annotation-qa/workflows/all/quality", Icon: "clipboard-check", Order: 20, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "quality_reviewer"}}, + {ID: "clip", Label: "调切/粗切", Path: "/plugins/annotation-qa/workflows/all/clip", Icon: "scissors", Order: 30, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "annotator"}}, + {ID: "clip-quality", Label: "剪切审核", Path: "/plugins/annotation-qa/workflows/all/clip-quality", Icon: "shield-check", Order: 40, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "quality_reviewer", "annotator"}}, + {ID: "acceptance", Label: "最终验收", Path: "/plugins/annotation-qa/workflows/all/acceptance", Icon: "shield-check", Order: 50, GroupID: "annotation-center", GroupLabel: "标注中心", GroupIcon: "tags", RequiredRoles: []string{"admin", "acceptance_reviewer"}}, }, WorkflowCapabilities: []string{"human_cut_adjustment", "human_cut_review", "human_annotation", "human_quality_review", "human_acceptance"}, OperatorIDs: []string{ diff --git a/internal/plugins/registry_test.go b/internal/plugins/registry_test.go index f5f621b3..98800e27 100644 --- a/internal/plugins/registry_test.go +++ b/internal/plugins/registry_test.go @@ -34,6 +34,11 @@ func TestAnnotationManifestContributesWorkbenchesAndOperators(t *testing.T) { if manifest.Navigation[0].ID != "annotate" || manifest.Navigation[4].ID != "acceptance" { t.Fatalf("unexpected navigation order: %#v", manifest.Navigation) } + for _, item := range manifest.Navigation { + if item.GroupID != "annotation-center" || item.GroupLabel != "标注中心" || item.GroupIcon != "tags" { + t.Fatalf("annotation navigation must share one primary group: %#v", item) + } + } wanted := map[string]bool{ "operator-builtin-annotation-gate": true, "operator-builtin-audit-sample": true, diff --git a/src/components/PluginSettingsPanel.tsx b/src/components/PluginSettingsPanel.tsx index b02271a5..335c33fe 100644 --- a/src/components/PluginSettingsPanel.tsx +++ b/src/components/PluginSettingsPanel.tsx @@ -37,6 +37,8 @@ export default function PluginSettingsPanel() { maxReworkRounds: 5, ...(status.config || {}), }; + const primaryNavigationCount = new Set((status.manifest.navigation || []).map((item) => item.groupId || item.id)) + .size; const updateConfig = (key: string, value: string | number) => setStatus((current) => (current ? { ...current, config: { ...config, [key]: value } } : current)); const save = async () => { @@ -64,7 +66,7 @@ export default function PluginSettingsPanel() {

Annotation QA 插件

- 安装后自动增加 {status.manifest.navigation?.length || 0} 个工作台入口和{" "} + 安装后增加 {primaryNavigationCount} 个标注中心入口、{status.manifest.navigation?.length || 0} 个阶段视图和{" "} {status.manifest.operatorIds?.length || 0} 个相关算子。

diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx index e2b756ac..7308e003 100644 --- a/src/components/Sidebar.tsx +++ b/src/components/Sidebar.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useMemo, useState } from "react"; -import { NavLink } from "react-router-dom"; +import { NavLink, useLocation } from "react-router-dom"; import { Logo } from "./Logo"; import { useUser } from "../context/UserContext"; import { @@ -30,7 +30,11 @@ import { } from "lucide-react"; import { cn } from "../lib/utils"; import { getActionErrorMessage } from "../lib/action-errors.js"; -import { getPluginNavigationContributions, resolvePluginNavigationRole } from "../lib/plugin-navigation.js"; +import { + getPluginPrimaryNavigationContributions, + matchesPluginNavigationPath, + resolvePluginNavigationRole, +} from "../lib/plugin-navigation.js"; import { getUserRoleLabel } from "../lib/user-roles"; import { usePlugins } from "../context/PluginContext"; @@ -39,6 +43,7 @@ type NavigationItem = { label: string; path: string; roles: readonly string[]; + matchPaths?: readonly string[]; }; const pluginNavigationIcons: Record> = { @@ -98,6 +103,7 @@ type ProfileDraft = { }; export function Sidebar({ isCollapsed, onToggle }: SidebarProps) { + const location = useLocation(); const [isProfileModalOpen, setIsProfileModalOpen] = useState(false); const [profileDraft, setProfileDraft] = useState(null); const [profileError, setProfileError] = useState(""); @@ -121,11 +127,12 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) { return []; } const effectiveRole = resolvePluginNavigationRole(role); - const pluginItems: NavigationItem[] = getPluginNavigationContributions(pluginStatuses, role).map((item) => ({ + const pluginItems: NavigationItem[] = getPluginPrimaryNavigationContributions(pluginStatuses, role).map((item) => ({ icon: pluginNavigationIcons[item.icon] || Blocks, label: item.label, path: item.path, roles: item.requiredRoles || ["admin"], + matchPaths: item.matchPaths, })); const insertionIndex = navItems.findIndex((item) => item.path === "/users"); const allItems = @@ -187,13 +194,15 @@ export function Sidebar({ isCollapsed, onToggle }: SidebarProps) { key={item.path} to={item.path} title={isCollapsed ? item.label : undefined} - className={({ isActive }) => - cn( + className={({ isActive }) => { + const active = + isActive || item.matchPaths?.some((path) => matchesPluginNavigationPath(location.pathname, path)); + return cn( "flex items-center gap-3 px-3 py-2 rounded-md text-sm font-medium transition-colors", - isActive ? "bg-blue-600/10 text-blue-400" : "text-gray-400 hover:text-white hover:bg-white/5", + active ? "bg-blue-600/10 text-blue-400" : "text-gray-400 hover:text-white hover:bg-white/5", isCollapsed && "justify-center px-0", - ) - } + ); + }} > {!isCollapsed && {item.label}} diff --git a/src/lib/plugin-navigation.js b/src/lib/plugin-navigation.js index 5eaad43f..11eba1cb 100644 --- a/src/lib/plugin-navigation.js +++ b/src/lib/plugin-navigation.js @@ -21,3 +21,31 @@ export function getPluginNavigationContributions(statuses, role) { .filter((item) => !item.requiredRoles?.length || item.requiredRoles.includes(effectiveRole)) .sort((left, right) => (left.order || 0) - (right.order || 0)); } + +export function getPluginPrimaryNavigationContributions(statuses, role) { + const items = getPluginNavigationContributions(statuses, role); + const grouped = new Map(); + for (const item of items) { + const key = `${item.pluginId}:${item.groupId || item.id}`; + const existing = grouped.get(key); + if (existing) { + existing.matchPaths.push(item.path); + continue; + } + grouped.set(key, { + ...item, + id: item.groupId || item.id, + label: item.groupLabel || item.label, + icon: item.groupIcon || item.icon, + matchPaths: [item.path], + }); + } + return Array.from(grouped.values()).sort((left, right) => (left.order || 0) - (right.order || 0)); +} + +export function matchesPluginNavigationPath(pathname, contributedPath) { + const current = pathname.split("?")[0].split("/").filter(Boolean); + const target = contributedPath.split("?")[0].split("/").filter(Boolean); + if (current.length < target.length) return false; + return target.every((segment, index) => segment === "all" || segment === current[index]); +} diff --git a/src/pages/AnnotationOperations.tsx b/src/pages/AnnotationOperations.tsx index 530c7d9e..4e90e578 100644 --- a/src/pages/AnnotationOperations.tsx +++ b/src/pages/AnnotationOperations.tsx @@ -52,7 +52,9 @@ import { artifactContentPath } from "../lib/artifact-download.js"; import AnnotationTimelineEditor from "../components/AnnotationTimelineEditor"; import RerunArtifactPreview from "../components/RerunArtifactPreview"; import { PageSubnav } from "../components/PageSubnav"; +import { usePlugins } from "../context/PluginContext"; import { buildBrowserPlayableVideoURL } from "../lib/video-preview.js"; +import { getPluginNavigationContributions } from "../lib/plugin-navigation.js"; type Tab = "queue" | "rejects" | "templates" | "groups" | "workload"; type WorkspaceMode = "clip" | "clip-quality" | "annotate" | "quality" | "acceptance"; @@ -161,6 +163,7 @@ function taskVisibleInMode(task: AnnotationTaskRecord, mode: WorkspaceMode) { export default function AnnotationOperations() { const { users, role, currentUser } = useUser(); + const { statuses: pluginStatuses } = usePlugins(); const { timeZone } = useTimeZone(); const [searchParams, setSearchParams] = useSearchParams(); const location = useLocation(); @@ -235,6 +238,20 @@ export default function AnnotationOperations() { const [previewTab, setPreviewTab] = useState<"video" | "rerun">("video"); const isManager = role === "admin"; + const annotationStageTabs = useMemo( + () => + role + ? getPluginNavigationContributions(pluginStatuses, role).map((item) => { + const path = item.path.replace("/workflows/all/", `/workflows/${requestedWorkflowId || "all"}/`); + return { + label: item.label, + to: `${path}${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ""}`, + match: [path], + }; + }) + : [], + [pluginStatuses, projectId, requestedWorkflowId, role], + ); const loadBase = useCallback(async () => { setLoading(true); @@ -960,19 +977,21 @@ export default function AnnotationOperations() {

{workspaceTitle}

- setTab("queue") }, - { label: "拒绝区", active: tab === "rejects", onSelect: () => setTab("rejects") }, - { label: "模板版本", active: tab === "templates", onSelect: () => setTab("templates") }, - { label: "供应商与角色", active: tab === "groups", onSelect: () => setTab("groups") }, - { label: "工时统计", active: tab === "workload", onSelect: () => setTab("workload") }, - ]} - label="当前工作台内部导航" - /> +
+ {isManager ? ( {statuses.map((status) => { const installed = status.enabled || status.manifest.system; + const primaryNavigationCount = new Set( + (status.manifest.navigation || []).map((item) => item.groupId || item.id), + ).size; return (
@@ -64,8 +67,8 @@ export default function Plugins() {
-
{status.manifest.navigation?.length || 0}
- 页面入口 +
{primaryNavigationCount}
+ 一级入口
{status.manifest.operatorIds?.length || 0}
diff --git a/src/types.ts b/src/types.ts index 38151d49..dd15e0a8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -488,6 +488,9 @@ export interface PluginManifest { label: string; icon?: string; order?: number; + groupId?: string; + groupLabel?: string; + groupIcon?: string; requiredRoles?: string[]; }>; workflowCapabilities?: string[]; diff --git a/tests/frontend/fanyu-comment-followup.test.mjs b/tests/frontend/fanyu-comment-followup.test.mjs index 00c599c4..c7c9238b 100644 --- a/tests/frontend/fanyu-comment-followup.test.mjs +++ b/tests/frontend/fanyu-comment-followup.test.mjs @@ -29,11 +29,14 @@ test("dashboard renders platform vendor and self workforce scopes", async () => test("human roles see only their assigned navigation surfaces", async () => { const [sidebar, registry] = await Promise.all([readFile(sidebarURL, "utf8"), readFile(pluginRegistryURL, "utf8")]); assert.match(sidebar, /roles: \["admin", "quality_reviewer", "acceptance_reviewer", "supplier_manager"\]/); - assert.match(sidebar, /getPluginNavigationContributions\(pluginStatuses, role\)/); - assert.match(registry, /Label: "标注员工作台 · 语义标注"[\s\S]*RequiredRoles: \[\]string\{"admin", "annotator"\}/); + assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/); assert.match( registry, - /Label: "审核员工作台 · 标注审核"[\s\S]*RequiredRoles: \[\]string\{"admin", "quality_reviewer"\}/, + /Label: "语义标注"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "annotator"\}/, + ); + assert.match( + registry, + /Label: "标注审核"[\s\S]*GroupLabel: "标注中心"[\s\S]*RequiredRoles: \[\]string\{"admin", "quality_reviewer"\}/, ); assert.match(registry, /Label: "最终验收"[\s\S]*RequiredRoles: \[\]string\{"admin", "acceptance_reviewer"\}/); assert.doesNotMatch(sidebar, /path: "\/monitoring",\s+roles: \[.*"supplier_manager".*\]/); diff --git a/tests/frontend/fanyu-v5-four-stage.test.mjs b/tests/frontend/fanyu-v5-four-stage.test.mjs index cad9cd31..570e2c58 100644 --- a/tests/frontend/fanyu-v5-four-stage.test.mjs +++ b/tests/frontend/fanyu-v5-four-stage.test.mjs @@ -28,9 +28,10 @@ test("annotator and reviewer each have the required cut workbench route", async const sidebar = await readFile(sidebarURL, "utf8"); const app = await readFile(appURL, "utf8"); const registry = await readFile(pluginRegistryURL, "utf8"); - assert.match(sidebar, /getPluginNavigationContributions\(pluginStatuses, role\)/); - assert.match(registry, /ID: "clip"[\s\S]*Label: "剪切员工作台 · 调切\/粗切"/); - assert.match(registry, /ID: "clip-quality"[\s\S]*Label: "标注员工作台 · 剪切审核"/); + assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/); + assert.match(registry, /ID: "clip"[\s\S]*Label: "调切\/粗切"/); + assert.match(registry, /ID: "clip-quality"[\s\S]*Label: "剪切审核"/); + assert.match(registry, /GroupID: "annotation-center"[\s\S]*GroupLabel: "标注中心"/); assert.match(app, /path\.endsWith\("\/annotate"\) \|\| path\.endsWith\("\/clip"\)/); }); diff --git a/tests/frontend/object-sync.test.mjs b/tests/frontend/object-sync.test.mjs index 81d2dea8..b4589003 100644 --- a/tests/frontend/object-sync.test.mjs +++ b/tests/frontend/object-sync.test.mjs @@ -79,7 +79,7 @@ test("drosync stays reachable from data storage without becoming a ninth primary for (const label of ["仪表盘", "项目管理", "工作流", "算子库", "数据存储", "用户管理"]) { assert.match(sidebar, new RegExp(`label: "${label}"`)); } - assert.match(sidebar, /getPluginNavigationContributions\(pluginStatuses, role\)/); + assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/); assert.doesNotMatch(sidebar, /label: "任务审核"|label: "抽检任务"/); }); diff --git a/tests/frontend/plugin-navigation.test.mjs b/tests/frontend/plugin-navigation.test.mjs index 10feff84..35b1de14 100644 --- a/tests/frontend/plugin-navigation.test.mjs +++ b/tests/frontend/plugin-navigation.test.mjs @@ -1,15 +1,36 @@ import assert from "node:assert/strict"; import test from "node:test"; -import { getPluginNavigationContributions, resolvePluginNavigationRole } from "../../src/lib/plugin-navigation.js"; +import { + getPluginNavigationContributions, + getPluginPrimaryNavigationContributions, + matchesPluginNavigationPath, + resolvePluginNavigationRole, +} from "../../src/lib/plugin-navigation.js"; const annotationStatus = { enabled: true, manifest: { id: "annotation-qa", navigation: [ - { id: "quality", label: "审核", path: "/quality", order: 20, requiredRoles: ["admin", "quality_reviewer"] }, - { id: "annotate", label: "标注", path: "/annotate", order: 10, requiredRoles: ["admin", "annotator"] }, + { + id: "quality", + label: "审核", + path: "/quality", + order: 20, + groupId: "annotation-center", + groupLabel: "标注中心", + requiredRoles: ["admin", "quality_reviewer"], + }, + { + id: "annotate", + label: "标注", + path: "/annotate", + order: 10, + groupId: "annotation-center", + groupLabel: "标注中心", + requiredRoles: ["admin", "annotator"], + }, ], }, }; @@ -26,6 +47,33 @@ test("plugin navigation appears only after installation and respects roles", () ); }); +test("plugin workbench stages collapse to one role-aware primary entry", () => { + const adminItems = getPluginPrimaryNavigationContributions([annotationStatus], "admin"); + assert.deepEqual( + adminItems.map((item) => [item.label, item.path]), + [["标注中心", "/annotate"]], + ); + assert.deepEqual(adminItems[0].matchPaths, ["/annotate", "/quality"]); + assert.deepEqual( + getPluginPrimaryNavigationContributions([annotationStatus], "quality_reviewer").map((item) => [ + item.label, + item.path, + ]), + [["标注中心", "/quality"]], + ); +}); + +test("grouped plugin primary entry stays active on every contributed stage route", () => { + assert.equal( + matchesPluginNavigationPath( + "/plugins/annotation-qa/workflows/workflow-1/quality", + "/plugins/annotation-qa/workflows/all/quality", + ), + true, + ); + assert.equal(matchesPluginNavigationPath("/plugins/another-plugin/workflows/workflow-1/quality", "/quality"), false); +}); + test("plugin navigation preserves legacy role compatibility", () => { assert.equal(resolvePluginNavigationRole("data_operator"), "annotator"); assert.equal(resolvePluginNavigationRole("qa_reviewer"), "quality_reviewer"); diff --git a/tests/frontend/plugin-page-subnav.test.mjs b/tests/frontend/plugin-page-subnav.test.mjs index 92c4f838..29118778 100644 --- a/tests/frontend/plugin-page-subnav.test.mjs +++ b/tests/frontend/plugin-page-subnav.test.mjs @@ -16,7 +16,8 @@ test("plugin management is a dedicated admin page", async () => { assert.match(sidebar, /label: "插件管理", path: "\/plugins"/); assert.doesNotMatch(settings, /PluginSettingsPanel/); assert.match(plugins, //); - assert.match(plugins, /status\.manifest\.navigation\?\.length/); + assert.match(plugins, /primaryNavigationCount/); + assert.match(plugins, /一级入口/); assert.match(plugins, /status\.manifest\.operatorIds\?\.length/); }); @@ -60,14 +61,15 @@ test("only pages with real internal views render secondary navigation", async () } }); -test("annotation secondary navigation stays inside the selected workbench", async () => { +test("annotation stages are secondary navigation under one primary center", async () => { const annotation = await source("src/pages/AnnotationOperations.tsx"); - assert.doesNotMatch(annotation, /getPluginNavigationContributions|pluginStatuses|annotationSubnav/); - assert.match(annotation, /compact[\s\S]*label: queueTabLabel[\s\S]*setTab\("queue"\)/); - assert.match(annotation, /label: "拒绝区"[\s\S]*setTab\("rejects"\)/); - assert.match(annotation, /label: "模板版本"[\s\S]*setTab\("templates"\)/); - assert.match(annotation, /label: "供应商与角色"[\s\S]*setTab\("groups"\)/); - assert.match(annotation, /label: "工时统计"[\s\S]*setTab\("workload"\)/); + const sidebar = await source("src/components/Sidebar.tsx"); + assert.match(annotation, /getPluginNavigationContributions\(pluginStatuses, role\)/); + assert.match(annotation, /items={annotationStageTabs}/); + assert.match(annotation, /aria-label="当前工作台视图"/); + assert.match(annotation, /