🧭 Group annotation stages under one primary tab

This commit is contained in:
eust-w 2026-08-24 02:51:12 +08:00
parent 39d97038e3
commit 52cd656a3f
14 changed files with 171 additions and 45 deletions

View File

@ -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"`
}

View File

@ -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{

View File

@ -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,

View File

@ -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() {
<div>
<h3 className="font-bold text-white">Annotation QA 插件</h3>
<p className="text-xs text-gray-500">
安装后自动增加 {status.manifest.navigation?.length || 0} 个工作台入口和{" "}
安装后增加 {primaryNavigationCount} 个标注中心入口、{status.manifest.navigation?.length || 0} 个阶段视图和{" "}
{status.manifest.operatorIds?.length || 0} 个相关算子。
</p>
</div>

View File

@ -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<string, React.ComponentType<{ className?: string }>> = {
@ -98,6 +103,7 @@ type ProfileDraft = {
};
export function Sidebar({ isCollapsed, onToggle }: SidebarProps) {
const location = useLocation();
const [isProfileModalOpen, setIsProfileModalOpen] = useState(false);
const [profileDraft, setProfileDraft] = useState<ProfileDraft | null>(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",
)
}
);
}}
>
<item.icon className="w-4 h-4 shrink-0" />
{!isCollapsed && <span className="truncate">{item.label}</span>}

View File

@ -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]);
}

View File

@ -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() {
<div className="flex flex-wrap items-center justify-between gap-3">
<div className="min-w-0 flex-1">
<h1 className="text-2xl font-semibold text-white">{workspaceTitle}</h1>
<PageSubnav
compact
items={[
{ label: queueTabLabel, active: tab === "queue", onSelect: () => 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="当前工作台内部导航"
/>
<PageSubnav compact items={annotationStageTabs} label="标注中心阶段导航" />
</div>
<div className="flex items-center gap-2">
<select
className={inputClass}
value={tab}
onChange={(event) => setTab(event.target.value as Tab)}
aria-label="当前工作台视图"
>
<option value="queue">{queueTabLabel}</option>
<option value="rejects">拒绝区</option>
<option value="templates">模板版本</option>
<option value="groups">供应商与角色</option>
<option value="workload">工时统计</option>
</select>
{isManager ? (
<Link
to={`/sampling${projectId ? `?projectId=${encodeURIComponent(projectId)}` : ""}`}

View File

@ -36,6 +36,9 @@ export default function Plugins() {
<div className="grid gap-4 md:grid-cols-2">
{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 (
<article key={status.manifest.id} className="rounded-xl border border-[#2a2b2f] bg-[#151619] p-5">
<div className="flex items-start justify-between gap-4">
@ -64,8 +67,8 @@ export default function Plugins() {
</div>
<div className="mt-5 grid grid-cols-3 gap-3 text-center text-xs text-gray-500">
<div className="rounded-lg border border-[#2a2b2f] bg-[#101114] px-2 py-3">
<div className="text-lg font-semibold text-white">{status.manifest.navigation?.length || 0}</div>
页面入口
<div className="text-lg font-semibold text-white">{primaryNavigationCount}</div>
一级入口
</div>
<div className="rounded-lg border border-[#2a2b2f] bg-[#101114] px-2 py-3">
<div className="text-lg font-semibold text-white">{status.manifest.operatorIds?.length || 0}</div>

View File

@ -488,6 +488,9 @@ export interface PluginManifest {
label: string;
icon?: string;
order?: number;
groupId?: string;
groupLabel?: string;
groupIcon?: string;
requiredRoles?: string[];
}>;
workflowCapabilities?: string[];

View File

@ -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".*\]/);

View File

@ -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"\)/);
});

View File

@ -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: "抽检任务"/);
});

View File

@ -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");

View File

@ -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, /<PluginSettingsPanel \/>/);
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, /<option value="queue">{queueTabLabel}<\/option>/);
assert.match(annotation, /<option value="workload">工时统计<\/option>/);
assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/);
assert.doesNotMatch(annotation, /Annotation Operations|标注中心(人工标注)工作台/);
assert.doesNotMatch(annotation, /data-testid="role-workbenches"/);
});