iteration-result-panel.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 { Iteration } 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 IterationResultPanel: FC<Props> = ({
  22. list,
  23. onHide,
  24. onBack,
  25. noWrap,
  26. }) => {
  27. const { t } = useTranslation()
  28. const [expandedIterations, setExpandedIterations] = useState<Record<number, boolean>>([])
  29. const toggleIteration = useCallback((index: number) => {
  30. setExpandedIterations(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='shrink-0 flex justify-between items-center h-8'>
  39. <div className='system-xl-semibold text-text-primary truncate'>
  40. {t(`${i18nPrefix}.testRunIteration`)}
  41. </div>
  42. <div className='ml-2 shrink-0 p-1 cursor-pointer' onClick={onHide}>
  43. <RiCloseLine className='w-4 h-4 text-text-tertiary' />
  44. </div>
  45. </div>
  46. <div className='flex items-center py-2 space-x-1 text-text-accent-secondary cursor-pointer' onClick={onBack}>
  47. <ArrowNarrowLeft className='w-4 h-4' />
  48. <div className='system-sm-medium'>{t(`${i18nPrefix}.back`)}</div>
  49. </div>
  50. </div>
  51. {/* List */}
  52. <div className={cn(!noWrap ? 'flex-grow overflow-auto' : 'max-h-full', 'p-2 bg-components-panel-bg')}>
  53. {list.map((iteration, index) => (
  54. <div key={index} className={cn('mb-1 overflow-hidden rounded-xl bg-background-section-burn border-none')}>
  55. <div
  56. className={cn(
  57. 'flex items-center justify-between w-full px-3 cursor-pointer',
  58. expandedIterations[index] ? 'pt-3 pb-2' : 'py-3',
  59. 'rounded-xl text-left',
  60. )}
  61. onClick={() => toggleIteration(index)}
  62. >
  63. <div className={cn('flex items-center gap-2 flex-grow')}>
  64. <div className='flex items-center justify-center w-4 h-4 rounded-[5px] border-divider-subtle bg-util-colors-cyan-cyan-500 flex-shrink-0'>
  65. <Iteration className='w-3 h-3 text-text-primary-on-surface' />
  66. </div>
  67. <span className='system-sm-semibold-uppercase text-text-primary flex-grow'>
  68. {t(`${i18nPrefix}.iteration`)} {index + 1}
  69. </span>
  70. <RiArrowRightSLine className={cn(
  71. 'w-4 h-4 text-text-tertiary transition-transform duration-200 flex-shrink-0',
  72. expandedIterations[index] && 'transform rotate-90',
  73. )} />
  74. </div>
  75. </div>
  76. {expandedIterations[index] && <div
  77. className="flex-grow h-px bg-divider-subtle"
  78. ></div>}
  79. <div className={cn(
  80. 'overflow-hidden transition-all duration-200',
  81. expandedIterations[index] ? 'max-h-[1000px] opacity-100' : 'max-h-0 opacity-0',
  82. )}>
  83. <TracingPanel
  84. list={iteration}
  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='h-full rounded-2xl bg-white flex flex-col'>
  109. {main}
  110. </div>
  111. </div >
  112. )
  113. }
  114. export default React.memo(IterationResultPanel)