run-and-history.tsx 3.2 KB

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