workflow-process.tsx 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. return (
  40. <div
  41. className={cn(
  42. '-mx-1 px-2.5 rounded-xl',
  43. collapse ? 'py-[7px] border-l-[0.25px] border-components-panel-border' : 'pt-[7px] px-1 pb-1 border-[0.5px] border-components-panel-border-subtle',
  44. running && !collapse && 'bg-background-section-burn',
  45. succeeded && !collapse && 'bg-state-success-hover',
  46. failed && !collapse && 'bg-state-destructive-hover',
  47. collapse && 'bg-workflow-process-bg',
  48. )}
  49. >
  50. <div
  51. className={cn('flex items-center cursor-pointer', !collapse && 'px-1.5', readonly && 'cursor-default')}
  52. onClick={() => !readonly && setCollapse(!collapse)}
  53. >
  54. {
  55. running && (
  56. <RiLoader2Line className='shrink-0 mr-1 w-3.5 h-3.5 text-text-tertiary' />
  57. )
  58. }
  59. {
  60. succeeded && (
  61. <CheckCircle className='shrink-0 mr-1 w-3.5 h-3.5 text-text-success' />
  62. )
  63. }
  64. {
  65. failed && (
  66. <RiErrorWarningFill className='shrink-0 mr-1 w-3.5 h-3.5 text-text-destructive' />
  67. )
  68. }
  69. <div className={cn('system-xs-medium text-text-secondary', !collapse && 'grow')}>
  70. {t('workflow.common.workflowProcess')}
  71. </div>
  72. {!readonly && <RiArrowRightSLine className={cn('ml-1 w-4 h-4 text-text-tertiary', !collapse && 'rotate-90')} />}
  73. </div>
  74. {
  75. !collapse && !readonly && (
  76. <div className='mt-1.5'>
  77. {
  78. <TracingPanel
  79. list={data.tracing}
  80. hideNodeInfo={hideInfo}
  81. hideNodeProcessDetail={hideProcessDetail}
  82. />
  83. }
  84. </div>
  85. )
  86. }
  87. </div>
  88. )
  89. }
  90. export default WorkflowProcessItem