Skip to content

Commit 5a282ba

Browse files
committed
react-select new version changes
1 parent 598a625 commit 5a282ba

File tree

12 files changed

+111
-134
lines changed

12 files changed

+111
-134
lines changed

src/components/ChallengeEditor/BillingAccount-Field/index.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,12 @@ const BillingAccountField = ({ accounts, onUpdateSelect, challenge }) => {
1313
<div className={cn(styles.field, styles.col2)}>
1414
<Select
1515
name='billingAccount'
16-
options={accounts}
17-
value={challenge.billingAccount}
16+
options={accounts.map(account => ({ label: account.name, value: account.name, name: account.name }))}
17+
value={{ label: challenge.billingAccount, value: challenge.billingAccount }}
1818
placeholder='Select an existing account'
19-
labelKey='name'
20-
valueKey='name'
21-
clearable={false}
19+
isClearable={false}
2220
onChange={(e) => onUpdateSelect(e)}
23-
disabled={false}
21+
isDisabled={false}
2422
/>
2523
</div>
2624
</div>

src/components/ChallengeEditor/ChallengeSchedule-Field/index.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,10 @@ class ChallengeScheduleField extends Component {
331331
) : (
332332
<Select
333333
name='template'
334-
options={templates}
334+
options={templates.map(template => ({ label: template.name, value: template.name, name: template.name }))}
335335
placeholder='Select'
336-
labelKey='name'
337-
valueKey='name'
338-
clearable={false}
339-
value={currentTemplate}
336+
isClearable={false}
337+
value={currentTemplate && { label: currentTemplate.name, value: currentTemplate.name }}
340338
onChange={(e) => resetPhase(e)}
341339
/>
342340
)}

