fix(evaluation-groups): 修复一级分组显示错误和 React key 警告
## 修复内容
### 1. 修复一级分组过滤问题
- **问题**: getEvaluationPointGroups 函数忽略了 pid 参数,导致返回所有分组(包括二级分组)
- **修复**: 添加 pid 参数处理逻辑,支持传递 "null" 字符串来查询一级分组
- **文件**: app/api/evaluation_points/rule-groups.ts:1186-1198
### 2. 修复 React key 重复警告
- **问题**: 父分组和子分组可能有相同的 ID,导致 "Encountered two children with the same key" 警告
- **修复**: 将 rowKey 从简单的 "id" 改为根据 isParent 生成唯一 key
- **文件**: app/routes/rule-groups._index.tsx:817
### 3. 新增后端 API 规范文档
- **文件**: docs/evaluation/evaluation_point_groups_backend_api_spec.md
- **内容**:
- 完整的 9 个 FastAPI v3 接口规范
- Python Pydantic 模型定义
- TypeScript 接口定义
- pid 参数处理说明(字符串 "null" 转换为 None)
- 10 个完整测试用例
- 数据库表结构建议
## 技术细节
**pid 参数处理**:
```typescript
// 前端发送
GET /api/v3/evaluation-point-groups?pid=null&page=1
// 后端需要识别字符串 "null" 并转换为 None/NULL
if (pid == "null") {
query = query.filter(EvaluationPointGroup.pid.is_(None))
}
```
**唯一 key 生成**:
```typescript
rowKey={(record) => record.isParent ? `parent-${record.id}` : `child-${record.id}`}
```
🔗 相关文档: docs/evaluation/evaluation_point_groups_backend_api_spec.md
This commit is contained in:
@@ -1171,6 +1171,7 @@ export async function getEvaluationPointGroups(
|
||||
name,
|
||||
code,
|
||||
is_enabled,
|
||||
pid,
|
||||
orderBy = 'created_at',
|
||||
order = 'desc'
|
||||
} = params || {};
|
||||
@@ -1182,6 +1183,19 @@ export async function getEvaluationPointGroups(
|
||||
if (name) queryParams.append('name', name);
|
||||
if (code) queryParams.append('code', code);
|
||||
if (is_enabled !== undefined) queryParams.append('is_enabled', String(is_enabled));
|
||||
// 🔑 添加 pid 参数过滤
|
||||
// pid=null 或 pid='0' 表示只查询一级分组,后端需要识别字符串 "null"
|
||||
// 如果 pid 未定义,则不传该参数(默认查询所有分组)
|
||||
if (pid !== undefined) {
|
||||
if (pid === null || pid === '0') {
|
||||
// 方案1:传递字符串 "null",后端需要识别并转换为 None/NULL
|
||||
queryParams.append('pid', 'null');
|
||||
// 方案2:不传参数,后端默认查询一级分组(需要后端支持)
|
||||
// 不添加 pid 参数
|
||||
} else {
|
||||
queryParams.append('pid', String(pid));
|
||||
}
|
||||
}
|
||||
|
||||
const url = `/api/v3/evaluation-point-groups?${queryParams.toString()}`;
|
||||
|
||||
|
||||
@@ -814,7 +814,7 @@ export default function RuleGroupsIndex() {
|
||||
<Table
|
||||
columns={columns}
|
||||
dataSource={processedData}
|
||||
rowKey="id"
|
||||
rowKey={(record) => record.isParent ? `parent-${record.id}` : `child-${record.id}`}
|
||||
emptyText="暂无分组数据"
|
||||
className="tree-table"
|
||||
/>
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user