workflow-process.tsx 3.2 KB

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