Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

run-and-history.tsx 3.6KB

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