run-and-history.tsx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. import type { FC } from 'react'
  2. import { memo } from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. RiLoader2Line,
  6. RiPlayLargeFill,
  7. } from '@remixicon/react'
  8. import { useStore } from '../store'
  9. import {
  10. useIsChatMode,
  11. useWorkflowRun,
  12. useWorkflowStartRun,
  13. } from '../hooks'
  14. import { WorkflowRunningStatus } from '../types'
  15. import ViewHistory from './view-history'
  16. import cn from '@/utils/classnames'
  17. import {
  18. StopCircle,
  19. } from '@/app/components/base/icons/src/vender/line/mediaAndDevices'
  20. import { MessagePlay } from '@/app/components/base/icons/src/vender/line/communication'
  21. const RunMode = memo(() => {
  22. const { t } = useTranslation()
  23. const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun()
  24. const { handleStopRun } = useWorkflowRun()
  25. const workflowRunningData = useStore(s => s.workflowRunningData)
  26. const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running
  27. return (
  28. <>
  29. <div
  30. className={cn(
  31. 'flex items-center px-1.5 h-7 rounded-md text-[13px] font-medium text-primary-600',
  32. 'hover:bg-primary-50 cursor-pointer',
  33. isRunning && 'bg-primary-50 !cursor-not-allowed',
  34. )}
  35. onClick={() => handleWorkflowStartRunInWorkflow()}
  36. >
  37. {
  38. isRunning
  39. ? (
  40. <>
  41. <RiLoader2Line className='mr-1 w-4 h-4 animate-spin' />
  42. {t('workflow.common.running')}
  43. </>
  44. )
  45. : (
  46. <>
  47. <RiPlayLargeFill className='mr-1 w-4 h-4' />
  48. {t('workflow.common.run')}
  49. </>
  50. )
  51. }
  52. </div>
  53. {
  54. isRunning && (
  55. <div
  56. className='flex items-center justify-center ml-0.5 w-7 h-7 cursor-pointer hover:bg-black/5 rounded-md'
  57. onClick={() => handleStopRun(workflowRunningData?.task_id || '')}
  58. >
  59. <StopCircle className='w-4 h-4 text-gray-500' />
  60. </div>
  61. )
  62. }
  63. </>
  64. )
  65. })
  66. RunMode.displayName = 'RunMode'
  67. const PreviewMode = memo(() => {
  68. const { t } = useTranslation()
  69. const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun()
  70. return (
  71. <div
  72. className={cn(
  73. 'flex items-center px-1.5 h-7 rounded-md text-[13px] font-medium text-primary-600',
  74. 'hover:bg-primary-50 cursor-pointer',
  75. )}
  76. onClick={() => handleWorkflowStartRunInChatflow()}
  77. >
  78. <MessagePlay className='mr-1 w-4 h-4' />
  79. {t('workflow.common.debugAndPreview')}
  80. </div>
  81. )
  82. })
  83. PreviewMode.displayName = 'PreviewMode'
  84. const RunAndHistory: FC = () => {
  85. const isChatMode = useIsChatMode()
  86. return (
  87. <div className='flex items-center px-0.5 h-8 rounded-lg border-[0.5px] border-gray-200 bg-white shadow-xs'>
  88. {
  89. !isChatMode && <RunMode />
  90. }
  91. {
  92. isChatMode && <PreviewMode />
  93. }
  94. <div className='mx-0.5 w-[0.5px] h-8 bg-gray-200'></div>
  95. <ViewHistory />
  96. </div>
  97. )
  98. }
  99. export default memo(RunAndHistory)