You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

workflow-process.tsx 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import {
  2. useEffect,
  3. useState,
  4. } from 'react'
  5. import {
  6. RiArrowRightSLine,
  7. RiErrorWarningFill,
  8. RiLoader2Line,
  9. } from '@remixicon/react'
  10. import { useTranslation } from 'react-i18next'
  11. import type { ChatItem, WorkflowProcess } from '../../types'
  12. import TracingPanel from '@/app/components/workflow/run/tracing-panel'
  13. import cn from '@/utils/classnames'
  14. import { CheckCircle } from '@/app/components/base/icons/src/vender/solid/general'
  15. import { WorkflowRunningStatus } from '@/app/components/workflow/types'
  16. type WorkflowProcessProps = {
  17. data: WorkflowProcess
  18. item?: ChatItem
  19. expand?: boolean
  20. hideInfo?: boolean
  21. hideProcessDetail?: boolean
  22. readonly?: boolean
  23. }
  24. const WorkflowProcessItem = ({
  25. data,
  26. expand = false,
  27. hideInfo = false,
  28. hideProcessDetail = false,
  29. readonly = false,
  30. }: WorkflowProcessProps) => {
  31. const { t } = useTranslation()
  32. const [collapse, setCollapse] = useState(!expand)
  33. const running = data.status === WorkflowRunningStatus.Running
  34. const succeeded = data.status === WorkflowRunningStatus.Succeeded
  35. const failed = data.status === WorkflowRunningStatus.Failed || data.status === WorkflowRunningStatus.Stopped
  36. useEffect(() => {
  37. setCollapse(!expand)
  38. }, [expand])
  39. if (readonly) return null
  40. return (
  41. <div
  42. className={cn(
  43. '-mx-1 rounded-xl px-2.5',
  44. collapse ? 'border-l-[0.25px] border-components-panel-border py-[7px]' : 'border-[0.5px] border-components-panel-border-subtle px-1 pb-1 pt-[7px]',
  45. running && !collapse && 'bg-background-section-burn',
  46. succeeded && !collapse && 'bg-state-success-hover',
  47. failed && !collapse && 'bg-state-destructive-hover',
  48. collapse && 'bg-workflow-process-bg',
  49. )}
  50. >
  51. <div
  52. className={cn('flex cursor-pointer items-center', !collapse && 'px-1.5')}
  53. onClick={() => setCollapse(!collapse)}
  54. >
  55. {
  56. running && (
  57. <RiLoader2Line className='mr-1 h-3.5 w-3.5 shrink-0 animate-spin text-text-tertiary' />
  58. )
  59. }
  60. {
  61. succeeded && (
  62. <CheckCircle className='mr-1 h-3.5 w-3.5 shrink-0 text-text-success' />
  63. )
  64. }
  65. {
  66. failed && (
  67. <RiErrorWarningFill className='mr-1 h-3.5 w-3.5 shrink-0 text-text-destructive' />
  68. )
  69. }
  70. <div className={cn('system-xs-medium text-text-secondary', !collapse && 'grow')}>
  71. {t('workflow.common.workflowProcess')}
  72. </div>
  73. <RiArrowRightSLine className={cn('ml-1 h-4 w-4 text-text-tertiary', !collapse && 'rotate-90')} />
  74. </div>
  75. {
  76. !collapse && (
  77. <div className='mt-1.5'>
  78. {
  79. <TracingPanel
  80. list={data.tracing}
  81. hideNodeInfo={hideInfo}
  82. hideNodeProcessDetail={hideProcessDetail}
  83. />
  84. }
  85. </div>
  86. )
  87. }
  88. </div>
  89. )
  90. }
  91. export default WorkflowProcessItem