panel.tsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. tooltip={t(`${i18nPrefix}.breakConditionTip`)}
  52. >
  53. <ConditionWrap
  54. nodeId={id}
  55. readOnly={readOnly}
  56. handleAddCondition={handleAddCondition}
  57. handleRemoveCondition={handleRemoveCondition}
  58. handleUpdateCondition={handleUpdateCondition}
  59. handleToggleConditionLogicalOperator={handleToggleConditionLogicalOperator}
  60. handleAddSubVariableCondition={handleAddSubVariableCondition}
  61. handleRemoveSubVariableCondition={handleRemoveSubVariableCondition}
  62. handleUpdateSubVariableCondition={handleUpdateSubVariableCondition}
  63. handleToggleSubVariableConditionLogicalOperator={handleToggleSubVariableConditionLogicalOperator}
  64. availableNodes={loopChildrenNodes}
  65. availableVars={childrenNodeVars}
  66. conditions={inputs.break_conditions || []}
  67. logicalOperator={inputs.logical_operator!}
  68. />
  69. </Field>
  70. <Split />
  71. <div className='mt-2'>
  72. <Field
  73. title={<div className='pl-3'>{t(`${i18nPrefix}.loopMaxCount`)}</div>}
  74. >
  75. <div className='px-3 py-2'>
  76. <InputNumberWithSlider
  77. min={1}
  78. max={LOOP_NODE_MAX_COUNT}
  79. value={inputs.loop_count}
  80. onChange={(val) => {
  81. const roundedVal = Math.round(val)
  82. handleUpdateLoopCount(Number.isNaN(roundedVal) ? 1 : roundedVal)
  83. }}
  84. />
  85. </div>
  86. </Field>
  87. </div>
  88. </div>
  89. {/* Error handling for the Loop node is currently not considered. */}
  90. {/* <div className='px-4 py-2'>
  91. <Field title={t(`${i18nPrefix}.errorResponseMethod`)} >
  92. <Select items={responseMethod} defaultValue={inputs.error_handle_mode} onSelect={changeErrorResponseMode} allowSearch={false}>
  93. </Select>
  94. </Field>
  95. </div> */}
  96. {isShowSingleRun && (
  97. <BeforeRunForm
  98. nodeName={inputs.title}
  99. onHide={hideSingleRun}
  100. forms={[]}
  101. runningStatus={runningStatus}
  102. onRun={handleRun}
  103. onStop={handleStop}
  104. {...logsParams}
  105. result={
  106. <ResultPanel {...runResult} showSteps={false} nodeInfo={nodeInfo} {...logsParams} />
  107. }
  108. />
  109. )}
  110. </div>
  111. )
  112. }
  113. export default React.memo(Panel)