workflow-process.tsx 3.3 KB

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