src/components/ChallengeEditor/Groups-Field/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ import { AUTOCOMPLETE_MIN_LENGTH, AUTOCOMPLETE_DEBOUNCE_TIME_MS, GROUPS_API_URL
1010
const GroupsField = ({ onUpdateMultiSelect, challenge }) => {
1111
async function fetchGroups (name) {
1212
if (!name) return []
13-
console.log('url')
14-
console.log(GROUPS_API_URL)
1513
const url = `${GROUPS_API_URL}?name=${name}`
1614
return axiosInstance.get(url)
1715
}
@@ -38,12 +36,12 @@ const GroupsField = ({ onUpdateMultiSelect, challenge }) => {
3836
<div className={cn(styles.field, styles.col2)}>
3937
<AsyncSelect
4038
name='group'
41-
multi
39+
isMulti
4240
loadOptions={(inputValue, callback) => {
4341
onInputChange(inputValue, callback)
4442
}}
4543
simpleValue
46-
value={challenge.groups.join(',')}
44+
multivalue={challenge.groups}
4745
placeholder='Select groups'
4846
onChange={(e) => onUpdateMultiSelect(e, 'groups')}
4947
/>

src/components/ChallengeEditor/ReviewType-Field/index.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,12 @@ const ReviewTypeField = ({ reviewers, challenge, onUpdateOthers, onUpdateSelect
7777
isInternal && (
7878
<Select
7979
name='reviewer'
80-
options={reviewers}
80+
options={reviewers.map(({ handle }) => ({ label: handle, value: handle }))}
8181
placeholder='Select Reviewer'
82-
labelKey='handle'
83-
valueKey='handle'
84-
clearable={false}
85-
value={challenge.reviewer}
86-
onChange={(e) => onUpdateSelect(e.handle, false, 'reviewer')}
87-
disabled={false}
82+
value={{ label: challenge.reviewer, value: challenge.reviewer }}
83+
isClearable={false}
84+
onChange={(e) => onUpdateSelect(e.value, false, 'reviewer')}
85+
isDisabled={false}
8886
/>
8987
)
9088
}

src/components/ChallengeEditor/TagsField/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ const TagsField = ({ challengeTags, challenge, onUpdateMultiSelect, readOnly })
1919
<span>{existingTags}</span>
2020
) : (<Select
2121
id='track-select'
22-
multi
22+
isMulti
2323
options={challengeTags.map(mapOps)}
2424
simpleValue
25-
value={existingTags}
25+
multivalue={challenge.tags && challenge.tags.map(tag => ({ label: tag, value: tag }))}
2626
onChange={(value) => onUpdateMultiSelect(value, 'tags')}
2727
/>)}
2828
</div>

src/components/ChallengeEditor/Terms-Field/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ const TermsField = ({ terms, challenge, onUpdateMultiSelect }) => {
1515
<input type='hidden' />
1616
<Select
1717
id='track-select'
18-
multi
18+
isMulti
1919
options={terms.map(mapOps)}
2020
simpleValue
21-
value={challenge.terms}
21+
multivalue={challenge.terms}
2222
onChange={(value) => onUpdateMultiSelect(value, 'terms')}
2323
/>
2424
</div>

src/components/ChallengeEditor/Type-Field/index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@ const TypeField = ({ types, onUpdateSelect, challenge, disabled }) => {
1515
<div className={cn(styles.field, styles.col2, { [styles.disabled]: disabled })}>
1616
<Select
1717
name='track'
18-
options={_.filter(types, t => t.isActive)}
19-
value={challenge.typeId}
18+
options={_.filter(types, t => t.isActive).map(type => ({ label: type.name, value: type.id }))}
2019
placeholder='Work Format'
21-
labelKey='name'
22-
valueKey='id'
23-
clearable={false}
24-
onChange={(e) => onUpdateSelect(e.id, false, 'typeId')}
25-
disabled={disabled}
20+
isClearable={false}
21+
onChange={(e) => onUpdateSelect(e.value, false, 'typeId')}
22+
isDisabled={disabled}
2623
/>
2724
</div>
2825
</div>

src/components/ChallengeEditor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ class ChallengeEditor extends Component {
708708
onUpdateMultiSelect (options, field) {
709709
const { challenge } = this.state
710710
let newChallenge = { ...challenge }
711-
newChallenge[field] = options ? options.split(',') : []
711+
newChallenge[field] = options ? options.map(option => option.value) : []
712712

713713
this.setState({ challenge: newChallenge }, () => {
714714
this.validateChallenge()

src/components/PhaseInput/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,9 @@ class PhaseInput extends Component {
7777
<div className={styles.scorecards}>
7878
<Select
7979
name='scorecard'
80-
options={phase.scorecards}
80+
options={phase.scorecards.map(({ name }) => ({ label: name, value: name, name }))}
8181
placeholder='Select Scorecard'
82-
labelKey='name'
83-
valueKey='name'
84-
clearable={false}
82+
isClearable={false}
8583
value={phase.scorecard}
8684
onChange={(e) => onUpdateSelect(e, true, 'phases')}
8785
/>

src/components/Select/AsyncSelect.js

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,16 @@ import React from 'react'
22
import _ from 'lodash'
33
import ReactSelect from 'react-select/async'
44
import PT from 'prop-types'
5+
import styles from './styles'
56

67
export default function Select (props) {
78
const { selectRef } = props
8-
const customStyles = {
9-
container: (provided) => ({
10-
...provided,
11-
width: '100%',
12-
minWidth: '150px',
13-
background: 'red'
14-
}),
15-
control: (provided) => ({
16-
...provided,
17-
borderRadius: '2px !important',
18-
':focus': {
19-
border: '1px solid #2C95D7',
20-
boxShadow: 'none'
21-
}
22-
}),
23-
menu: (provided) => ({
24-
...provided,
25-
boxSizing: 'border-box',
26-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
27-
fontSize: '15px',
28-
fontWeight: 300,
29-
lineHeight: '18px',
30-
color: '#2a2a2a',
31-
border: '1px solid #2C95D7',
32-
zIndex: 4
33-
}),
34-
option: (provided) => ({
35-
...provided,
36-
paddingLeft: '20px'
37-
}),
38-
placeholder: (provided) => ({
39-
...provided,
40-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
41-
fontSize: '15px',
42-
fontWeight: 300,
43-
paddingLeft: '20px',
44-
color: '#2a2a2a'
45-
}),
46-
input: (provided) => ({
47-
...provided,
48-
backgroundColor: 'transparent',
49-
marginLeft: 0,
50-
paddingRight: '6px',
51-
paddingLeft: '10px',
52-
border: 'none'
53-
})
54-
}
559
return (
5610
<ReactSelect
5711
ref={selectRef}
5812
{...props}
5913
autosize={false}
60-
styles={customStyles}
14+
styles={styles}
6115
/>
6216
)
6317
}

src/components/Select/index.js

Lines changed: 2 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -2,62 +2,16 @@ import React from 'react'
22
import _ from 'lodash'
33
import ReactSelect from 'react-select'
44
import PT from 'prop-types'
5+
import styles from './styles'
56

67
export default function Select (props) {
78
const { selectRef } = props
8-
const customStyles = {
9-
container: (provided) => ({
10-
...provided,
11-
width: '100%',
12-
minWidth: '150px',
13-
background: 'red'
14-
}),
15-
control: (provided) => ({
16-
...provided,
17-
borderRadius: '2px !important',
18-
':focus': {
19-
border: '1px solid #2C95D7',
20-
boxShadow: 'none'
21-
}
22-
}),
23-
menu: (provided) => ({
24-
...provided,
25-
boxSizing: 'border-box',
26-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
27-
fontSize: '15px',
28-
fontWeight: 300,
29-
lineHeight: '18px',
30-
color: '#2a2a2a',
31-
border: '1px solid #2C95D7',
32-
zIndex: 4
33-
}),
34-
option: (provided) => ({
35-
...provided,
36-
paddingLeft: '20px'
37-
}),
38-
placeholder: (provided) => ({
39-
...provided,
40-
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
41-
fontSize: '15px',
42-
fontWeight: 300,
43-
paddingLeft: '20px',
44-
color: '#2a2a2a'
45-
}),
46-
input: (provided) => ({
47-
...provided,
48-
backgroundColor: 'transparent',
49-
marginLeft: 0,
50-
paddingRight: '6px',
51-
paddingLeft: '10px',
52-
border: 'none'
53-
})
54-
}
559
return (
5610
<ReactSelect
5711
ref={selectRef}
5812
{...props}
5913
autosize={false}
60-
styles={customStyles}
14+
styles={styles}
6115
/>
6216
)
6317
}

src/components/Select/styles.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
export default {
2+
container: (provided) => ({
3+
...provided,
4+
width: '100%'
5+
}),
6+
control: (provided, state) => {
7+
console.log('state')
8+
console.log(state)
9+
let styles = {
10+
...provided,
11+
borderRadius: '2px !important'
12+
}
13+
if (state.isFocused) {
14+
styles = {
15+
...styles,
16+
border: '1px solid #2C95D7',
17+
boxShadow: 'none'
18+
}
19+
}
20+
return styles
21+
},
22+
menu: (provided) => ({
23+
...provided,
24+
boxSizing: 'border-box',
25+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
26+
fontSize: '15px',
27+
fontWeight: 300,
28+
lineHeight: '18px',
29+
color: '#2a2a2a',
30+
border: '1px solid #2C95D7',
31+
borderRadius: 0,
32+
zIndex: 4,
33+
margin: 0,
34+
padding: 0
35+
}),
36+
menuList: (provided) => ({
37+
...provided,
38+
padding: 0
39+
}),
40+
option: (provided) => ({
41+
...provided,
42+
paddingLeft: '20px'
43+
}),
44+
placeholder: (provided) => ({
45+
...provided,
46+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
47+
fontSize: '15px',
48+
fontWeight: 300,
49+
paddingLeft: '20px',
50+
color: '#2a2a2a'
51+
}),
52+
input: (provided) => ({
53+
...provided,
54+
backgroundColor: 'transparent',
55+
marginLeft: 0,
56+
paddingRight: '6px',
57+
paddingLeft: '10px',
58+
border: 'none',
59+
input: {
60+
width: 'auto !important',
61+
height: 'auto !important',
62+
lineHeight: 'normal !important'
63+
}
64+
}),
65+
multiValue: (provided) => ({
66+
...provided,
67+
backgroundColor: '#2c95d7'
68+
}),
69+
multiValueLabel: (provided) => ({
70+
...provided,
71+
color: 'white'
72+
}),
73+
multiValueRemove: (provided) => ({
74+
...provided,
75+
margin: '4px 4px',
76+
height: '16px',
77+
width: '16px',
78+
backgroundColor: '#c6def1',
79+
color: '#2C95D7',
80+
borderRadius: '50%'
81+
})
82+
}

0 commit comments

Comments
 (0)