Skip to content

Commit ca73946

Browse files
authored
Merge pull request #1032 from CDharmateja/develop
groups filter from api
2 parents 3e113c9 + 311bcb1 commit ca73946

File tree

16 files changed

+363
-193
lines changed

16 files changed

+363
-193
lines changed

package-lock.json

Lines changed: 155 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"react-redux": "^6.0.0",
8080
"react-redux-toastr": "^7.5.1",
8181
"react-router-dom": "^4.3.1",
82-
"react-select": "^1.2.0",
82+
"react-select": "^3.1.1",
8383
"react-stickynode": "^2.1.1",
8484
"react-svg": "^4.1.1",
8585
"react-tabs": "^3.0.0",

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
)}
Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,69 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
3-
import Select from '../../Select'
3+
import AsyncSelect from '../../Select/AsyncSelect'
44
import cn from 'classnames'
55
import styles from './Groups-Field.module.scss'
6+
import _ from 'lodash'
7+
import { fetchGroups } from '../../../services/challenges'
8+
import { AUTOCOMPLETE_MIN_LENGTH, AUTOCOMPLETE_DEBOUNCE_TIME_MS } from '../../../config/constants'
9+
10+
const GroupsField = ({ onUpdateMultiSelect, challenge }) => {
11+
const [groups, setGroups] = React.useState([])
12+
13+
const onInputChange = React.useCallback(_.debounce(async (inputValue, callback) => {
14+
if (!inputValue) return
15+
const preparedValue = inputValue.trim()
16+
if (preparedValue.length < AUTOCOMPLETE_MIN_LENGTH) {
17+
return []
18+
}
19+
const data = await fetchGroups({ name: inputValue })
20+
const suggestions = data.map(suggestion => ({
21+
label: suggestion.name,
22+
value: suggestion.id
23+
}))
24+
callback && callback(suggestions)
25+
}, AUTOCOMPLETE_DEBOUNCE_TIME_MS), [])
26+
27+
React.useEffect(() => {
28+
Promise.all(
29+
challenge.groups
30+
.map(group => fetchGroups({}, `/${group}`))
31+
).then(groups => {
32+
setGroups(groups.map(group => ({
33+
label: group.name,
34+
value: group.id
35+
})))
36+
}).catch(console.error)
37+
}, [])
638

7-
const GroupsField = ({ groups, onUpdateMultiSelect, challenge }) => {
839
return (
940
<div className={styles.row}>
1041
<div className={cn(styles.field, styles.col1)}>
1142
<label htmlFor='type'>Groups :</label>
1243
</div>
1344
<div className={cn(styles.field, styles.col2)}>
14-
<Select
45+
<AsyncSelect
1546
name='group'
16-
multi
17-
options={groups.map(g => ({ label: g.name, value: g.id }))}
47+
isMulti
48+
loadOptions={(inputValue, callback) => {
49+
onInputChange(inputValue, callback)
50+
}}
1851
simpleValue
19-
value={challenge.groups.join(',')}
52+
value={groups}
2053
placeholder='Select groups'
21-
onChange={(e) => onUpdateMultiSelect(e, 'groups')}
54+
onChange={(e) => {
55+
onUpdateMultiSelect(e, 'groups')
56+
setGroups(e)
57+
}}
2258
/>
2359
</div>
2460
</div>
2561
)
2662
}
2763

28-
GroupsField.defaultProps = {
29-
groups: []
30-
}
31-
3264
GroupsField.propTypes = {
3365
onUpdateMultiSelect: PropTypes.func.isRequired,
34-
challenge: PropTypes.shape().isRequired,
35-
groups: PropTypes.arrayOf(PropTypes.shape()).isRequired
66+
challenge: PropTypes.shape().isRequired
3667
}
3768

3869
export default GroupsField

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

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

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+
value={challenge.tags && challenge.tags.map(tag => ({ label: tag, value: tag }))}
2626
onChange={(value) => onUpdateMultiSelect(value, 'tags')}
2727
/>)}
2828
</div>

0 commit comments

Comments
 (0)