1- import React , { useEffect , useState } from 'react' ;
1+ import React , { useEffect , useState , Fragment } from 'react' ;
22import { PropTypes } from 'prop-types' ;
33import RequestBody from './RequestBody' ;
44import FlowNode from 'components/atoms/flow/FlowNode' ;
@@ -9,9 +9,12 @@ import AddVariableModal from 'components/molecules/modals/flow/AddVariableModal'
99import useCanvasStore from 'stores/CanvasStore' ;
1010import TextInput from 'components/atoms/common/TextInput' ;
1111import NodeHorizontalDivider from 'components/atoms/flow/NodeHorizontalDivider' ;
12+ import { Listbox , Transition } from '@headlessui/react' ;
13+ import { CheckIcon , ChevronUpDownIcon } from '@heroicons/react/20/solid' ;
1214
1315const RequestNode = ( { id, data } ) => {
1416 const setRequestNodeUrl = useCanvasStore ( ( state ) => state . setRequestNodeUrl ) ;
17+ const setRequestNodeType = useCanvasStore ( ( state ) => state . setRequestNodeType ) ;
1518 const requestNodeAddPreRequestVar = useCanvasStore ( ( state ) => state . requestNodeAddPreRequestVar ) ;
1619 const requestNodeDeletePreRequestVar = useCanvasStore ( ( state ) => state . requestNodeDeletePreRequestVar ) ;
1720 const requestNodeChangePreRequestVar = useCanvasStore ( ( state ) => state . requestNodeChangePreRequestVar ) ;
@@ -100,6 +103,8 @@ const RequestNode = ({ id, data }) => {
100103 ) ;
101104 } ;
102105
106+ const requestTypes = [ 'GET' , 'PUT' , 'POST' , 'DELETE' ] ;
107+
103108 return (
104109 < FlowNode
105110 title = { data . requestType + ' Request' }
@@ -109,13 +114,61 @@ const RequestNode = ({ id, data }) => {
109114 handleRightData = { { type : 'source' } }
110115 >
111116 < div className = 'min-w-80' >
112- < div className = 'pb-4' >
113- < TextInput
114- placeHolder = { `Enter URL for a ${ data . requestType } request` }
115- onChangeHandler = { handleUrlInputChange }
116- name = { 'username' }
117- value = { data . url ? data . url : '' }
118- />
117+ < div className = 'flex' >
118+ < Listbox
119+ value = { data . requestType }
120+ onChange = { ( selectedValue ) => {
121+ setRequestNodeType ( id , selectedValue ) ;
122+ } }
123+ >
124+ < div className = 'relative min-w-36' >
125+ < Listbox . Button className = 'relative w-full p-2 text-left border rounded cursor-default border-cyan-950' >
126+ < span className = 'block truncate' > { data . requestType } </ span >
127+ < span className = 'absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none' >
128+ < ChevronUpDownIcon className = 'w-5 h-5' aria-hidden = 'true' />
129+ </ span >
130+ </ Listbox . Button >
131+ < Transition
132+ as = { Fragment }
133+ leave = 'transition ease-in duration-100'
134+ leaveFrom = 'opacity-100'
135+ leaveTo = 'opacity-0'
136+ >
137+ < Listbox . Options className = 'absolute w-full py-1 mt-1 overflow-auto text-base bg-white max-h-60 focus:outline-none' >
138+ { requestTypes . map ( ( reqType ) => (
139+ < Listbox . Option
140+ key = { reqType }
141+ className = { ( { active } ) =>
142+ `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
143+ active ? 'bg-background-light text-slate-900' : ''
144+ } `
145+ }
146+ value = { reqType }
147+ >
148+ { ( { selected } ) => (
149+ < >
150+ < span className = { `block` } > { reqType } </ span >
151+ { selected ? (
152+ < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
153+ < CheckIcon className = 'w-5 h-5' aria-hidden = 'true' />
154+ </ span >
155+ ) : null }
156+ </ >
157+ ) }
158+ </ Listbox . Option >
159+ ) ) }
160+ </ Listbox . Options >
161+ </ Transition >
162+ </ div >
163+ </ Listbox >
164+ < div className = 'pb-4' >
165+ < TextInput
166+ placeHolder = { `Enter URL for a ${ data . requestType } request` }
167+ onChangeHandler = { handleUrlInputChange }
168+ name = { 'url' }
169+ value = { data . url ? data . url : '' }
170+ />
171+ </ div >
119172 </ div >
120173 < NodeHorizontalDivider />
121174 < RequestBody nodeId = { id } nodeData = { data } />
0 commit comments