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