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.

use-single-run-form-params.ts 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { useTranslation } from 'react-i18next'
  2. import type { InputVar, Variable } from '@/app/components/workflow/types'
  3. import { InputVarType } from '@/app/components/workflow/types'
  4. import { useCallback, useMemo } from 'react'
  5. import type { KnowledgeBaseNodeType } from './types'
  6. type Params = {
  7. id: string,
  8. payload: KnowledgeBaseNodeType
  9. runInputData: Record<string, any>
  10. getInputVars: (textList: string[]) => InputVar[]
  11. setRunInputData: (data: Record<string, any>) => void
  12. toVarInputs: (variables: Variable[]) => InputVar[]
  13. }
  14. const useSingleRunFormParams = ({
  15. payload,
  16. runInputData,
  17. setRunInputData,
  18. }: Params) => {
  19. const { t } = useTranslation()
  20. const query = runInputData.query
  21. const setQuery = useCallback((newQuery: string) => {
  22. setRunInputData({
  23. ...runInputData,
  24. query: newQuery,
  25. })
  26. }, [runInputData, setRunInputData])
  27. const forms = useMemo(() => {
  28. return [
  29. {
  30. inputs: [{
  31. label: t('workflow.nodes.common.inputVars'),
  32. variable: 'query',
  33. type: InputVarType.paragraph,
  34. required: true,
  35. }],
  36. values: { query },
  37. onChange: (keyValue: Record<string, any>) => setQuery(keyValue.query),
  38. },
  39. ]
  40. }, [query, setQuery, t])
  41. const getDependentVars = () => {
  42. return [payload.index_chunk_variable_selector]
  43. }
  44. const getDependentVar = (variable: string) => {
  45. if(variable === 'query')
  46. return payload.index_chunk_variable_selector
  47. }
  48. return {
  49. forms,
  50. getDependentVars,
  51. getDependentVar,
  52. }
  53. }
  54. export default useSingleRunFormParams