run-and-history.tsx 3.0 KB

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