panel.tsx 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import Split from '../_base/components/split'
  5. import ResultPanel from '../../run/result-panel'
  6. import InputNumberWithSlider from '../_base/components/input-number-with-slider'
  7. import type { LoopNodeType } from './types'
  8. import useConfig from './use-config'
  9. import ConditionWrap from './components/condition-wrap'
  10. import 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 formatTracing from '@/app/components/workflow/run/utils/format-log'
  14. import { useLogs } from '@/app/components/workflow/run/hooks'
  15. import { LOOP_NODE_MAX_COUNT } from '@/config'
  16. const i18nPrefix = 'workflow.nodes.loop'
  17. const Panel: FC<NodePanelProps<LoopNodeType>> = ({
  18. id,
  19. data,
  20. }) => {
  21. const { t } = useTranslation()
  22. const {
  23. readOnly,
  24. inputs,
  25. childrenNodeVars,
  26. loopChildrenNodes,
  27. isShowSingleRun,
  28. hideSingleRun,
  29. runningStatus,
  30. handleRun,
  31. handleStop,
  32. runResult,
  33. loopRunResult,
  34. handleAddCondition,
  35. handleUpdateCondition,
  36. handleRemoveCondition,
  37. handleToggleConditionLogicalOperator,
  38. handleAddSubVariableCondition,
  39. handleRemoveSubVariableCondition,
  40. handleUpdateSubVariableCondition,
  41. handleToggleSubVariableConditionLogicalOperator,
  42. handleUpdateLoopCount,
  43. } = useConfig(id, data)
  44. const nodeInfo = formatTracing(loopRunResult, t)[0]
  45. const logsParams = useLogs()
  46. return (
  47. <div className='mt-2'>
  48. <div>
  49. <Field
  50. title={<div className='pl-3'>{t(`${i18nPrefix}.breakCondition`)}</div>}
  51. >
  52. <ConditionWrap
  53. nodeId={id}
  54. readOnly={readOnly}
  55. handleAddCondition={handleAddCondition}
  56. handleRemoveCondition={handleRemoveCondition}
  57. handleUpdateCondition={handleUpdateCondition}
  58. handleToggleConditionLogicalOperator={handleToggleConditionLogicalOperator}
  59. handleAddSubVariableCondition={handleAddSubVariableCondition}
  60. handleRemoveSubVariableCondition={handleRemoveSubVariableCondition}
  61. handleUpdateSubVariableCondition={handleUpdateSubVariableCondition}
  62. handleToggleSubVariableConditionLogicalOperator={handleToggleSubVariableConditionLogicalOperator}
  63. availableNodes={loopChildrenNodes}
  64. availableVars={childrenNodeVars}
  65. conditions={inputs.break_conditions || []}
  66. logicalOperator={inputs.logical_operator!}
  67. />
  68. </Field>
  69. <Split />
  70. <div className='mt-2'>
  71. <Field
  72. title={<div className='pl-3'>{t(`${i18nPrefix}.loopMaxCount`)}</div>}
  73. >
  74. <div className='px-3 py-2'>
  75. <InputNumberWithSlider
  76. min={1}
  77. max={LOOP_NODE_MAX_COUNT}
  78. value={inputs.loop_count}
  79. onChange={(val) => {
  80. const roundedVal = Math.round(val)
  81. handleUpdateLoopCount(Number.isNaN(roundedVal) ? 1 : roundedVal)
  82. }}
  83. />
  84. </div>
  85. </Field>
  86. </div>
  87. </div>
  88. {/* Error handling for the Loop node is currently not considered. */}
  89. {/* <div className='px-4 py-2'>
  90. <Field title={t(`${i18nPrefix}.errorResponseMethod`)} >
  91. <Select items={responseMethod} defaultValue={inputs.error_handle_mode} onSelect={changeErrorResponseMode} allowSearch={false}>
  92. </Select>
  93. </Field>
  94. </div> */}
  95. {isShowSingleRun && (
  96. <BeforeRunForm
  97. nodeName={inputs.title}
  98. onHide={hideSingleRun}
  99. forms={[]}
  100. runningStatus={runningStatus}
  101. onRun={handleRun}
  102. onStop={handleStop}
  103. {...logsParams}
  104. result={
  105. <ResultPanel {...runResult} showSteps={false} nodeInfo={nodeInfo} {...logsParams} />
  106. }
  107. />
  108. )}
  109. </div>
  110. )
  111. }
  112. export default React.memo(Panel)