panel.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import type { FC } from 'react'
  2. import {
  3. memo,
  4. } from 'react'
  5. import { useTranslation } from 'react-i18next'
  6. import {
  7. RiAddLine,
  8. } from '@remixicon/react'
  9. import useConfig from './use-config'
  10. import type { IfElseNodeType } from './types'
  11. import ConditionWrap from './components/condition-wrap'
  12. import Button from '@/app/components/base/button'
  13. import type { NodePanelProps } from '@/app/components/workflow/types'
  14. import Field from '@/app/components/workflow/nodes/_base/components/field'
  15. const i18nPrefix = 'workflow.nodes.ifElse'
  16. const Panel: FC<NodePanelProps<IfElseNodeType>> = ({
  17. id,
  18. data,
  19. }) => {
  20. const { t } = useTranslation()
  21. const {
  22. readOnly,
  23. inputs,
  24. filterVar,
  25. handleAddCase,
  26. handleRemoveCase,
  27. handleSortCase,
  28. handleAddCondition,
  29. handleUpdateCondition,
  30. handleRemoveCondition,
  31. handleToggleConditionLogicalOperator,
  32. handleAddSubVariableCondition,
  33. handleRemoveSubVariableCondition,
  34. handleUpdateSubVariableCondition,
  35. handleToggleSubVariableConditionLogicalOperator,
  36. nodesOutputVars,
  37. availableNodes,
  38. varsIsVarFileAttribute,
  39. } = useConfig(id, data)
  40. const cases = inputs.cases || []
  41. return (
  42. <div className='p-1'>
  43. <ConditionWrap
  44. nodeId={id}
  45. cases={cases}
  46. readOnly={readOnly}
  47. handleSortCase={handleSortCase}
  48. handleRemoveCase={handleRemoveCase}
  49. handleAddCondition={handleAddCondition}
  50. handleRemoveCondition={handleRemoveCondition}
  51. handleUpdateCondition={handleUpdateCondition}
  52. handleToggleConditionLogicalOperator={handleToggleConditionLogicalOperator}
  53. handleAddSubVariableCondition={handleAddSubVariableCondition}
  54. handleRemoveSubVariableCondition={handleRemoveSubVariableCondition}
  55. handleUpdateSubVariableCondition={handleUpdateSubVariableCondition}
  56. handleToggleSubVariableConditionLogicalOperator={handleToggleSubVariableConditionLogicalOperator}
  57. nodesOutputVars={nodesOutputVars}
  58. availableNodes={availableNodes}
  59. varsIsVarFileAttribute={varsIsVarFileAttribute}
  60. filterVar={filterVar}
  61. />
  62. <div className='px-4 py-2'>
  63. <Button
  64. className='w-full'
  65. variant='tertiary'
  66. onClick={() => handleAddCase()}
  67. disabled={readOnly}
  68. >
  69. <RiAddLine className='mr-1 w-4 h-4' />
  70. ELIF
  71. </Button>
  72. </div>
  73. <div className='my-2 mx-3 h-[1px] bg-divider-subtle'></div>
  74. <Field
  75. title={t(`${i18nPrefix}.else`)}
  76. className='px-4 py-2'
  77. >
  78. <div className='leading-[18px] text-xs font-normal text-text-tertiary'>{t(`${i18nPrefix}.elseDescription`)}</div>
  79. </Field>
  80. </div>
  81. )
  82. }
  83. export default memo(Panel)