run-and-history.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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={() => {
  37. handleWorkflowStartRunInWorkflow()
  38. }}
  39. >
  40. {
  41. isRunning
  42. ? (
  43. <>
  44. <RiLoader2Line className='mr-1 w-4 h-4 animate-spin' />
  45. {t('workflow.common.running')}
  46. </>
  47. )
  48. : (
  49. <>
  50. <RiPlayLargeLine className='mr-1 w-4 h-4' />
  51. {t('workflow.common.run')}
  52. </>
  53. )
  54. }
  55. </div>
  56. {
  57. isRunning && (
  58. <div
  59. className='flex items-center justify-center ml-0.5 w-7 h-7 cursor-pointer hover:bg-black/5 rounded-md'
  60. onClick={() => handleStopRun(workflowRunningData?.task_id || '')}
  61. >
  62. <StopCircle className='w-4 h-4 text-components-button-ghost-text' />
  63. </div>
  64. )
  65. }
  66. </>
  67. )
  68. })
  69. RunMode.displayName = 'RunMode'
  70. const PreviewMode = memo(() => {
  71. const { t } = useTranslation()
  72. const { handleWorkflowStartRunInChatflow } = useWorkflowStartRun()
  73. return (
  74. <div
  75. className={cn(
  76. 'flex items-center px-2.5 h-7 rounded-md text-[13px] font-medium text-components-button-secondary-accent-text',
  77. 'hover:bg-state-accent-hover cursor-pointer',
  78. )}
  79. onClick={() => handleWorkflowStartRunInChatflow()}
  80. >
  81. <RiPlayLargeLine className='mr-1 w-4 h-4' />
  82. {t('workflow.common.debugAndPreview')}
  83. </div>
  84. )
  85. })
  86. PreviewMode.displayName = 'PreviewMode'
  87. const RunAndHistory: FC = () => {
  88. const isChatMode = useIsChatMode()
  89. const { nodesReadOnly } = useNodesReadOnly()
  90. return (
  91. <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'>
  92. {
  93. !isChatMode && <RunMode />
  94. }
  95. {
  96. isChatMode && <PreviewMode />
  97. }
  98. <div className='mx-0.5 w-[1px] h-3.5 bg-divider-regular'></div>
  99. <ViewHistory />
  100. <Checklist disabled={nodesReadOnly} />
  101. </div>
  102. )
  103. }
  104. export default memo(RunAndHistory)