You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

class-item.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. 'use client'
  2. import type { FC } from 'react'
  3. import React, { useCallback } from 'react'
  4. import { useTranslation } from 'react-i18next'
  5. import type { Topic } from '../types'
  6. import Editor from '@/app/components/workflow/nodes/_base/components/prompt/editor'
  7. import useAvailableVarList from '@/app/components/workflow/nodes/_base/hooks/use-available-var-list'
  8. import type { ValueSelector, Var } from '@/app/components/workflow/types'
  9. const i18nPrefix = 'workflow.nodes.questionClassifiers'
  10. type Props = {
  11. nodeId: string
  12. payload: Topic
  13. onChange: (payload: Topic) => void
  14. onRemove: () => void
  15. index: number
  16. readonly?: boolean
  17. filterVar: (payload: Var, valueSelector: ValueSelector) => boolean
  18. }
  19. const ClassItem: FC<Props> = ({
  20. nodeId,
  21. payload,
  22. onChange,
  23. onRemove,
  24. index,
  25. readonly,
  26. filterVar,
  27. }) => {
  28. const { t } = useTranslation()
  29. const handleNameChange = useCallback((value: string) => {
  30. onChange({ ...payload, name: value })
  31. }, [onChange, payload])
  32. const { availableVars, availableNodesWithParent } = useAvailableVarList(nodeId, {
  33. onlyLeafNodeVar: false,
  34. hideChatVar: false,
  35. hideEnv: false,
  36. filterVar,
  37. })
  38. return (
  39. <Editor
  40. title={`${t(`${i18nPrefix}.class`)} ${index}`}
  41. placeholder={t(`${i18nPrefix}.topicPlaceholder`)!}
  42. value={payload.name}
  43. onChange={handleNameChange}
  44. showRemove
  45. onRemove={onRemove}
  46. nodesOutputVars={availableVars}
  47. availableNodes={availableNodesWithParent}
  48. readOnly={readonly} // ?
  49. justVar // ?
  50. isSupportFileVar // ?
  51. />
  52. )
  53. }
  54. export default React.memo(ClassItem)