panel.tsx 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. RiArrowRightSLine,
  6. } from '@remixicon/react'
  7. import VarReferencePicker from '../_base/components/variable/var-reference-picker'
  8. import Split from '../_base/components/split'
  9. import ResultPanel from '../../run/result-panel'
  10. import IterationResultPanel from '../../run/iteration-result-panel'
  11. import type { IterationNodeType } from './types'
  12. import useConfig from './use-config'
  13. import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
  14. import Field from '@/app/components/workflow/nodes/_base/components/field'
  15. import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
  16. const i18nPrefix = 'workflow.nodes.iteration'
  17. const Panel: FC<NodePanelProps<IterationNodeType>> = ({
  18. id,
  19. data,
  20. }) => {
  21. const { t } = useTranslation()
  22. const {
  23. readOnly,
  24. inputs,
  25. filterInputVar,
  26. handleInputChange,
  27. childrenNodeVars,
  28. iterationChildrenNodes,
  29. handleOutputVarChange,
  30. isShowSingleRun,
  31. hideSingleRun,
  32. isShowIterationDetail,
  33. backToSingleRun,
  34. showIterationDetail,
  35. hideIterationDetail,
  36. runningStatus,
  37. handleRun,
  38. handleStop,
  39. runResult,
  40. inputVarValues,
  41. setInputVarValues,
  42. usedOutVars,
  43. iterator,
  44. setIterator,
  45. iteratorInputKey,
  46. iterationRunResult,
  47. } = useConfig(id, data)
  48. return (
  49. <div className='mt-2'>
  50. <div className='px-4 pb-4 space-y-4'>
  51. <Field
  52. title={t(`${i18nPrefix}.input`)}
  53. operations={(
  54. <div className='flex items-center h-[18px] px-1 border border-black/8 rounded-[5px] text-xs font-medium text-gray-500 capitalize'>Array</div>
  55. )}
  56. >
  57. <VarReferencePicker
  58. readonly={readOnly}
  59. nodeId={id}
  60. isShowNodeName
  61. value={inputs.iterator_selector || []}
  62. onChange={handleInputChange}
  63. filterVar={filterInputVar}
  64. />
  65. </Field>
  66. </div>
  67. <Split />
  68. <div className='mt-2 px-4 pb-4 space-y-4'>
  69. <Field
  70. title={t(`${i18nPrefix}.output`)}
  71. operations={(
  72. <div className='flex items-center h-[18px] px-1 border border-black/8 rounded-[5px] text-xs font-medium text-gray-500 capitalize'>Array</div>
  73. )}
  74. >
  75. <VarReferencePicker
  76. readonly={readOnly}
  77. nodeId={id}
  78. isShowNodeName
  79. value={inputs.output_selector || []}
  80. onChange={handleOutputVarChange}
  81. availableNodes={iterationChildrenNodes}
  82. availableVars={childrenNodeVars}
  83. />
  84. </Field>
  85. </div>
  86. {isShowSingleRun && (
  87. <BeforeRunForm
  88. nodeName={inputs.title}
  89. onHide={hideSingleRun}
  90. forms={[
  91. {
  92. inputs: [...usedOutVars],
  93. values: inputVarValues,
  94. onChange: setInputVarValues,
  95. },
  96. {
  97. label: t(`${i18nPrefix}.input`)!,
  98. inputs: [{
  99. label: '',
  100. variable: iteratorInputKey,
  101. type: InputVarType.iterator,
  102. required: false,
  103. }],
  104. values: { [iteratorInputKey]: iterator },
  105. onChange: keyValue => setIterator((keyValue as any)[iteratorInputKey]),
  106. },
  107. ]}
  108. runningStatus={runningStatus}
  109. onRun={handleRun}
  110. onStop={handleStop}
  111. result={
  112. <div className='mt-3'>
  113. <div className='px-4'>
  114. <div className='flex items-center h-[34px] justify-between px-3 bg-gray-100 border-[0.5px] border-gray-200 rounded-lg cursor-pointer' onClick={showIterationDetail}>
  115. <div className='leading-[18px] text-[13px] font-medium text-gray-700'>{t(`${i18nPrefix}.iteration`, { count: iterationRunResult.length })}</div>
  116. <RiArrowRightSLine className='w-3.5 h-3.5 text-gray-500' />
  117. </div>
  118. <Split className='mt-3' />
  119. </div>
  120. <ResultPanel {...runResult} showSteps={false} />
  121. </div>
  122. }
  123. />
  124. )}
  125. {isShowIterationDetail && (
  126. <IterationResultPanel
  127. onBack={backToSingleRun}
  128. onHide={hideIterationDetail}
  129. list={iterationRunResult}
  130. />
  131. )}
  132. </div>
  133. )
  134. }
  135. export default React.memo(Panel)