panel.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import type { FC } from 'react'
  2. import React from 'react'
  3. import { useTranslation } from 'react-i18next'
  4. import {
  5. RiAddLine,
  6. } from '@remixicon/react'
  7. import VarList from './components/var-list'
  8. import useConfig from './use-config'
  9. import type { AssignerNodeType } from './types'
  10. import { useHandleAddOperationItem } from './hooks'
  11. import ActionButton from '@/app/components/base/action-button'
  12. import { type NodePanelProps } from '@/app/components/workflow/types'
  13. const i18nPrefix = 'workflow.nodes.assigner'
  14. const Panel: FC<NodePanelProps<AssignerNodeType>> = ({
  15. id,
  16. data,
  17. }) => {
  18. const { t } = useTranslation()
  19. const handleAddOperationItem = useHandleAddOperationItem()
  20. const {
  21. readOnly,
  22. inputs,
  23. handleOperationListChanges,
  24. getAssignedVarType,
  25. getToAssignedVarType,
  26. writeModeTypesNum,
  27. writeModeTypesArr,
  28. writeModeTypes,
  29. filterAssignedVar,
  30. filterToAssignedVar,
  31. } = useConfig(id, data)
  32. const handleAddOperation = () => {
  33. const newList = handleAddOperationItem(inputs.items || [])
  34. handleOperationListChanges(newList)
  35. }
  36. return (
  37. <div className='flex py-2 flex-col items-start self-stretch'>
  38. <div className='flex flex-col justify-center items-start gap-1 px-4 py-2 w-full self-stretch'>
  39. <div className='flex items-start gap-2 self-stretch'>
  40. <div className='flex flex-col justify-center items-start flex-grow text-text-secondary system-sm-semibold-uppercase'>{t(`${i18nPrefix}.variables`)}</div>
  41. <ActionButton onClick={handleAddOperation}>
  42. <RiAddLine className='w-4 h-4 shrink-0 text-text-tertiary' />
  43. </ActionButton>
  44. </div>
  45. <VarList
  46. readonly={readOnly}
  47. nodeId={id}
  48. list={inputs.items || []}
  49. onChange={(newList) => {
  50. handleOperationListChanges(newList)
  51. }}
  52. filterVar={filterAssignedVar}
  53. filterToAssignedVar={filterToAssignedVar}
  54. getAssignedVarType={getAssignedVarType}
  55. writeModeTypes={writeModeTypes}
  56. writeModeTypesArr={writeModeTypesArr}
  57. writeModeTypesNum={writeModeTypesNum}
  58. getToAssignedVarType={getToAssignedVarType}
  59. />
  60. </div>
  61. </div>
  62. )
  63. }
  64. export default React.memo(Panel)