panel.tsx 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import useConfig from './use-config'
  5. import VarList from './components/var-list'
  6. import type { VariableAssignerNodeType } from './types'
  7. import Field from '@/app/components/workflow/nodes/_base/components/field'
  8. import Selector from '@/app/components/workflow/nodes/_base/components/selector'
  9. import AddButton from '@/app/components/base/button/add-button'
  10. import { ChevronDown } from '@/app/components/base/icons/src/vender/line/arrows'
  11. import type { NodePanelProps } from '@/app/components/workflow/types'
  12. import { VarType } from '@/app/components/workflow/types'
  13. import Split from '@/app/components/workflow/nodes/_base/components/split'
  14. import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
  15. const i18nPrefix = 'workflow.nodes.variableAssigner'
  16. const Panel: FC<NodePanelProps<VariableAssignerNodeType>> = ({
  17. id,
  18. data,
  19. }) => {
  20. const { t } = useTranslation()
  21. const {
  22. readOnly,
  23. inputs,
  24. handleOutputTypeChange,
  25. handleVarListChange,
  26. handleAddVariable,
  27. handleOnVarOpen,
  28. filterVar,
  29. } = useConfig(id, data)
  30. const typeOptions = [
  31. { label: t(`${i18nPrefix}.type.string`), value: VarType.string },
  32. { label: t(`${i18nPrefix}.type.number`), value: VarType.number },
  33. { label: t(`${i18nPrefix}.type.object`), value: VarType.object },
  34. { label: t(`${i18nPrefix}.type.array`), value: VarType.array },
  35. ]
  36. return (
  37. <div className='mt-2'>
  38. <div className='px-4 pb-4 space-y-4'>
  39. <Field
  40. title={t(`${i18nPrefix}.outputVarType`)}
  41. >
  42. <Selector
  43. readonly={readOnly}
  44. value={inputs.output_type}
  45. options={typeOptions}
  46. onChange={handleOutputTypeChange}
  47. trigger={
  48. <div className='flex items-center h-8 justify-between px-2.5 rounded-lg bg-gray-100 capitalize'>
  49. <div className='text-[13px] font-normal text-gray-900'>{inputs.output_type}</div>
  50. {!readOnly && <ChevronDown className='w-3.5 h-3.5 text-gray-700' />}
  51. </div>
  52. }
  53. popupClassName='!top-[36px] !w-[387px]'
  54. showChecked
  55. />
  56. </Field>
  57. <Field
  58. title={t(`${i18nPrefix}.title`)}
  59. operations={
  60. !readOnly ? <AddButton onClick={handleAddVariable} /> : undefined
  61. }
  62. >
  63. <VarList
  64. readonly={readOnly}
  65. nodeId={id}
  66. list={inputs.variables}
  67. onChange={handleVarListChange}
  68. onOpen={handleOnVarOpen}
  69. onlyLeafNodeVar
  70. filterVar={filterVar}
  71. />
  72. </Field>
  73. </div>
  74. <Split />
  75. <div className='px-4 pt-4 pb-2'>
  76. <OutputVars>
  77. <>
  78. <VarItem
  79. name='output'
  80. type={inputs.output_type}
  81. description={t(`${i18nPrefix}.outputVars.output`)}
  82. />
  83. </>
  84. </OutputVars>
  85. </div>
  86. </div>
  87. )
  88. }
  89. export default React.memo(Panel)