Skip to content

Commit 0daaf49

Browse files
authored
Merge pull request #2870 from gautam1168/reactselectversionupdate
fix issue #2870
2 parents 0b36a62 + 23b36d6 commit 0daaf49

File tree

14 files changed

+1822
-1493
lines changed

14 files changed

+1822
-1493
lines changed

package-lock.json

Lines changed: 1584 additions & 1319 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
@@ -130,7 +130,7 @@
130130
"react-s-alert": "^1.1.4",
131131
"react-scroll": "^1.7.6",
132132
"react-scroll-lock-component": "^1.1.2",
133-
"react-select": "^0.9.1",
133+
"react-select": "^2.4.0",
134134
"react-stickynode": "^1.2.1",
135135
"react-text-truncate": "^0.8.3",
136136
"react-transition-group": "^2.5.0",

src/components/FileList/FileListItem.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,10 @@ export default class FileListItem extends React.Component {
113113
{ (errors && errors.title) && <div className="error-message">{ errors.title }</div> }
114114
<textarea defaultValue={description} ref="desc" maxLength={250} className="tc-textarea" />
115115
{ (errors && errors.desc) && <div className="error-message">{ errors.desc }</div> }
116-
<UserAutoComplete onUpdate={this.onUserIdChange}
116+
<UserAutoComplete onUpdate={this.onUserIdChange}
117117
projectMembers={projectMembers}
118118
loggedInUser={loggedInUser}
119-
selectedUsers={this.userIdsToHandles(allowedUsers).join(',')}
119+
selectedUsers={this.userIdsToHandles(allowedUsers).join(',')}
120120
/>
121121
</div>
122122
)

