status.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. 'use client'
  2. import type { FC } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import cn from '@/utils/classnames'
  5. import Indicator from '@/app/components/header/indicator'
  6. type ResultProps = {
  7. status: string
  8. time?: number
  9. tokens?: number
  10. error?: string
  11. }
  12. const StatusPanel: FC<ResultProps> = ({
  13. status,
  14. time,
  15. tokens,
  16. error,
  17. }) => {
  18. const { t } = useTranslation()
  19. return (
  20. <div
  21. className={cn(
  22. 'px-3 py-[10px] rounded-lg border-[0.5px] border-[rbga(0,0,0,0.05)] shadow-xs',
  23. status === 'running' && '!bg-primary-50',
  24. status === 'succeeded' && '!bg-[#ecfdf3]',
  25. status === 'failed' && '!bg-[#fef3f2]',
  26. status === 'stopped' && '!bg-[#fffaeb]',
  27. )}
  28. >
  29. <div className='flex'>
  30. <div className='flex-[33%] max-w-[120px]'>
  31. <div className='text-xs leading-[18px] font-medium text-gray-400'>{t('runLog.resultPanel.status')}</div>
  32. <div
  33. className={cn(
  34. 'flex items-center gap-1 h-[18px] text-xs leading-3 font-semibold',
  35. status === 'running' && '!text-primary-600',
  36. status === 'succeeded' && '!text-[#039855]',
  37. status === 'failed' && '!text-[#d92d20]',
  38. status === 'stopped' && '!text-[#f79009]',
  39. )}
  40. >
  41. {status === 'running' && (
  42. <span>Running</span>
  43. )}
  44. {status === 'succeeded' && (
  45. <>
  46. <Indicator color={'green'} />
  47. <span>SUCCESS</span>
  48. </>
  49. )}
  50. {status === 'failed' && (
  51. <>
  52. <Indicator color={'red'} />
  53. <span>FAIL</span>
  54. </>
  55. )}
  56. {status === 'stopped' && (
  57. <>
  58. <Indicator color={'yellow'} />
  59. <span>STOP</span>
  60. </>
  61. )}
  62. </div>
  63. </div>
  64. <div className='flex-[33%] max-w-[152px]'>
  65. <div className='text-xs leading-[18px] font-medium text-gray-400'>{t('runLog.resultPanel.time')}</div>
  66. <div className='flex items-center gap-1 h-[18px] text-gray-700 text-xs leading-3 font-semibold'>
  67. {status === 'running' && (
  68. <div className='w-16 h-2 rounded-sm bg-[rgba(0,0,0,0.05)]' />
  69. )}
  70. {status !== 'running' && (
  71. <span>{`${time?.toFixed(3)}s`}</span>
  72. )}
  73. </div>
  74. </div>
  75. <div className='flex-[33%]'>
  76. <div className='text-xs leading-[18px] font-medium text-gray-400'>{t('runLog.resultPanel.tokens')}</div>
  77. <div className='flex items-center gap-1 h-[18px] text-gray-700 text-xs leading-3 font-semibold'>
  78. {status === 'running' && (
  79. <div className='w-20 h-2 rounded-sm bg-[rgba(0,0,0,0.05)]' />
  80. )}
  81. {status !== 'running' && (
  82. <span>{`${tokens || 0} Tokens`}</span>
  83. )}
  84. </div>
  85. </div>
  86. </div>
  87. {status === 'failed' && error && (
  88. <>
  89. <div className='my-2 h-[0.5px] bg-black opacity-5' />
  90. <div className='text-xs leading-[18px] text-[#d92d20]'>{error}</div>
  91. </>
  92. )}
  93. </div>
  94. )
  95. }
  96. export default StatusPanel