選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

loop-result-panel.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. 'transition-all duration-200',
  81. expandedLoops[index]
  82. ? 'opacity-100'
  83. : 'max-h-0 overflow-hidden opacity-0',
  84. )}>
  85. <TracingPanel
  86. list={loop}
  87. className='bg-background-section-burn'
  88. />
  89. </div>
  90. </div>
  91. ))}
  92. </div>
  93. </>
  94. )
  95. const handleNotBubble = useCallback((e: React.MouseEvent) => {
  96. // if not do this, it will trigger the message log modal disappear(useClickAway)
  97. e.stopPropagation()
  98. e.nativeEvent.stopImmediatePropagation()
  99. }, [])
  100. if (noWrap)
  101. return main
  102. return (
  103. <div
  104. className='absolute inset-0 z-10 rounded-2xl pt-10'
  105. style={{
  106. backgroundColor: 'rgba(16, 24, 40, 0.20)',
  107. }}
  108. onClick={handleNotBubble}
  109. >
  110. <div className='flex h-full flex-col rounded-2xl bg-components-panel-bg'>
  111. {main}
  112. </div>
  113. </div >
  114. )
  115. }
  116. export default React.memo(LoopResultPanel)