@@ -13,12 +13,17 @@ import { cloneDeep } from 'lodash';
1313const AuthNode = ( { id, data } ) => {
1414 const setAuthNodeType = useCanvasStore ( ( state ) => state . setAuthNodeType ) ;
1515 const setBasicAuthValues = useCanvasStore ( ( state ) => state . setBasicAuthValues ) ;
16- const [ selected , setSelected ] = useState ( data . type && data . type === 'basic-auth' ? 'basic-auth' : 'no-auth' ) ;
16+ const setBearerTokenValue = useCanvasStore ( ( state ) => state . setBearerTokenValue ) ;
17+ const [ selected , setSelected ] = useState ( data . type ? data . type : 'no-auth' ) ;
1718
18- const handleChange = ( value , option ) => {
19+ const handleBasicAuthValueChange = ( value , option ) => {
1920 setBasicAuthValues ( id , option , value ) ;
2021 } ;
2122
23+ const handleBearerTokenChange = ( value ) => {
24+ setBearerTokenValue ( id , value ) ;
25+ } ;
26+
2227 const getActiveVariables = ( ) => {
2328 const collectionId = useCanvasStore . getState ( ) . collectionId ;
2429 if ( collectionId ) {
@@ -33,6 +38,16 @@ const AuthNode = ({ id, data }) => {
3338 return [ ] ;
3439 } ;
3540
41+ const getAuthType = ( ) => {
42+ if ( selected === 'no-auth' ) {
43+ return 'No Auth' ;
44+ } else if ( selected === 'basic-auth' ) {
45+ return 'Basic Auth' ;
46+ } else if ( selected === 'bearer-token' ) {
47+ return 'Bearer Token' ;
48+ }
49+ } ;
50+
3651 return (
3752 < >
3853 < FlowNode
@@ -42,89 +57,122 @@ const AuthNode = ({ id, data }) => {
4257 handleRight = { true }
4358 handleRightData = { { type : 'source' } }
4459 >
45- < Listbox
46- value = { selected }
47- onChange = { ( selectedValue ) => {
48- setSelected ( selectedValue ) ;
49- setAuthNodeType ( id , selectedValue ) ;
50- } }
51- >
52- < div className = 'relative min-w-36' >
53- < Listbox . Button className = 'relative w-full p-2 text-left border rounded cursor-default border-cyan-950' >
54- < span className = 'block truncate' > { selected === 'no-auth' ? 'No Auth' : 'Basic Auth' } </ span >
55- < span className = 'absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none' >
56- < ChevronUpDownIcon className = 'w-5 h-5' aria-hidden = 'true' />
57- </ span >
58- </ Listbox . Button >
59- < Transition
60- as = { Fragment }
61- leave = 'transition ease-in duration-100'
62- leaveFrom = 'opacity-100'
63- leaveTo = 'opacity-0'
64- >
65- < Listbox . Options className = 'absolute z-10 w-full py-1 mt-1 overflow-auto text-base bg-white max-h-60 focus:outline-none' >
66- < Listbox . Option
67- className = { ( { active } ) =>
68- `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
69- active ? 'bg-background-light text-slate-900' : ''
70- } `
71- }
72- value = { 'no-auth' }
73- >
74- { ( { selected } ) => (
75- < >
76- < span className = { `block` } > No Auth</ span >
77- { selected ? (
78- < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
79- < CheckIcon className = 'w-5 h-5' aria-hidden = 'true' />
80- </ span >
81- ) : null }
82- </ >
83- ) }
84- </ Listbox . Option >
85- < Listbox . Option
86- className = { ( { active } ) =>
87- `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
88- active ? 'bg-background-light text-slate-900' : ''
89- } `
90- }
91- value = { 'basic-auth' }
92- >
93- { ( { selected } ) => (
94- < >
95- < span className = { `block` } > Basic auth</ span >
96- { selected ? (
97- < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
98- < CheckIcon className = 'w-5 h-5' aria-hidden = 'true' />
99- </ span >
100- ) : null }
101- </ >
102- ) }
103- </ Listbox . Option >
104- </ Listbox . Options >
105- </ Transition >
106- </ div >
107- </ Listbox >
108- { data . type === 'basic-auth' && (
109- < div className = 'flex flex-col gap-2 py-4' >
110- < TextEditor
111- placeHolder = { `Username` }
112- onChangeHandler = { ( value ) => handleChange ( value , 'username' ) }
113- name = { 'username' }
114- value = { data . username ? data . username : '' }
115- completionOptions = { getActiveVariables ( ) }
116- styles = { 'w-full' }
117- />
118- < TextEditor
119- placeHolder = { `Password` }
120- onChangeHandler = { ( value ) => handleChange ( value , 'password' ) }
121- name = { 'password' }
122- value = { data . password ? data . password : '' }
123- completionOptions = { getActiveVariables ( ) }
124- styles = { 'w-full' }
125- />
126- </ div >
127- ) }
60+ < div className = 'w-52' >
61+ < Listbox
62+ value = { selected }
63+ onChange = { ( selectedValue ) => {
64+ setSelected ( selectedValue ) ;
65+ setAuthNodeType ( id , selectedValue ) ;
66+ } }
67+ >
68+ < div className = 'relative' >
69+ < Listbox . Button className = 'relative w-full cursor-default rounded border border-cyan-950 p-2 text-left' >
70+ < span className = 'block truncate' > { getAuthType ( ) } </ span >
71+ < span className = 'pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2' >
72+ < ChevronUpDownIcon className = 'h-5 w-5' aria-hidden = 'true' />
73+ </ span >
74+ </ Listbox . Button >
75+ < Transition
76+ as = { Fragment }
77+ leave = 'transition ease-in duration-100'
78+ leaveFrom = 'opacity-100'
79+ leaveTo = 'opacity-0'
80+ >
81+ < Listbox . Options className = 'absolute z-10 mt-1 max-h-60 w-full overflow-auto bg-white py-1 text-base focus:outline-none' >
82+ < Listbox . Option
83+ className = { ( { active } ) =>
84+ `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
85+ active ? 'bg-background-light text-slate-900' : ''
86+ } `
87+ }
88+ value = { 'no-auth' }
89+ >
90+ { ( { selected } ) => (
91+ < >
92+ < span className = { `block` } > No Auth</ span >
93+ { selected ? (
94+ < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
95+ < CheckIcon className = 'h-5 w-5' aria-hidden = 'true' />
96+ </ span >
97+ ) : null }
98+ </ >
99+ ) }
100+ </ Listbox . Option >
101+ < Listbox . Option
102+ className = { ( { active } ) =>
103+ `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
104+ active ? 'bg-background-light text-slate-900' : ''
105+ } `
106+ }
107+ value = { 'basic-auth' }
108+ >
109+ { ( { selected } ) => (
110+ < >
111+ < span className = { `block` } > Basic auth</ span >
112+ { selected ? (
113+ < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
114+ < CheckIcon className = 'h-5 w-5' aria-hidden = 'true' />
115+ </ span >
116+ ) : null }
117+ </ >
118+ ) }
119+ </ Listbox . Option >
120+ < Listbox . Option
121+ className = { ( { active } ) =>
122+ `relative cursor-default select-none py-2 pl-10 pr-4 hover:font-semibold ${
123+ active ? 'bg-background-light text-slate-900' : ''
124+ } `
125+ }
126+ value = { 'bearer-token' }
127+ >
128+ { ( { selected } ) => (
129+ < >
130+ < span className = { `block` } > Bearer Token</ span >
131+ { selected ? (
132+ < span className = 'absolute inset-y-0 left-0 flex items-center pl-3 font-semibold' >
133+ < CheckIcon className = 'h-5 w-5' aria-hidden = 'true' />
134+ </ span >
135+ ) : null }
136+ </ >
137+ ) }
138+ </ Listbox . Option >
139+ </ Listbox . Options >
140+ </ Transition >
141+ </ div >
142+ </ Listbox >
143+ { data . type === 'basic-auth' && (
144+ < div className = 'flex flex-col gap-2 py-4' >
145+ < TextEditor
146+ placeHolder = { `Username` }
147+ onChangeHandler = { ( value ) => handleBasicAuthValueChange ( value , 'username' ) }
148+ name = { 'username' }
149+ value = { data . username ? data . username : '' }
150+ completionOptions = { getActiveVariables ( ) }
151+ styles = { 'w-full' }
152+ />
153+ < TextEditor
154+ placeHolder = { `Password` }
155+ onChangeHandler = { ( value ) => handleBasicAuthValueChange ( value , 'password' ) }
156+ name = { 'password' }
157+ value = { data . password ? data . password : '' }
158+ completionOptions = { getActiveVariables ( ) }
159+ styles = { 'w-full' }
160+ />
161+ </ div >
162+ ) }
163+ { data . type === 'bearer-token' && (
164+ < div className = 'flex flex-col gap-2 py-4' >
165+ < TextEditor
166+ placeHolder = { `Token` }
167+ onChangeHandler = { ( value ) => handleBearerTokenChange ( value ) }
168+ name = { 'token' }
169+ value = { data . token ? data . token : '' }
170+ completionOptions = { getActiveVariables ( ) }
171+ styles = { 'w-full' }
172+ />
173+ </ div >
174+ ) }
175+ </ div >
128176 </ FlowNode >
129177 </ >
130178 ) ;
0 commit comments