panel.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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, availableNodesWithParent } = useAvailableVarList(id, {
  22. onlyLeafNodeVar: false,
  23. hideChatVar: true,
  24. hideEnv: true,
  25. filterVar,
  26. })
  27. return (
  28. <div className='mt-2 mb-2 px-4 space-y-4'>
  29. <Editor
  30. readOnly={readOnly}
  31. justVar
  32. title={t(`${i18nPrefix}.answer`)!}
  33. value={inputs.answer}
  34. onChange={handleAnswerChange}
  35. nodesOutputVars={availableVars}
  36. availableNodes={availableNodesWithParent}
  37. />
  38. </div>
  39. )
  40. }
  41. export default React.memo(Panel)