You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

run-and-history.tsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. import { useEventEmitterContextContext } from '@/context/event-emitter'
  23. import { EVENT_WORKFLOW_STOP } from '@/app/components/workflow/variable-inspect/types'
  24. import useTheme from '@/hooks/use-theme'
  25. const RunMode = memo(() => {
  26. const { t } = useTranslation()
  27. const { handleWorkflowStartRunInWorkflow } = useWorkflowStartRun()
  28. const { handleStopRun } = useWorkflowRun()
  29. const workflowRunningData = useStore(s => s.workflowRunningData)
  30. const isRunning = workflowRunningData?.result.status === WorkflowRunningStatus.Running
  31. const handleStop = () => {
  32. handleStopRun(workflowRunningData?.task_id || '')
  33. }
  34. const { eventEmitter } = useEventEmitterContextContext()
  35. eventEmitter?.useSubscription((v: any) => {
  36. if (v.type === EVENT_WORKFLOW_STOP)
  37. handleStop()
  38. })
  39. return (
  40. <>
  41. <div
  42. className={cn(
  43. 'flex h-7 items-center rounded-md px-2.5 text-[13px] font-medium text-components-button-secondary-accent-text',
  44. 'cursor-pointer hover:bg-state-accent-hover',
  45. isRunning && '!cursor-not-allowed bg-state-accent-hover',
  46. )}
  47. onClick={() => {
  48. handleWorkflowStartRunInWorkflow()
  49. }}
  50. >
  51. {
  52. isRunning
  53. ? (
  54. <>
  55. <RiLoader2Line className='mr-1 h-4 w-4 animate-spin' />
  56. {t('workflow.common.running')}
  57. </>
  58. )
  59. : (
  60. <>
  61. <RiPlayLargeLine className='mr-1 h-4 w-4' />
  62. {t('workflow.common.run')}
  63. </>
  64. )
  65. }
  66. </div>
  67. {
  68. isRunning && (
  69. <div
  70. className='ml-0.5 flex h-7 w-7 cursor-pointer items-center justify-center rounded-md hover:bg-black/5'
  71. onClick={handleStop}
  72. >
  73. <StopCircle className='h-4 w-4 text-components-button-ghost-text' />
  74. </div>
  75. )
  76. }
  77. </>
  78. )
  79. })
  80. RunMode.displayName = 'RunMode'
  81. const PreviewMode = memo(() => {
  82. const { t } = useTranslation()
  83. const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun()
  84. return (
  85. <div
  86. className={cn(
  87. 'flex h-7 items-center rounded-md px-2.5 text-[13px] font-medium text-components-button-secondary-accent-text',
  88. 'cursor-pointer hover:bg-state-accent-hover',
  89. )}
  90. onClick={() => handleWorkflowStartRunInChatflow()}
  91. >
  92. <RiPlayLargeLine className='mr-1 h-4 w-4' />
  93. {t('workflow.common.debugAndPreview')}
  94. </div>
  95. )
  96. })
  97. PreviewMode.displayName = 'PreviewMode'
  98. const RunAndHistory: FC = () => {
  99. const { theme } = useTheme()
  100. const isChatMode = useIsChatMode()
  101. const { nodesReadOnly } = useNodesReadOnly()
  102. return (
  103. <>
  104. <div className={cn(
  105. 'flex h-8 items-center rounded-lg border-[0.5px] border-components-button-secondary-border bg-components-button-secondary-bg px-0.5 shadow-xs',
  106. theme === 'dark' && 'rounded-lg border border-black/5 bg-white/10 backdrop-blur-sm',
  107. )}>
  108. {
  109. !isChatMode && <RunMode />
  110. }
  111. {
  112. isChatMode && <PreviewMode />
  113. }
  114. <div className='mx-0.5 h-3.5 w-[1px] bg-divider-regular'></div>
  115. <ViewHistory />
  116. <Checklist disabled={nodesReadOnly} />
  117. </div>
  118. </>
  119. )
  120. }
  121. export default memo(RunAndHistory)