-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6941 from topcoder-platform/deploy_29_Nov
Deploy 29 nov
- Loading branch information
Showing
20 changed files
with
432 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
src/shared/components/GUIKit/DropdownSingleSkills/index.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
/* eslint-disable jsx-a11y/label-has-for */ | ||
/** | ||
* Dropdown terms component. | ||
*/ | ||
import React, { | ||
useRef, | ||
useEffect, | ||
} from 'react'; | ||
import PT from 'prop-types'; | ||
import { AsyncCreatable } from 'react-select'; | ||
import './style.scss'; | ||
|
||
function DropdownSingleSkills({ | ||
terms, | ||
placeholder, | ||
label, | ||
required, | ||
onChange, | ||
errorMsg, | ||
cacheOptions, | ||
loadOptions, | ||
createText, | ||
}) { | ||
const containerRef = useRef(null); | ||
useEffect(() => { | ||
const selectInput = containerRef.current.getElementsByClassName('Select-input'); | ||
if (selectInput && selectInput.length) { | ||
const inputField = selectInput[0].getElementsByTagName('input'); | ||
inputField[0].style.border = 'none'; | ||
inputField[0].style.boxShadow = 'none'; | ||
selectInput[0].style.borderTop = 'none'; | ||
} | ||
}, [terms]); | ||
|
||
const CustomReactSelectRow = React.forwardRef(({ | ||
className, | ||
option, | ||
children, | ||
onSelect, | ||
}, ref) => (children ? ( | ||
<a | ||
ref={ref} | ||
role="button" | ||
className={className} | ||
onMouseDown={(event) => { | ||
event.preventDefault(); | ||
event.stopPropagation(); | ||
onSelect(option, event); | ||
}} | ||
title={option.title} | ||
tabIndex={-1} | ||
> | ||
{children} | ||
</a> | ||
) : null)); | ||
|
||
CustomReactSelectRow.defaultProps = { | ||
children: null, | ||
className: '', | ||
onSelect: () => {}, | ||
}; | ||
|
||
CustomReactSelectRow.propTypes = { | ||
children: PT.node, | ||
className: PT.string, | ||
onSelect: PT.func, | ||
option: PT.object.isRequired, | ||
}; | ||
|
||
return ( | ||
<div | ||
ref={containerRef} | ||
className="dropdownContainer" | ||
styleName={`container ${ | ||
terms ? 'haveValue' : '' | ||
} ${errorMsg ? 'haveError' : ''}`} | ||
> | ||
<div styleName="relative"> | ||
<AsyncCreatable | ||
autosize={false} | ||
optionComponent={CustomReactSelectRow} | ||
value={terms ? { | ||
value: terms, | ||
label: terms, | ||
} : null} | ||
onChange={(value) => { | ||
onChange(value ? (value.value || '') : ''); | ||
}} | ||
defaultValue={terms ? { | ||
value: terms, | ||
label: terms, | ||
} : null} | ||
promptTextCreator={value => `${createText} "${value}"`} | ||
placeholder={`${placeholder}${placeholder && required ? ' *' : ''}`} | ||
cacheOptions={cacheOptions} | ||
loadOptions={loadOptions} | ||
/> | ||
</div> | ||
{label ? ( | ||
<span styleName="label"> | ||
{label} | ||
{required ? <span> *</span> : null} | ||
</span> | ||
) : null} | ||
{errorMsg ? <span styleName="errorMessage">{errorMsg}</span> : null} | ||
</div> | ||
); | ||
} | ||
|
||
DropdownSingleSkills.defaultProps = { | ||
terms: '', | ||
placeholder: '', | ||
label: '', | ||
required: false, | ||
cacheOptions: false, | ||
onChange: () => {}, | ||
errorMsg: '', | ||
createText: 'Select', | ||
loadOptions: undefined, | ||
}; | ||
|
||
DropdownSingleSkills.propTypes = { | ||
terms: PT.string, | ||
placeholder: PT.string, | ||
label: PT.string, | ||
required: PT.bool, | ||
cacheOptions: PT.bool, | ||
onChange: PT.func, | ||
errorMsg: PT.string, | ||
createText: PT.string, | ||
loadOptions: PT.func, | ||
}; | ||
|
||
export default DropdownSingleSkills; |
71 changes: 71 additions & 0 deletions
71
src/shared/components/GUIKit/DropdownSingleSkills/style.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
@import '../Dropdown/style.scss'; | ||
|
||
.label { | ||
z-index: 6; | ||
} | ||
|
||
.relative { | ||
position: relative; | ||
} | ||
|
||
.errorMessage, | ||
.haveValue, | ||
.haveError { | ||
font-family: Roboto, sans-serif; | ||
} | ||
|
||
.container { | ||
font-family: Roboto, sans-serif; | ||
|
||
:global { | ||
.Select-control { | ||
min-height: 52px; | ||
height: auto; | ||
display: flex !important; | ||
overflow: visible !important; | ||
} | ||
|
||
.Select-clear-zone, | ||
.Select-clear { | ||
font-size: 21px; | ||
line-height: 40px; | ||
|
||
&:hover { | ||
color: $dashboard-teal; | ||
} | ||
} | ||
|
||
.Select-value { | ||
font-size: 14px !important; | ||
padding-right: 42px !important; | ||
overflow: hidden; | ||
|
||
.Select-value-label { | ||
font-size: 14px; | ||
max-width: 100%; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
} | ||
} | ||
|
||
.Select-input { | ||
input { | ||
font-size: 14px; | ||
|
||
&::-webkit-input-placeholder { | ||
/* Edge */ | ||
color: $gui-kit-gray-30; | ||
} | ||
|
||
&:-ms-input-placeholder { | ||
/* Internet Explorer 10-11 */ | ||
color: $gui-kit-gray-30; | ||
} | ||
|
||
&::placeholder { | ||
color: $gui-kit-gray-30; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,67 @@ | ||
/** | ||
* SearchCombo component. | ||
*/ | ||
import React, { useState, useEffect } from 'react'; | ||
import React, { useState, useMemo } from 'react'; | ||
import DropdownSingleSkills from 'components/GUIKit/DropdownSingleSkills'; | ||
import PT from 'prop-types'; | ||
import _ from 'lodash'; | ||
import './style.scss'; | ||
import IconClearSearch from 'assets/images/icon-clear-search.svg'; | ||
import { getService } from 'services/skills'; | ||
|
||
function SearchCombo({ | ||
term, | ||
placeholder, | ||
btnText, | ||
onSearch, | ||
auth, | ||
}) { | ||
const [inputVal, setVal] = useState(term); | ||
useEffect(() => setVal(term), [term]); | ||
const clearSearch = () => { | ||
setVal(''); | ||
onSearch(''); | ||
}; | ||
const onKeyDown = (e) => { | ||
if (e.which === 13) { | ||
onSearch(inputVal); | ||
const [skills, setSkills] = useState(term); | ||
|
||
const fetchSkills = useMemo(() => _.debounce((inputValue, callback) => { | ||
if (!inputValue) { | ||
callback(null); | ||
} else { | ||
getService(auth.tokenV3).getSkills(inputValue).then( | ||
(response) => { | ||
const suggestedOptions = (response || []).map(skillItem => ({ | ||
label: skillItem.name, | ||
value: skillItem.name, | ||
})); | ||
return callback(null, { | ||
options: suggestedOptions, | ||
}); | ||
}, | ||
).catch(() => callback(null)); | ||
} | ||
}; | ||
}, 150), [auth.tokenV3]); | ||
|
||
return ( | ||
<div styleName="container"> | ||
<div styleName="input-wrap"> | ||
{ | ||
!inputVal ? <span styleName="search-placeholder">{placeholder}</span> : null | ||
} | ||
<input type="text" styleName="input" value={inputVal} onChange={event => setVal(event.target.value)} onKeyDown={onKeyDown} /> | ||
{ | ||
inputVal ? <IconClearSearch onClick={clearSearch} styleName="clear-search" /> : null | ||
} | ||
</div> | ||
<button type="button" styleName="primary-green-md" onClick={() => onSearch(inputVal)} disabled={!inputVal}> | ||
{btnText} | ||
</button> | ||
<DropdownSingleSkills | ||
terms={skills} | ||
placeholder={placeholder} | ||
onChange={(newSkill) => { | ||
setSkills(newSkill); | ||
onSearch(newSkill); | ||
}} | ||
cacheOptions | ||
loadOptions={fetchSkills} | ||
createText="Search" | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
SearchCombo.defaultProps = { | ||
term: '', | ||
placeholder: '', | ||
btnText: 'SEARCH', | ||
auth: {}, | ||
}; | ||
|
||
SearchCombo.propTypes = { | ||
term: PT.string, | ||
placeholder: PT.string, | ||
btnText: PT.string, | ||
onSearch: PT.func.isRequired, | ||
auth: PT.object, | ||
}; | ||
|
||
export default SearchCombo; |
Oops, something went wrong.