From fae3e7f23771be15847e46f7d5eb3c7e88ea445f Mon Sep 17 00:00:00 2001 From: Vigneshkumar Chinnachamy M Date: Sun, 19 Apr 2020 02:38:06 +0530 Subject: [PATCH 1/4] style talent picker --- .../PositiveNumberInput.jsx | 69 +++++++ .../detail/components/Accordion/Accordion.jsx | 3 +- .../SkillsQuestion/SkillsQuestionBase.jsx | 17 +- .../TalentPickerQuestion.jsx | 52 +++--- .../TalentPickerQuestion.scss | 64 +++++-- .../TalentPickerRow/TalentPickerRow.jsx | 176 +++++++++++------- .../TalentPickerRow/TalentPickerRow.scss | 139 +++++++++++++- 7 files changed, 402 insertions(+), 118 deletions(-) create mode 100644 src/components/PositiveNumberInput/PositiveNumberInput.jsx diff --git a/src/components/PositiveNumberInput/PositiveNumberInput.jsx b/src/components/PositiveNumberInput/PositiveNumberInput.jsx new file mode 100644 index 000000000..357c31e13 --- /dev/null +++ b/src/components/PositiveNumberInput/PositiveNumberInput.jsx @@ -0,0 +1,69 @@ +import React from 'react' +import PT from 'prop-types' +import { noop, omit } from 'lodash' + +class PositiveNumberInput extends React.PureComponent { + constructor(props) { + super(props) + + this.isInputValid = true + + this.onKeyDown = this.onKeyDown.bind(this) + this.onPaste = this.onPaste.bind(this) + this.onKeyUp = this.onKeyUp.bind(this) + } + + onKeyDown(evt) { + const isPrintableKey = evt.key.length === 1 && !evt.ctrlKey + const digitPattern = /\d/ + + // Don't allow typing non digit characters + if (isPrintableKey && !digitPattern.test(evt.key)) { + evt.preventDefault() + } + this.props.onKeyDown(evt) + } + + onPaste(evt) { + const text = evt.clipboardData.getData('text') + const digitsPattern = /^\d+$/ + + // Don't allow pasting non digit text + if (!digitsPattern.test(text)) { + evt.preventDefault() + } + this.props.onPaste(evt) + } + + onKeyUp(evt) { + const isValid = evt.target.validity.valid + if (isValid !== this.isInputValid) { + this.isInputValid = isValid + this.props.onValidityChange(isValid) + } + this.props.onKeyUp(evt) + } + + render() { + const props = omit(this.props, ['onValidityChange']) + return + } +} + +PositiveNumberInput.defaultProps = { + onKeyDown: noop, + onPaste: noop, + onKeyUp: noop, + onValidityChange: noop + +} + +PositiveNumberInput.propTypes = { + onKeyDown: PT.func, + onPaste: PT.func, + onKeyUp: PT.func, + onValidityChange: PT.func +} + + +export default PositiveNumberInput diff --git a/src/projects/detail/components/Accordion/Accordion.jsx b/src/projects/detail/components/Accordion/Accordion.jsx index 3dad63d4b..f2cf2a905 100644 --- a/src/projects/detail/components/Accordion/Accordion.jsx +++ b/src/projects/detail/components/Accordion/Accordion.jsx @@ -171,7 +171,8 @@ class Accordion extends React.Component { case TYPE.SELECT_DROPDOWN: return mapValue(value) case TYPE.TALENT_PICKER: { const getRoleName = (role) => _.find(options, { role }).roleTitle - return _.filter(value, (v) => v.people !== '0').map((v) => `${getRoleName(v.role)}: ${v.people}`).join(', ') + const totalPeoplePerRole = _.mapValues(_.groupBy(value, v => v.role), valuesUnderGroup => _.sumBy(valuesUnderGroup, v => Number(v.people))) + return _.toPairs(totalPeoplePerRole).filter(([, people]) => people > 0).map(([role, people]) => `${getRoleName(role)} ${people}`).join(', ') } default: return value } diff --git a/src/projects/detail/components/SkillsQuestion/SkillsQuestionBase.jsx b/src/projects/detail/components/SkillsQuestion/SkillsQuestionBase.jsx index 0bb34e060..8896234d4 100644 --- a/src/projects/detail/components/SkillsQuestion/SkillsQuestionBase.jsx +++ b/src/projects/detail/components/SkillsQuestion/SkillsQuestionBase.jsx @@ -165,6 +165,7 @@ class SkillsQuestion extends React.PureComponent { skillsCategories, currentProjectData, categoriesField, + selectWrapperClass, } = this.props const { availableOptions, customOptionValue } = this.state @@ -189,13 +190,14 @@ class SkillsQuestion extends React.PureComponent { return (
- checkboxGroupValues} - setValue={(val) => { this.handleChange(_.union(val, selectGroupValues)) }} - /> -
+ {checkboxGroupOptions.length > 0 ? ( + checkboxGroupValues} + setValue={(val) => { this.handleChange(_.union(val, selectGroupValues)) }} + />) : null} +