panel.tsx 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 type { AnswerNodeType } from './types'
  6. import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
  7. import type { NodePanelProps } from '@/app/components/workflow/types'
  8. import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
  9. const i18nPrefix = 'workflow.nodes.answer'
  10. const Panel: FC<NodePanelProps<AnswerNodeType>> = ({
  11. id,
  12. data,
  13. }) => {
  14. const { t } = useTranslation()
  15. const {
  16. readOnly,
  17. inputs,
  18. handleAnswerChange,
  19. filterVar,
  20. } = useConfig(id, data)
  21. const { availableVars, availableNodes } = useAvailableVarList(id, {
  22. onlyLeafNodeVar: false,
  23. filterVar,
  24. })
  25. return (
  26. <div className='mt-2 mb-2 px-4 space-y-4'>
  27. <Editor
  28. readOnly={readOnly}
  29. justVar
  30. title={t(`${i18nPrefix}.answer`)!}
  31. value={inputs.answer}
  32. onChange={handleAnswerChange}
  33. nodesOutputVars={availableVars}
  34. availableNodes={availableNodes}
  35. />
  36. </div>
  37. )
  38. }
  39. export default React.memo(Panel)