workflow-process.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import {
  2. useCallback,
  3. useEffect,
  4. useMemo,
  5. useState,
  6. } from 'react'
  7. import {
  8. RiArrowRightSLine,
  9. RiErrorWarningFill,
  10. RiLoader2Line,
  11. } from '@remixicon/react'
  12. import { useTranslation } from 'react-i18next'
  13. import type { ChatItem, WorkflowProcess } from '../../types'
  14. import TracingPanel from '@/app/components/workflow/run/tracing-panel'
  15. import cn from '@/utils/classnames'
  16. import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
  17. import { WorkflowRunningStatus } from '@/app/components/workflow/types'
  18. import { useStore as useAppStore } from '@/app/components/app/store'
  19. type WorkflowProcessProps = {
  20. data: WorkflowProcess
  21. item?: ChatItem
  22. grayBg?: boolean
  23. expand?: boolean
  24. hideInfo?: boolean
  25. hideProcessDetail?: boolean
  26. }
  27. const WorkflowProcessItem = ({
  28. data,
  29. item,
  30. grayBg,
  31. expand = false,
  32. hideInfo = false,
  33. hideProcessDetail = false,
  34. }: WorkflowProcessProps) => {
  35. const { t } = useTranslation()
  36. const [collapse, setCollapse] = useState(!expand)
  37. const running = data.status === WorkflowRunningStatus.Running
  38. const succeeded = data.status === WorkflowRunningStatus.Succeeded
  39. const failed = data.status === WorkflowRunningStatus.Failed || data.status === WorkflowRunningStatus.Stopped
  40. const background = useMemo(() => {
  41. if (running && !collapse)
  42. return 'linear-gradient(180deg, #E1E4EA 0%, #EAECF0 100%)'
  43. if (succeeded && !collapse)
  44. return 'linear-gradient(180deg, #ECFDF3 0%, #F6FEF9 100%)'
  45. if (failed && !collapse)
  46. return 'linear-gradient(180deg, #FEE4E2 0%, #FEF3F2 100%)'
  47. }, [running, succeeded, failed, collapse])
  48. useEffect(() => {
  49. setCollapse(!expand)
  50. }, [expand])
  51. const setCurrentLogItem = useAppStore(s => s.setCurrentLogItem)
  52. const setShowMessageLogModal = useAppStore(s => s.setShowMessageLogModal)
  53. const setCurrentLogModalActiveTab = useAppStore(s => s.setCurrentLogModalActiveTab)
  54. const showIterationDetail = useCallback(() => {
  55. setCurrentLogItem(item)
  56. setCurrentLogModalActiveTab('TRACING')
  57. setShowMessageLogModal(true)
  58. }, [item, setCurrentLogItem, setCurrentLogModalActiveTab, setShowMessageLogModal])
  59. return (
  60. <div
  61. className={cn(
  62. 'mb-2 rounded-xl border-[0.5px] border-black/8',
  63. collapse ? 'py-[7px]' : hideInfo ? 'pt-2 pb-1' : 'py-2',
  64. collapse && (!grayBg ? 'bg-white' : 'bg-gray-50'),
  65. hideInfo ? 'mx-[-8px] px-1' : 'w-full px-3',
  66. )}
  67. style={{
  68. background,
  69. }}
  70. >
  71. <div
  72. className={cn(
  73. 'flex items-center h-[18px] cursor-pointer',
  74. hideInfo && 'px-[6px]',
  75. )}
  76. onClick={() => setCollapse(!collapse)}
  77. >
  78. {
  79. running && (
  80. <RiLoader2Line className='shrink-0 mr-1 w-3 h-3 text-[#667085] animate-spin' />
  81. )
  82. }
  83. {
  84. succeeded && (
  85. <CheckCircle className='shrink-0 mr-1 w-3 h-3 text-[#12B76A]' />
  86. )
  87. }
  88. {
  89. failed && (
  90. <RiErrorWarningFill className='shrink-0 mr-1 w-3 h-3 text-[#F04438]' />
  91. )
  92. }
  93. <div className='grow text-xs font-medium text-gray-700'>
  94. {t('workflow.common.workflowProcess')}
  95. </div>
  96. <RiArrowRightSLine className={`'ml-1 w-3 h-3 text-gray-500' ${collapse ? '' : 'rotate-90'}`} />
  97. </div>
  98. {
  99. !collapse && (
  100. <div className='mt-1.5'>
  101. {
  102. <TracingPanel
  103. list={data.tracing}
  104. onShowIterationDetail={showIterationDetail}
  105. hideNodeInfo={hideInfo}
  106. hideNodeProcessDetail={hideProcessDetail}
  107. />
  108. }
  109. </div>
  110. )
  111. }
  112. </div>
  113. )
  114. }
  115. export default WorkflowProcessItem