14
14
* limitations under the License.
15
15
*/
16
16
17
- import React , { useState , useEffect , useContext , Fragment } from 'react'
18
- import { RadioGroup , RadioGroupItem , ConditionType , PluginType , CustomInput , PipelineFormType } from '@devtron-labs/devtron-fe-common-lib'
19
- import ReactSelect , { components } from 'react-select'
17
+ import { useState , useEffect , useContext , Fragment } from 'react'
18
+ import {
19
+ RadioGroup ,
20
+ RadioGroupItem ,
21
+ ConditionType ,
22
+ PluginType ,
23
+ CustomInput ,
24
+ PipelineFormType ,
25
+ SelectPicker ,
26
+ SelectPickerVariantType ,
27
+ } from '@devtron-labs/devtron-fe-common-lib'
20
28
import { ReactComponent as Dropdown } from '../../assets/icons/ic-chevron-down.svg'
21
29
import { ConditionContainerType } from '../ciPipeline/types'
22
30
import { ReactComponent as Close } from '../../assets/icons/ic-close.svg'
23
31
import { ReactComponent as Add } from '../../assets/icons/ic-add.svg'
24
- import { getCustomOptionSelectionStyle } from '../v2/common/ReactSelect.utils'
25
- import { selectOperatorStyle , selectVariableStyle } from './ciPipeline.utils'
26
32
import { OptionType } from '../app/types'
27
33
import { ReactComponent as AlertTriangle } from '../../assets/icons/ic-alert-triangle.svg'
28
34
import { pipelineContext } from '../workflowEditor/workflowEditor'
@@ -157,7 +163,7 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
157
163
setFormData ( _formData )
158
164
}
159
165
160
- const handleConditionOnVariableChange = ( selectedValue : { label : string ; value : number } , index : number ) : void => {
166
+ const handleConditionOnVariableChange = ( index : number ) => ( selectedValue : OptionType ) => {
161
167
const _formData = { ...formData }
162
168
_formData [ activeStageName ] . steps [ selectedTaskIndex ] [ currentStepTypeVariable ] . conditionDetails [ index ] [
163
169
'conditionOnVariable'
@@ -166,7 +172,7 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
166
172
setFormData ( _formData )
167
173
}
168
174
169
- const handleConditionOperatorChange = ( selectedValue : OptionType , index : number ) : void => {
175
+ const handleConditionOperatorChange = ( index : number ) => ( selectedValue : OptionType ) : void => {
170
176
setSelectedOperator ( selectedValue )
171
177
const _formData = { ...formData }
172
178
_formData [ activeStageName ] . steps [ selectedTaskIndex ] [ currentStepTypeVariable ] . conditionDetails [ index ] [
@@ -175,37 +181,6 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
175
181
setFormData ( _formData )
176
182
}
177
183
178
- function formatOptionLabel ( option ) {
179
- return (
180
- < div className = "flexbox justify-space" >
181
- < span className = "cn-9" > { option . label } </ span >
182
- < span className = "cn-5" > { option . description } </ span >
183
- </ div >
184
- )
185
- }
186
-
187
- const ValueContainer = ( props ) => {
188
- const value = props . getValue ( ) [ 0 ] ?. label
189
- return (
190
- < components . ValueContainer { ...props } >
191
- < >
192
- { ! props . selectProps . menuIsOpen && ( value || < span className = "cn-5" > Select variable</ span > ) }
193
- { React . cloneElement ( props . children [ 1 ] ) }
194
- </ >
195
- </ components . ValueContainer >
196
- )
197
- }
198
-
199
- const Option = ( _props ) => {
200
- const { selectProps, selectOption, data } = _props
201
- selectProps . styles . option = getCustomOptionSelectionStyle ( { padding : '4px 10px' } )
202
- return (
203
- < div className = "flex left" >
204
- < components . Option { ..._props } > { _props . children } </ components . Option >
205
- </ div >
206
- )
207
- }
208
-
209
184
const handleConditionCollapse = ( ) : void => {
210
185
setCollapsedSection ( ! collapsedSection )
211
186
if ( collapsedSection ) {
@@ -269,14 +244,9 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
269
244
return (
270
245
< div >
271
246
< div className = "mb-10 flexbox justify-space" >
272
- < span
273
- className = "fw-6 fs-13 cn-9"
274
- onClick = { ( event ) => {
275
- handleConditionCollapse ( )
276
- } }
277
- >
247
+ < div className = "fw-6 fs-13 cn-9" onClick = { handleConditionCollapse } >
278
248
{ type } Condition
279
- </ span >
249
+ </ div >
280
250
281
251
< Dropdown
282
252
className = "pointer"
@@ -321,13 +291,15 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
321
291
formDataErrorObj [ activeStageName ] . steps [ selectedTaskIndex ] [ currentStepTypeVariable ]
322
292
?. conditionDetails ?. [ index ]
323
293
return conditionDetail . conditionType === conditionType ? (
324
- < Fragment key = { `condtion__ ${ index } ` } >
325
- < div className = "condition-container" >
326
- < div className = "tp-4 fs-13 lh-32 fw-4 dc__uppercase mr-10 " >
294
+ < Fragment key = { `condition__ ${ index } ` } >
295
+ < div className = "condition-container dc__gap-8 " >
296
+ < div className = "tp-4 fs-13 lh-32 fw-4 dc__uppercase" >
327
297
{ conditionDetail . conditionType } If
328
298
</ div >
329
- < div className = "tp-4 fs-13 fw-4 mr-10" >
330
- < ReactSelect
299
+ < div className = "flex left" >
300
+ < SelectPicker
301
+ inputId = "condition-on-variable"
302
+ classNamePrefix = "condition-on-variable"
331
303
autoFocus
332
304
value = {
333
305
conditionDetail . conditionOnVariable
@@ -337,11 +309,8 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
337
309
}
338
310
: null
339
311
}
340
- tabIndex = { 1 }
341
312
placeholder = "Select variable"
342
- onChange = { ( selectedValue ) => {
343
- handleConditionOnVariableChange ( selectedValue , index )
344
- } }
313
+ onChange = { handleConditionOnVariableChange ( index ) }
345
314
options = { formData [ activeStageName ] . steps [ selectedTaskIndex ] [
346
315
currentStepTypeVariable
347
316
] [
@@ -352,40 +321,25 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
352
321
?. filter ( ( variable ) => variable . name )
353
322
. map ( ( variable ) => ( { label : variable . name , value : variable . id } ) ) }
354
323
isSearchable = { false }
355
- styles = { selectVariableStyle }
356
- components = { {
357
- IndicatorSeparator : null ,
358
- Option,
359
- ValueContainer,
360
- } }
324
+ variant = { SelectPickerVariantType . BORDER_LESS }
361
325
/>
362
326
</ div >
363
- < div className = "fw-4 mr-10" >
364
- < ReactSelect
365
- defaultValue = {
366
- conditionDetail . conditionOperator
367
- ? {
368
- label : conditionDetail . conditionOperator ,
369
- value : conditionDetail . conditionOperator ,
370
- }
371
- : selectedOperator
372
- }
373
- tabIndex = { 1 }
374
- onChange = { ( selectedValue ) => {
375
- handleConditionOperatorChange ( selectedValue , index )
376
- } }
377
- options = { operatorOptions }
378
- isSearchable = { false }
379
- styles = { selectOperatorStyle }
380
- formatOptionLabel = { formatOptionLabel }
381
- components = { {
382
- IndicatorSeparator : null ,
383
- Option,
384
- ValueContainer,
385
- } }
386
- />
387
- </ div >
388
- < div className = "fs-13 mr-10" >
327
+ < SelectPicker
328
+ inputId = "condition-operator"
329
+ classNamePrefix = "condition-operator"
330
+ value = {
331
+ conditionDetail . conditionOperator
332
+ ? {
333
+ label : conditionDetail . conditionOperator ,
334
+ value : conditionDetail . conditionOperator ,
335
+ }
336
+ : selectedOperator
337
+ }
338
+ onChange = { handleConditionOperatorChange ( index ) }
339
+ options = { operatorOptions }
340
+ isSearchable = { false }
341
+ />
342
+ < div className = "fs-13" >
389
343
< CustomInput
390
344
name = "conditionalValue"
391
345
rootClassName = "w-100 en-2 bw-1 pl-10 pr-10 pt-6 pb-6 br-4 h-32"
@@ -405,7 +359,6 @@ export const ConditionContainer = ({ type }: { type: ConditionContainerType }) =
405
359
< div className = "flexbox cr-5 mb-8 fw-5 fs-11 flexbox" >
406
360
{ errorObj && ! errorObj . isValid && (
407
361
< >
408
- { ' ' }
409
362
< AlertTriangle className = "icon-dim-14 mr-5 ml-5 mt-2" />
410
363
< span > { errorObj . message } </ span >
411
364
</ >
0 commit comments