diff --git a/web/app/components/evaluation/components/batch-test-panel/history-tab.tsx b/web/app/components/evaluation/components/batch-test-panel/history-tab.tsx index 728b3e6c99..7080e175c4 100644 --- a/web/app/components/evaluation/components/batch-test-panel/history-tab.tsx +++ b/web/app/components/evaluation/components/batch-test-panel/history-tab.tsx @@ -1,47 +1,163 @@ -import type { BatchTestRecord } from '../../types' +import type { EvaluationResourceProps } from '../../types' +import type { EvaluationLogFile } from '@/types/evaluation' +import { keepPreviousData, useMutation, useQuery } from '@tanstack/react-query' +import { useState } from 'react' import { useTranslation } from 'react-i18next' -import Badge from '@/app/components/base/badge' +import Pagination from '@/app/components/base/pagination' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuTrigger, +} from '@/app/components/base/ui/dropdown-menu' +import { consoleClient, consoleQuery } from '@/service/client' +import { downloadUrl } from '@/utils/download' -type HistoryTabProps = { - batchRecords: BatchTestRecord[] +const PAGE_SIZE = 16 +const LOADING_ROW_IDS = ['1', '2', '3', '4', '5', '6'] + +const formatCreatedAt = (createdAt: string) => { + if (!createdAt) + return '-' + + return createdAt.includes('T') ? createdAt.slice(0, 10) : createdAt } -const HistoryTab = ({ batchRecords }: HistoryTabProps) => { +const HistoryTab = ({ + resourceType, + resourceId, +}: EvaluationResourceProps) => { const { t } = useTranslation('evaluation') - const statusLabels = { - running: t('batch.status.running'), - success: t('batch.status.success'), - failed: t('batch.status.failed'), - } + const [page, setPage] = useState(0) + const logsQuery = useQuery({ + ...consoleQuery.evaluation.logs.queryOptions({ + input: { + params: { + targetType: resourceType, + targetId: resourceId, + }, + query: { + page: page + 1, + page_size: PAGE_SIZE, + }, + }, + refetchOnWindowFocus: false, + }), + placeholderData: keepPreviousData, + }) + const fileDownloadMutation = useMutation({ + mutationFn: async (file: EvaluationLogFile) => { + const fileInfo = await consoleClient.evaluation.file({ + params: { + targetType: resourceType, + targetId: resourceId, + fileId: file.id, + }, + }) + + downloadUrl({ url: fileInfo.download_url, fileName: file.name }) + }, + }) + const records = logsQuery.data?.data ?? [] + const total = logsQuery.data?.total ?? 0 + const isInitialLoading = logsQuery.isLoading && !logsQuery.data return ( -
- {batchRecords.length === 0 && ( -
- {t('batch.emptyHistory')} -
- )} - {batchRecords.map(record => ( -
-
-
-
{record.summary}
-
{record.fileName}
-
- - {record.status === 'running' - ? ( - - - ) - : statusLabels[record.status]} - +
+
+ + + + + + + + + + + + + + + + + + + {isInitialLoading && LOADING_ROW_IDS.map(rowId => ( + + + + ))} + {!isInitialLoading && records.map(record => ( + + + + + + + + ))} + +
+ + {t('history.columns.time')} + + {t('history.columns.creator')}{t('history.columns.version')}{t('history.columns.status')} +
+
+
{formatCreatedAt(record.created_at)}{record.created_by}{record.version || '-'} + {record.result_file + ? + : } + + + + )} + > + + + fileDownloadMutation.mutate(record.test_file)} + > + + record.result_file && fileDownloadMutation.mutate(record.result_file)} + > + + + +
+ {!isInitialLoading && records.length === 0 && ( +
+ {t('history.empty')}
-
{record.startedAt}
-
- ))} + )} +
+ {total > PAGE_SIZE && ( + + )}
) } diff --git a/web/app/components/evaluation/components/batch-test-panel/index.tsx b/web/app/components/evaluation/components/batch-test-panel/index.tsx index 818f83e5d5..78aac12787 100644 --- a/web/app/components/evaluation/components/batch-test-panel/index.tsx +++ b/web/app/components/evaluation/components/batch-test-panel/index.tsx @@ -76,7 +76,7 @@ const BatchTestPanel = ({ onUploadFileNameChange={uploadedFileName => setUploadedFileName(resourceType, resourceId, uploadedFileName)} /> )} - {resource.activeBatchTab === 'history' && } + {resource.activeBatchTab === 'history' && }
) diff --git a/web/i18n/en-US/evaluation.json b/web/i18n/en-US/evaluation.json index 33191cd39a..3558d5e9e2 100644 --- a/web/i18n/en-US/evaluation.json +++ b/web/i18n/en-US/evaluation.json @@ -47,6 +47,9 @@ "conditions.valueTypes.number": "Number", "conditions.valueTypes.string": "String", "description": "Configure automated testing to grade your application's performance.", + "history.actions.downloadResultFile": "Download result", + "history.actions.downloadTestFile": "Download test file", + "history.actions.open": "Open history actions", "history.columns.creator": "Creator", "history.columns.status": "Status", "history.columns.time": "Time", @@ -55,6 +58,8 @@ "history.empty": "No test history yet", "history.latestVersion": "Latest", "history.searchPlaceholder": "Search", + "history.status.completed": "Completed", + "history.status.running": "Running", "history.title": "Test History", "judgeModel.description": "Choose the model used to score your evaluation results.", "judgeModel.title": "Judge Model", diff --git a/web/i18n/zh-Hans/evaluation.json b/web/i18n/zh-Hans/evaluation.json index 04883d95e1..db167bf50d 100644 --- a/web/i18n/zh-Hans/evaluation.json +++ b/web/i18n/zh-Hans/evaluation.json @@ -47,6 +47,20 @@ "conditions.valueTypes.number": "数值", "conditions.valueTypes.string": "文本", "description": "配置自动化测试,对应用表现进行评分。", + "history.actions.downloadResultFile": "下载结果文件", + "history.actions.downloadTestFile": "下载测试文件", + "history.actions.open": "打开历史记录操作", + "history.columns.creator": "创建人", + "history.columns.status": "状态", + "history.columns.time": "时间", + "history.columns.version": "版本", + "history.creatorYou": "你", + "history.empty": "还没有测试历史", + "history.latestVersion": "最新", + "history.searchPlaceholder": "搜索", + "history.status.completed": "已完成", + "history.status.running": "运行中", + "history.title": "测试历史", "judgeModel.description": "选择用于打分和判定评测结果的模型。", "judgeModel.title": "判定模型", "metrics.add": "添加指标", diff --git a/web/types/evaluation.ts b/web/types/evaluation.ts index 30070cfb57..547b9cfa41 100644 --- a/web/types/evaluation.ts +++ b/web/types/evaluation.ts @@ -77,6 +77,19 @@ export type EvaluationRun = { created_at: number } +export type EvaluationLogFile = { + id: string + name: string +} + +export type EvaluationLog = { + created_at: string + created_by: string + test_file: EvaluationLogFile + result_file: EvaluationLogFile | null + version: string +} + export type EvaluationRunMetric = { name?: string value?: unknown @@ -97,7 +110,7 @@ export type EvaluationRunItem = { } export type EvaluationLogsResponse = { - data: EvaluationRun[] + data: EvaluationLog[] total: number page: number page_size: number