list.tsx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. 'use client'
  2. import Pagination, { type Props as PaginationProps } from '@/app/components/base/pagination'
  3. import type { FC } from 'react'
  4. import Button from '@/app/components/base/button'
  5. import cn from '@/utils/classnames'
  6. import { useTranslation } from 'react-i18next'
  7. import useTimestamp from '@/hooks/use-timestamp'
  8. import { downloadLogFile } from '@/service/common'
  9. type PageListProps = {
  10. list: []
  11. pagination: PaginationProps
  12. onUpdate: () => void
  13. }
  14. const LogPageList: FC<PageListProps> = ({
  15. list = [],
  16. pagination,
  17. onUpdate,
  18. }) => {
  19. const { t } = useTranslation()
  20. const { formatTime } = useTimestamp()
  21. const statusMap = new Map([
  22. ['CREATED', '创建'],
  23. ['TRAINING', '训练中'],
  24. ['COMPLETED', '完成'],
  25. ])
  26. const handleDownload = async (item: any) => {
  27. await downloadLogFile({
  28. url: `/intentions/train_tasks/download/${item.id}`,
  29. fileName: item.name,
  30. })
  31. }
  32. return (
  33. <div className='relative flex h-full w-full flex-col'>
  34. <div className='relative grow overflow-x-auto'>
  35. <table className={'mt-3 w-full min-w-[700px] max-w-full border-collapse border-0 text-sm'}>
  36. <thead className="h-8 border-b border-divider-subtle text-xs font-medium uppercase leading-8 text-text-tertiary">
  37. <tr>
  38. <td>训练任务</td>
  39. <td>训练状态</td>
  40. <td>训练语料数据集版本</td>
  41. <td>训练时间</td>
  42. <td>训练模型结果版本</td>
  43. <td className="w-[120px] text-center">操作</td>
  44. </tr>
  45. </thead>
  46. <tbody className="text-text-secondary">
  47. {list.map((item: any, index) => (
  48. <tr
  49. key={item.id}
  50. className={'h-8 border-b border-divider-subtle hover:bg-background-default-hover'}
  51. >
  52. <td>{item.name}</td>
  53. <td>{statusMap.get(item.status)}</td>
  54. <td>{item.dataset_info.version}</td>
  55. <td>{formatTime(item.created_at, t('datasetHitTesting.dateTimeFormat') as string)}</td>
  56. <td>{item.model_info.version}</td>
  57. <td className="flex justify-center gap-2">
  58. <Button variant='ghost-accent' size='small' className={cn('shrink-0')} onClick={(e) => {
  59. e.stopPropagation()
  60. handleDownload(item)
  61. }}>
  62. 下载
  63. </Button>
  64. </td>
  65. </tr>
  66. ))}
  67. </tbody>
  68. </table>
  69. </div>
  70. {/* Show Pagination only if the total is more than the limit */}
  71. {pagination.total && (
  72. <Pagination
  73. {...pagination}
  74. className='w-full shrink-0 px-0 pb-0'
  75. />
  76. )}
  77. </div>
  78. )
  79. }
  80. export default LogPageList