@@ -10,61 +10,79 @@ import useCanvasStore from 'stores/CanvasStore';
1010
1111const RequestNode = ( { id, data } ) => {
1212 const setRequestNodeUrl = useCanvasStore ( ( state ) => state . setRequestNodeUrl ) ;
13- const requestNodeAddVariable = useCanvasStore ( ( state ) => state . requestNodeAddVariable ) ;
14- const requestNodeDeleteVariable = useCanvasStore ( ( state ) => state . requestNodeDeleteVariable ) ;
15- const requestNodeChangeVariable = useCanvasStore ( ( state ) => state . requestNodeChangeVariable ) ;
13+ const requestNodeAddPreRequestVar = useCanvasStore ( ( state ) => state . requestNodeAddPreRequestVar ) ;
14+ const requestNodeDeletePreRequestVar = useCanvasStore ( ( state ) => state . requestNodeDeletePreRequestVar ) ;
15+ const requestNodeChangePreRequestVar = useCanvasStore ( ( state ) => state . requestNodeChangePreRequestVar ) ;
16+
17+ const requestNodeAddPostResponseVar = useCanvasStore ( ( state ) => state . requestNodeAddPostResponseVar ) ;
18+ const requestNodeDeletePostResponseVar = useCanvasStore ( ( state ) => state . requestNodeDeletePostResponseVar ) ;
19+ const requestNodeChangePostResponseVar = useCanvasStore ( ( state ) => state . requestNodeChangePostResponseVar ) ;
1620
1721 const [ variableDialogOpen , setVariableDialogOpen ] = useState ( false ) ;
22+ const [ modalType , setModalType ] = useState ( '' ) ;
1823
19- const handleAddVariable = ( name , type ) => {
20- requestNodeAddVariable ( id , name , type ) ;
24+ const handleAddVariable = ( vType , name , type ) => {
25+ if ( vType === 'pre-request' ) {
26+ requestNodeAddPreRequestVar ( id , name , type ) ;
27+ } else if ( vType === 'post-response' ) {
28+ requestNodeAddPostResponseVar ( id , name , type ) ;
29+ }
2130 } ;
2231
23- const handleDeleteVariable = ( event , vId ) => {
24- requestNodeDeleteVariable ( id , vId ) ;
32+ const handleDeleteVariable = ( event , vType , vId ) => {
33+ if ( vType === 'pre-request' ) {
34+ requestNodeDeletePreRequestVar ( id , vId ) ;
35+ } else if ( vType === 'post-response' ) {
36+ requestNodeDeletePostResponseVar ( id , vId ) ;
37+ }
2538 } ;
2639
27- const handleVariableChange = ( event , vId ) => {
28- requestNodeChangeVariable ( id , vId , event . target . value ) ;
40+ const handleVariableChange = ( event , vType , vId ) => {
41+ if ( vType === 'pre-request' ) {
42+ requestNodeChangePreRequestVar ( id , vId , event . target . value ) ;
43+ } else if ( vType === 'post-response' ) {
44+ requestNodeChangePostResponseVar ( id , vId , event . target . value ) ;
45+ }
2946 } ;
3047
3148 const handleUrlInputChange = ( event ) => {
3249 setRequestNodeUrl ( id , event . target . value ) ;
3350 } ;
3451
35- const renderVariables = ( ) => {
52+ const renderVariables = ( vType ) => {
53+ const variables = vType === 'pre-request' ? data . preReqVars : data . postRespVars ;
3654 return (
3755 < >
38- { data . variables &&
39- Object . keys ( data . variables ) . map ( ( id ) => (
56+ { variables &&
57+ Object . keys ( variables ) . map ( ( id ) => (
4058 < div className = 'flex items-center justify-between pb-2' key = { id } >
4159 < div className = 'flex items-center justify-between text-sm border rounded-md border-neutral-500 text-neutral-500 outline-0 focus:ring-0' >
4260 < label className = 'px-4 py-2 border-r rounded-bl-md rounded-tl-md border-r-neutral-500' > { id } </ label >
43- { data . variables [ id ] . type === 'Boolean' ? (
61+ { variables [ id ] . type === 'Boolean' ? (
4462 < select
45- onChange = { ( e ) => handleVariableChange ( e , id ) }
63+ onChange = { ( e ) => handleVariableChange ( e , vType , id ) }
4664 name = 'boolean-val'
4765 className = 'nodrag h-9 w-full rounded-br-md rounded-tr-md p-2.5 px-1 '
48- value = { data . variables [ id ] . value }
66+ value = { variables [ id ] . value }
4967 >
5068 < option value = 'true' > True</ option >
5169 < option value = 'false' > False</ option >
5270 </ select >
5371 ) : (
5472 < input
55- type = { getInputType ( data . variables [ id ] . type ) }
73+ type = { getInputType ( variables [ id ] . type ) }
5674 className = 'nodrag nowheel block h-9 w-full rounded-bl-md rounded-tl-md p-2.5'
5775 name = 'variable-value'
58- data-type = { getInputType ( data . variables [ id ] . type ) }
59- onChange = { ( e ) => handleVariableChange ( e , id ) }
60- value = { data . variables [ id ] . value }
76+ data-type = { getInputType ( variables [ id ] . type ) }
77+ onChange = { ( e ) => handleVariableChange ( e , vType , id ) }
78+ value = { variables [ id ] . value }
6179 />
6280 ) }
6381 < div className = 'px-4 py-2 border-l rounded-br-md rounded-tr-md border-l-neutral-500' >
64- { data . variables [ id ] . type }
82+ { variables [ id ] . type }
6583 </ div >
6684 </ div >
67- < div onClick = { ( e ) => handleDeleteVariable ( e , id ) } className = 'p-2 text-neutral-500' >
85+ < div onClick = { ( e ) => handleDeleteVariable ( e , vType , id ) } className = 'p-2 text-neutral-500' >
6886 < TrashIcon className = 'w-4 h-4' />
6987 </ div >
7088 </ div >
@@ -96,16 +114,39 @@ const RequestNode = ({ id, data }) => {
96114 < div className = 'border-t border-neutral-300 bg-slate-100' >
97115 < div className = 'flex items-center justify-between px-2 py-4 font-medium' >
98116 < h3 > Variables</ h3 >
99- < button className = 'p-2' onClick = { ( ) => setVariableDialogOpen ( true ) } >
117+ </ div >
118+ < div >
119+ Pre Request
120+ < button
121+ className = 'p-2'
122+ onClick = { ( ) => {
123+ setModalType ( 'pre-request' ) ;
124+ setVariableDialogOpen ( true ) ;
125+ } }
126+ >
127+ < PlusIcon className = 'w-4 h-4' />
128+ </ button >
129+ < div className = 'p-2 pt-4 border-t border-neutral-300 bg-slate-50' > { renderVariables ( 'pre-request' ) } </ div >
130+ </ div >
131+ < div >
132+ Post Response
133+ < button
134+ className = 'p-2'
135+ onClick = { ( ) => {
136+ setModalType ( 'post-response' ) ;
137+ setVariableDialogOpen ( true ) ;
138+ } }
139+ >
100140 < PlusIcon className = 'w-4 h-4' />
101141 </ button >
142+ < div className = 'p-2 pt-4 border-t border-neutral-300 bg-slate-50' > { renderVariables ( 'post-response' ) } </ div >
102143 </ div >
103- < div className = 'p-2 pt-4 border-t border-neutral-300 bg-slate-50' > { renderVariables ( ) } </ div >
104144 </ div >
105145 </ div >
106146 < AddVariableModal
107147 closeFn = { ( ) => setVariableDialogOpen ( false ) }
108148 open = { variableDialogOpen }
149+ modalType = { modalType }
109150 onVariableAdd = { handleAddVariable }
110151 />
111152 </ FlowNode >
0 commit comments