RoleProcessTree.tsx
1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
// REQ-USR-003: 左侧角色/流程树(按角色/按流程分组 + 计数;点击高亮,不取数,BR11)。
import { useState } from 'react';
import type { GroupItem } from './dashboardData';
import styles from './HomePage.module.css';
interface RoleProcessTreeProps {
roleGroups: GroupItem[];
processGroups: GroupItem[];
onSelect?: (label: string) => void;
}
export default function RoleProcessTree({
roleGroups,
processGroups,
onSelect,
}: RoleProcessTreeProps) {
// 本地高亮态:默认高亮「所有部门」(复刻原型首项 active)
const [activeLabel, setActiveLabel] = useState<string>('所有部门');
const handleClick = (label: string) => {
setActiveLabel(label);
onSelect?.(label);
};
const renderItem = (g: GroupItem, keyPrefix: string) => (
<button
type="button"
key={`${keyPrefix}-${g.label}`}
className={`${styles.treeItem} ${activeLabel === g.label ? styles.treeItemActive : ''}`}
aria-pressed={activeLabel === g.label}
onClick={() => handleClick(g.label)}
>
{g.label} ({g.count})
</button>
);
return (
<div className={`${styles.leftNav} ${styles.tree}`} data-testid="role-tree">
<div className={styles.treeGroup}>按角色</div>
{roleGroups.map((g) => renderItem(g, 'role'))}
<div className={styles.treeGroup}>按流程</div>
{processGroups.map((g) => renderItem(g, 'proc'))}
</div>
);
}