src/components/LinksMenu/EditFileAttachment.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class EditFileAttachment extends React.Component {
5656
<UserAutoComplete onUpdate={this.onUserIdChange}
5757
projectMembers={projectMembers}
5858
loggedInUser={loggedInUser}
59-
selectedUsers={this.userIdsToHandles(allowedUsers).join(',')}
59+
selectedUsers={this.userIdsToHandles(allowedUsers).map(user => ({value: user, label: user}))}
6060
/>
6161
{showVisibleToAllProjectMembersText && <div className="project-members-visible">
6262
There are no specified file viewers. File will be visible to all project members.

src/components/Select/Select.jsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,36 @@
88
*/
99
import React from 'react'
1010
import ReactSelect from 'react-select'
11-
import 'react-select/dist/react-select.css'
11+
import CreatableSelect from 'react-select/lib/Creatable'
1212
import './Select.scss'
1313

1414
const Select = (props) => {
15-
return (
16-
<ReactSelect {...props} />
17-
)
15+
let containerclass = 'react-select-hiddendropdown-container'
16+
if (props.showDropdownIndicator) {
17+
containerclass = 'react-select-container'
18+
}
19+
20+
if (props.createOption) {
21+
return (
22+
<CreatableSelect
23+
{...props}
24+
createOptionPosition="first"
25+
className={containerclass}
26+
classNamePrefix="react-select"
27+
noOptionsMessage={() => ('Type to search')}
28+
/>
29+
)
30+
} else {
31+
return (
32+
<ReactSelect
33+
{...props}
34+
createOptionPosition="first"
35+
className={containerclass}
36+
classNamePrefix="react-select"
37+
noOptionsMessage={() => ('Type to search')}
38+
/>
39+
)
40+
}
1841
}
1942

2043
export default Select

src/components/Select/Select.scss

Lines changed: 75 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,79 @@
11
@import '~tc-ui/src/styles/tc-includes';
22

33
:global {
4-
.Select {
5-
line-height: normal;
6-
text-align: left;
7-
}
8-
9-
/* to override input styles use same params like in tc-includes */
10-
.Select-input {
11-
height: 28px;
12-
}
13-
14-
.Select-input > input:not([type="checkbox"]) {
15-
border: 0 none;
16-
height: 28px;
17-
line-height: 17px;
18-
padding: 0;
19-
transition: none;
20-
21-
&:focus:not(.error),
22-
&:active {
23-
box-shadow: none;
24-
}
25-
}
26-
27-
.Select-placeholder {
28-
@include roboto;
29-
color: $tc-gray-50;
30-
font-size: 13px;
31-
line-height: 28px;
32-
}
33-
34-
.Select-control {
35-
height: 30px;
36-
}
37-
38-
.Select-item {
39-
background-color: $tc-gray-10;
40-
border: 0;
41-
height: 21px;
42-
margin-left: 4px;
43-
margin-top: 4px;
44-
padding: 0 10px 0 4px;
45-
}
46-
47-
.Select-item-label {
48-
@include roboto-medium;
49-
display: inline;
50-
color: $tc-black;
51-
font-size: 13px;
52-
line-height: 20px;
53-
padding: 0 0 0 4px;
54-
}
55-
56-
.Select-item-icon {
57-
color:$tc-gray-40;
58-
border-right-color: $tc-gray-10;
59-
padding: 0 5px 1px;
60-
61-
&:active,
62-
&:focus,
63-
&:hover {
64-
background-color: transparent;
65-
color: $tc-red-110;
66-
}
67-
}
68-
69-
.Select-option {
70-
@include roboto-medium;
71-
color: $tc-black;
72-
font-size: 13px;
73-
padding-top: 5px;
74-
padding-bottom: 6px;
75-
76-
&:hover,
77-
&.is-focused {
78-
background-color: $tc-gray-neutral-dark;
79-
}
80-
}
81-
82-
.Select-noresults,
83-
.Select-search-prompt,
84-
.Select-searching {
85-
@include roboto-medium;
86-
color: $tc-gray-50;
87-
font-size: 13px;
88-
}
4+
$reactselectheight : 40px;
5+
$reactselectcontentheight: 20px;
6+
@mixin reactselectstyles {
7+
8+
& .react-select__control:hover {
9+
border-color: $tc-gray-50;
10+
}
11+
12+
& .react-select__control--is-focused {
13+
border-color: #0681ff !important;
14+
box-shadow: 0 0 2px 0 rgba(6, 129, 255, 0.7) !important;
15+
}
16+
17+
& .react-select__control {
18+
height: $reactselectheight;
19+
border-color: $tc-gray-30;
20+
box-shadow: none;//0 0 2px 0 rgba(6, 129, 255, 0.7) !important;
21+
22+
& > div {
23+
height: $reactselectheight - 2px;
24+
}
25+
26+
& > div:nth-child(1) > div:nth-last-child(1) {
27+
height: $reactselectcontentheight + 4px;
28+
}
29+
30+
& input {
31+
height: $reactselectcontentheight;
32+
line-height: $reactselectcontentheight;
33+
transition: none !important;
34+
box-shadow: none !important;
35+
-webkit-box-shadow: none !important;
36+
}
37+
38+
}
39+
40+
& .react-select__value-container {
41+
& > div:nth-last-child(1) {
42+
height: $reactselectcontentheight + 4px;
43+
}
44+
}
45+
46+
& .react-select__option {
47+
@include roboto-medium;
48+
font-size: 13px;
49+
}
50+
51+
& .react-select__multi-value {
52+
background-color: $tc-gray-20 !important;
53+
font-weight: bold;
54+
}
55+
56+
& .react-select__menu-notice--no-options {
57+
text-align : left !important;
58+
font-size : 15px;
59+
color: $tc-gray-50;
60+
}
61+
}
62+
.react-select-hiddendropdown-container {
63+
@include reactselectstyles;
64+
/*hide dropdown indicator*/
65+
& .react-select__control {
66+
& > div:nth-child(2) {
67+
display: none;
68+
}
69+
& .react-select__dropdown-indicator {
70+
display: none;
71+
}
72+
}
73+
}
74+
75+
.react-select-container {
76+
@include reactselectstyles;
77+
}
78+
8979
}
90-
Lines changed: 8 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import React from 'react'
22
import PropTypes from 'prop-types'
3-
import {findIndex} from 'lodash'
43
import Select from '../Select/Select'
54
import './AutocompleteInput.scss'
6-
import {loadMemberSuggestions} from '../../api/projectMembers'
7-
import {AUTOCOMPLETE_TRIGGER_LENGTH} from '../../config/constants'
85

96
/**
107
* Render a searchable dropdown for selecting users that can be invited
@@ -13,78 +10,27 @@ class AutocompleteInput extends React.Component {
1310
constructor(props) {
1411
super(props)
1512

16-
this.onChange = this.onChange.bind(this)
17-
this.asyncOptions = this.asyncOptions.bind(this)
18-
19-
this.debounceTimer = null
20-
}
21-
22-
// cannot use debounce method from lodash, because we have to return Promise
23-
loadMemberSuggestionsDebounced(value) {
24-
return new Promise((resolve) => {
25-
if (this.debounceTimer) {
26-
clearTimeout(this.debounceTimer)
27-
}
28-
29-
this.debounceTimer = setTimeout(() => {
30-
resolve(loadMemberSuggestions(value))
31-
}, 500)
32-
})
33-
}
34-
35-
onChange(inputValue, selectedOptions = []) {
36-
const { onUpdate } = this.props
37-
38-
if (onUpdate) {
39-
onUpdate(selectedOptions)
40-
}
41-
}
42-
43-
asyncOptions(input) {
44-
const { allMembers } = this.props
45-
46-
const value = typeof input === 'string' ? input : ''
47-
const createOption = {
48-
handle: value,
49-
// Decide if it's email
50-
isEmail: (/(.+)@(.+){2,}\.(.+){2,}/).test(value),
51-
}
52-
if (value.length >= AUTOCOMPLETE_TRIGGER_LENGTH) {
53-
return this.loadMemberSuggestionsDebounced(value).then(r => {
54-
// Remove current members from suggestions
55-
const suggestions = r.filter(suggestion => (
56-
findIndex(allMembers, (member) => member.handle === suggestion.handle) === -1 &&
57-
// Remove current value from list to add it manually on top
58-
suggestion.handle !== value
59-
))
60-
// Only allow creation if it is not already exists in members
61-
const shouldIncludeCreateOption = findIndex(allMembers, (member) => member.handle === value) === -1
62-
63-
return Promise.resolve({options: shouldIncludeCreateOption?[createOption, ...suggestions]: suggestions})
64-
}).catch( () => {
65-
return Promise.resolve({options: [createOption] })
66-
})
67-
}
68-
return Promise.resolve({options: value.length > 0 ? [createOption] : []})
6913
}
7014

7115
render() {
7216
const {
7317
placeholder,
7418
selectedMembers,
75-
disabled,
19+
disabled
7620
} = this.props
7721

7822
return (
7923
<div className="autocomplete-wrapper">
8024
<Select
81-
multi
25+
isMulti
26+
closeMenuOnSelect
27+
showDropdownIndicator={false}
28+
createOption
8229
placeholder={placeholder}
8330
value={selectedMembers}
84-
onChange={this.onChange}
85-
asyncOptions={this.asyncOptions}
86-
valueKey="handle"
87-
labelKey="handle"
31+
onInputChange={this.props.onInputChange}
32+
onChange={this.props.onUpdate}
33+
options={this.props.suggestedMembers}
8834
disabled={disabled}
8935
/>
9036
</div>
@@ -132,5 +78,4 @@ AutocompleteInput.propTypes = {
13278
allMembers: PropTypes.arrayOf(PropTypes.object)
13379
}
13480

135-
13681
export default AutocompleteInput

0 commit comments

Comments
 (0)