panel.tsx 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. >
  52. <VarReferencePicker
  53. readonly={readOnly}
  54. nodeId={id}
  55. isShowNodeName
  56. value={inputs.iterator_selector || []}
  57. onChange={handleInputChange}
  58. filterVar={filterInputVar}
  59. />
  60. </Field>
  61. </div>
  62. <Split />
  63. <div className='mt-2 px-4 pb-4 space-y-4'>
  64. <Field
  65. title={t(`${i18nPrefix}.output`)}
  66. operations={(
  67. <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>
  68. )}
  69. >
  70. <VarReferencePicker
  71. readonly={readOnly}
  72. nodeId={id}
  73. isShowNodeName
  74. value={inputs.output_selector || []}
  75. onChange={handleOutputVarChange}
  76. availableNodes={iterationChildrenNodes}
  77. availableVars={childrenNodeVars}
  78. />
  79. </Field>
  80. </div>
  81. {isShowSingleRun && (
  82. <BeforeRunForm
  83. nodeName={inputs.title}
  84. onHide={hideSingleRun}
  85. forms={[
  86. {
  87. inputs: [...usedOutVars],
  88. values: inputVarValues,
  89. onChange: setInputVarValues,
  90. },
  91. {
  92. label: t(`${i18nPrefix}.input`)!,
  93. inputs: [{
  94. label: '',
  95. variable: iteratorInputKey,
  96. type: InputVarType.iterator,
  97. required: false,
  98. }],
  99. values: { [iteratorInputKey]: iterator },
  100. onChange: keyValue => setIterator((keyValue as any)[iteratorInputKey]),
  101. },
  102. ]}
  103. runningStatus={runningStatus}
  104. onRun={handleRun}
  105. onStop={handleStop}
  106. result={
  107. <div className='mt-3'>
  108. <div className='px-4'>
  109. <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}>
  110. <div className='leading-[18px] text-[13px] font-medium text-gray-700'>{t(`${i18nPrefix}.iteration`, { count: iterationRunResult.length })}</div>
  111. <ArrowNarrowRight className='w-3.5 h-3.5 text-gray-500' />
  112. </div>
  113. <Split className='mt-3' />
  114. </div>
  115. <ResultPanel {...runResult} showSteps={false} />
  116. </div>
  117. }
  118. />
  119. )}
  120. {isShowIterationDetail && (
  121. <IterationResultPanel
  122. onBack={backToSingleRun}
  123. onHide={hideIterationDetail}
  124. list={iterationRunResult}
  125. />
  126. )}
  127. </div>
  128. )
  129. }
  130. export default React.memo(Panel)