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 0819ff2137..84ebdf6f1a 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,5 +1,5 @@ import type { EvaluationResourceProps } from '../../types' -import type { EvaluationLog, EvaluationLogFile } from '@/types/evaluation' +import type { EvaluationLog, EvaluationRunStatus } from '@/types/evaluation' import { cn } from '@langgenius/dify-ui/cn' import { DropdownMenu, @@ -11,22 +11,35 @@ import { keepPreviousData, useMutation, useQuery } from '@tanstack/react-query' import { useEffect, useMemo, useState } from 'react' import { useTranslation } from 'react-i18next' import Pagination from '@/app/components/base/pagination' +import useTimestamp from '@/hooks/use-timestamp' import { consoleClient, consoleQuery } from '@/service/client' +import { useMembers } from '@/service/use-common' import { downloadUrl } from '@/utils/download' import { useEvaluationResource, useEvaluationStore } from '../../store' const PAGE_SIZE = 16 const LOADING_ROW_IDS = ['1', '2', '3', '4', '5', '6'] +const CREATED_AT_FORMAT = 'YYYY-MM-DD' -const formatCreatedAt = (createdAt: string) => { - if (!createdAt) +type FormatTimestamp = (value: number, format: string) => string + +const STATUS_ICON_CLASS_NAMES: Record = { + pending: 'i-ri-time-line text-text-tertiary', + running: 'i-ri-loader-4-line animate-spin text-text-accent', + completed: 'i-ri-checkbox-circle-fill text-util-colors-green-green-600', + failed: 'i-ri-close-circle-fill text-text-destructive', + cancelled: 'i-ri-forbid-2-line text-text-tertiary', +} + +const formatCreatedAt = (createdAt: number | null | undefined, formatTime: FormatTimestamp) => { + if (createdAt == null) return '-' - return createdAt.includes('T') ? createdAt.slice(0, 10) : createdAt + return formatTime(createdAt, CREATED_AT_FORMAT) } const getLogRunId = (record: EvaluationLog) => { - return record.run_id ?? record.evaluation_run_id ?? record.id ?? null + return record.id } const HistoryTab = ({ @@ -34,6 +47,8 @@ const HistoryTab = ({ resourceId, }: EvaluationResourceProps) => { const { t } = useTranslation('evaluation') + const { formatTime } = useTimestamp() + const { data: membersData } = useMembers() const [page, setPage] = useState(0) const resource = useEvaluationResource(resourceType, resourceId) const setSelectedRunId = useEvaluationStore(state => state.setSelectedRunId) @@ -54,19 +69,22 @@ const HistoryTab = ({ placeholderData: keepPreviousData, }) const fileDownloadMutation = useMutation({ - mutationFn: async (file: EvaluationLogFile) => { + mutationFn: async (fileId: string) => { const fileInfo = await consoleClient.evaluation.file({ params: { targetType: resourceType, targetId: resourceId, - fileId: file.id, + fileId, }, }) - downloadUrl({ url: fileInfo.download_url, fileName: file.name }) + downloadUrl({ url: fileInfo.download_url, fileName: fileInfo.name }) }, }) const records = useMemo(() => logsQuery.data?.data ?? [], [logsQuery.data?.data]) + const memberNameById = useMemo(() => { + return new Map((membersData?.accounts ?? []).map(member => [member.id, member.name])) + }, [membersData?.accounts]) const total = logsQuery.data?.total ?? 0 const isInitialLoading = logsQuery.isLoading && !logsQuery.data @@ -85,8 +103,7 @@ const HistoryTab = ({ - - + @@ -99,7 +116,6 @@ const HistoryTab = ({ - {isInitialLoading && LOADING_ROW_IDS.map(rowId => ( - ))} {!isInitialLoading && records.map(record => ( - - - - + +
{t('history.columns.creator')}{t('history.columns.version')} {t('history.columns.status')}
+
{formatCreatedAt(record.created_at)}{record.created_by}{record.version || '-'} - {record.result_file - ? - : } + {formatCreatedAt(record.created_at, formatTime)}{memberNameById.get(record.created_by) ?? record.created_by} +
+ +
@@ -153,9 +168,11 @@ const HistoryTab = ({ { event.stopPropagation() - fileDownloadMutation.mutate(record.test_file) + if (record.dataset_file_id) + fileDownloadMutation.mutate(record.dataset_file_id) }} > { event.stopPropagation() - if (record.result_file) - fileDownloadMutation.mutate(record.result_file) + if (record.result_file_id) + fileDownloadMutation.mutate(record.result_file_id) }} >