loop-result-panel.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback, useState } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import {
  6. RiArrowRightSLine,
  7. RiCloseLine,
  8. } from '@remixicon/react'
  9. import { ArrowNarrowLeft } from '../../base/icons/src/vender/line/arrows'
  10. import TracingPanel from './tracing-panel'
  11. import { Loop } from '@/app/components/base/icons/src/vender/workflow'
  12. import cn from '@/utils/classnames'
  13. import type { NodeTracing } from '@/types/workflow'
  14. const i18nPrefix = 'workflow.singleRun'
  15. type Props = {
  16. list: NodeTracing[][]
  17. onHide: () => void
  18. onBack: () => void
  19. noWrap?: boolean
  20. }
  21. const LoopResultPanel: FC<Props> = ({
  22. list,
  23. onHide,
  24. onBack,
  25. noWrap,
  26. }) => {
  27. const { t } = useTranslation()
  28. const [expandedLoops, setExpandedLoops] = useState<Record<number, boolean>>([])
  29. const toggleLoop = useCallback((index: number) => {
  30. setExpandedLoops(prev => ({
  31. ...prev,
  32. [index]: !prev[index],
  33. }))
  34. }, [])
  35. const main = (
  36. <>
  37. <div className={cn(!noWrap && 'shrink-0 ', 'px-4 pt-3')}>
  38. <div className='flex h-8 shrink-0 items-center justify-between'>
  39. <div className='system-xl-semibold truncate text-text-primary'>
  40. {t(`${i18nPrefix}.testRunLoop`)}
  41. </div>
  42. <div className='ml-2 shrink-0 cursor-pointer p-1' onClick={onHide}>
  43. <RiCloseLine className='h-4 w-4 text-text-tertiary' />
  44. </div>
  45. </div>
  46. <div className='flex cursor-pointer items-center space-x-1 py-2 text-text-accent-secondary' onClick={onBack}>
  47. <ArrowNarrowLeft className='h-4 w-4' />
  48. <div className='system-sm-medium'>{t(`${i18nPrefix}.back`)}</div>
  49. </div>
  50. </div>
  51. {/* List */}
  52. <div className={cn(!noWrap ? 'grow overflow-auto' : 'max-h-full', 'bg-components-panel-bg p-2')}>
  53. {list.map((loop, index) => (
  54. <div key={index} className={cn('mb-1 overflow-hidden rounded-xl border-none bg-background-section-burn')}>
  55. <div
  56. className={cn(
  57. 'flex w-full cursor-pointer items-center justify-between px-3',
  58. expandedLoops[index] ? 'pb-2 pt-3' : 'py-3',
  59. 'rounded-xl text-left',
  60. )}
  61. onClick={() => toggleLoop(index)}
  62. >
  63. <div className={cn('flex grow items-center gap-2')}>
  64. <div className='flex h-4 w-4 shrink-0 items-center justify-center rounded-[5px] border-divider-subtle bg-util-colors-cyan-cyan-500'>
  65. <Loop className='h-3 w-3 text-text-primary-on-surface' />
  66. </div>
  67. <span className='system-sm-semibold-uppercase grow text-text-primary'>
  68. {t(`${i18nPrefix}.loop`)} {index + 1}
  69. </span>
  70. <RiArrowRightSLine className={cn(
  71. 'h-4 w-4 shrink-0 text-text-tertiary transition-transform duration-200',
  72. expandedLoops[index] && 'rotate-90',
  73. )} />
  74. </div>
  75. </div>
  76. {expandedLoops[index] && <div
  77. className="h-px grow bg-divider-subtle"
  78. ></div>}
  79. <div className={cn(
  80. 'overflow-hidden transition-all duration-200',
  81. expandedLoops[index] ? 'max-h-[1000px] opacity-100' : 'max-h-0 opacity-0',
  82. )}>
  83. <TracingPanel
  84. list={loop}
  85. className='bg-background-section-burn'
  86. />
  87. </div>
  88. </div>
  89. ))}
  90. </div>
  91. </>
  92. )
  93. const handleNotBubble = useCallback((e: React.MouseEvent) => {
  94. // if not do this, it will trigger the message log modal disappear(useClickAway)
  95. e.stopPropagation()
  96. e.nativeEvent.stopImmediatePropagation()
  97. }, [])
  98. if (noWrap)
  99. return main
  100. return (
  101. <div
  102. className='absolute inset-0 z-10 rounded-2xl pt-10'
  103. style={{
  104. backgroundColor: 'rgba(16, 24, 40, 0.20)',
  105. }}
  106. onClick={handleNotBubble}
  107. >
  108. <div className='flex h-full flex-col rounded-2xl bg-components-panel-bg'>
  109. {main}
  110. </div>
  111. </div >
  112. )
  113. }
  114. export default React.memo(LoopResultPanel)