Files
AIclinicalresearch/frontend-v2/src/modules/dc/hooks/useAssets.ts
HaHafeng 91cab452d1 fix(dc/tool-c): Fix special character handling and improve UX
Major fixes:
- Fix pivot transformation with special characters in column names
- Fix compute column validation for Chinese punctuation
- Fix recode dialog to fetch unique values from full dataset via new API
- Add column mapping mechanism to handle special characters

Database migration:
- Add column_mapping field to dc_tool_c_sessions table
- Migration file: 20251208_add_column_mapping

UX improvements:
- Darken table grid lines for better visibility
- Reduce column width by 40% with tooltip support
- Insert new columns next to source columns
- Preserve original row order after operations
- Add notice about 50-row preview limit

Modified files:
- Backend: SessionService, SessionController, QuickActionService, routes
- Python: pivot.py, compute.py, recode.py, binning.py, conditional.py
- Frontend: DataGrid, RecodeDialog, index.tsx, ag-grid-custom.css
- Database: schema.prisma, migration SQL

Status: Code complete, database migrated, ready for testing
2025-12-08 23:20:55 +08:00

113 lines
2.6 KiB
TypeScript

/**
* DC模块 - 数据资产Hook
*
* 管理数据资产库的状态和数据获取
*/
import { useState, useEffect } from 'react';
import type { Asset, AssetTabType } from '../types/portal';
// Mock数据
const mockAssets: Asset[] = [
{
id: 'asset-001',
name: '2025糖尿病研究_AI提取结果.xlsx',
type: 'processed',
source: 'tool-b',
rowCount: 150,
tags: ['糖尿病', 'AI结构化'],
modifiedAt: '2025-12-01T11:45:00Z',
fileSize: 245760,
fileKey: 'dc/outputs/task-001-result.xlsx'
},
{
id: 'asset-002',
name: '高血压病历原始数据.xlsx',
type: 'raw',
source: 'upload',
rowCount: 320,
tags: ['高血压', '原始数据'],
modifiedAt: '2025-12-02T09:00:00Z',
fileSize: 512000,
fileKey: 'dc/uploads/hypertension-raw.xlsx'
},
{
id: 'asset-003',
name: '多中心数据合并结果.xlsx',
type: 'processed',
source: 'tool-a',
rowCount: 580,
tags: ['多中心', '数据合并'],
modifiedAt: '2025-11-30T16:20:00Z',
fileSize: 1048576,
fileKey: 'dc/outputs/merged-data.xlsx'
}
];
export const useAssets = (activeTab: AssetTabType) => {
const [assets, setAssets] = useState<Asset[]>([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
// 获取资产列表
const fetchAssets = async () => {
try {
setLoading(true);
// TODO: 替换为真实API调用
// const response = await fetch(`/api/v1/dc/assets?type=${activeTab}`);
// const data = await response.json();
// 模拟API延迟
await new Promise(resolve => setTimeout(resolve, 300));
// 根据Tab筛选
let filteredAssets = mockAssets;
if (activeTab === 'processed') {
filteredAssets = mockAssets.filter(a => a.type === 'processed');
} else if (activeTab === 'raw') {
filteredAssets = mockAssets.filter(a => a.type === 'raw');
}
setAssets(filteredAssets);
setError(null);
} catch (err) {
setError(err instanceof Error ? err.message : '获取资产列表失败');
} finally {
setLoading(false);
}
};
useEffect(() => {
fetchAssets();
}, [activeTab]);
// 刷新资产列表
const refresh = () => {
fetchAssets();
};
// 删除资产
const deleteAsset = async (id: string) => {
// TODO: 实现删除逻辑
console.log('Delete asset:', id);
setAssets(assets.filter(a => a.id !== id));
};
return {
assets,
loading,
error,
refresh,
deleteAsset
};
};