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.

user-input.tsx 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {
  2. memo,
  3. } from 'react'
  4. import { useNodes } from 'reactflow'
  5. import FormItem from '../../nodes/_base/components/before-run-form/form-item'
  6. import { BlockEnum } from '../../types'
  7. import {
  8. useStore,
  9. useWorkflowStore,
  10. } from '../../store'
  11. import type { StartNodeType } from '../../nodes/start/types'
  12. import cn from '@/utils/classnames'
  13. const UserInput = () => {
  14. const workflowStore = useWorkflowStore()
  15. const inputs = useStore(s => s.inputs)
  16. const nodes = useNodes<StartNodeType>()
  17. const startNode = nodes.find(node => node.data.type === BlockEnum.Start)
  18. const variables = startNode?.data.variables || []
  19. const visibleVariables = variables.filter(v => v.hide !== true)
  20. const handleValueChange = (variable: string, v: string) => {
  21. const {
  22. inputs,
  23. setInputs,
  24. } = workflowStore.getState()
  25. setInputs({
  26. ...inputs,
  27. [variable]: v,
  28. })
  29. }
  30. if (!visibleVariables.length)
  31. return null
  32. return (
  33. <div className={cn('relative z-[1] rounded-xl border-[0.5px] border-components-panel-border-subtle bg-components-panel-on-panel-item-bg shadow-xs')}>
  34. <div className='px-4 pb-4 pt-3'>
  35. {visibleVariables.map((variable, index) => (
  36. <div
  37. key={variable.variable}
  38. className='mb-4 last-of-type:mb-0'
  39. >
  40. <FormItem
  41. autoFocus={index === 0}
  42. payload={variable}
  43. value={inputs[variable.variable]}
  44. onChange={v => handleValueChange(variable.variable, v)}
  45. />
  46. </div>
  47. ))}
  48. </div>
  49. </div>
  50. )
  51. }
  52. export default memo(UserInput)