Skip to content

Commit 24e1462

Browse files
authored
Merge pull request #3987 from appirio-tech/hotfix/post-release-2.9.1
[DEV] [HOTFIX] Post release 2.9.1 - enforce max values for people and duration in talent picker
2 parents 8fc46f0 + 6b1a16a commit 24e1462

File tree

2 files changed

+45
-7
lines changed

2 files changed

+45
-7
lines changed

src/components/PositiveNumberInput/PositiveNumberInput.jsx

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ class PositiveNumberInput extends React.PureComponent {
77
super(props)
88

99
this.isInputValid = true
10+
this.previousValue = props.value || ''
1011

1112
this.onKeyDown = this.onKeyDown.bind(this)
1213
this.onPaste = this.onPaste.bind(this)
1314
this.onKeyUp = this.onKeyUp.bind(this)
15+
this.onChange = this.onChange.bind(this)
1416
}
1517

1618
onKeyDown(evt) {
@@ -44,26 +46,62 @@ class PositiveNumberInput extends React.PureComponent {
4446
this.props.onKeyUp(evt)
4547
}
4648

49+
onChange(evt) {
50+
const { onChange } = this.props
51+
52+
this.enforceInputBelowMax(evt)
53+
onChange(evt)
54+
}
55+
56+
/**
57+
* Makes sure the input value is kept below the max value
58+
* @param {Event} evt The change event
59+
*/
60+
enforceInputBelowMax(evt) {
61+
const value = evt.target.value
62+
if (this.isBelowMaxLimit(value)) {
63+
this.previousValue = value
64+
} else {
65+
evt.target.value = this.previousValue
66+
}
67+
}
68+
69+
isBelowMaxLimit(text) {
70+
const { max = Infinity } = this.props
71+
return Number(text) <= max
72+
}
73+
4774
render() {
4875
const props = omit(this.props, ['onValidityChange'])
49-
return <input type="number" min={0} {...props} onKeyDown={this.onKeyDown} onPaste={this.onPaste} onKeyUp={this.onKeyUp} />
76+
return (
77+
<input
78+
type="number"
79+
min={0}
80+
{...props}
81+
onKeyDown={this.onKeyDown}
82+
onPaste={this.onPaste}
83+
onKeyUp={this.onKeyUp}
84+
onChange={this.onChange}
85+
/>
86+
)
5087
}
5188
}
5289

5390
PositiveNumberInput.defaultProps = {
5491
onKeyDown: noop,
5592
onPaste: noop,
5693
onKeyUp: noop,
57-
onValidityChange: noop
58-
94+
onValidityChange: noop,
95+
onChange: noop,
5996
}
6097

6198
PositiveNumberInput.propTypes = {
99+
max: PT.number,
62100
onKeyDown: PT.func,
63101
onPaste: PT.func,
64102
onKeyUp: PT.func,
65-
onValidityChange: PT.func
103+
onValidityChange: PT.func,
104+
onChange: PT.func,
66105
}
67106

68-
69107
export default PositiveNumberInput

src/projects/detail/components/TalentPickerRow/TalentPickerRow.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,9 @@ class TalentPickerRow extends React.PureComponent {
100100
People
101101
</label>
102102
<PositiveNumberInput
103-
type="number"
104103
styleName="noMargin"
105104
className={cn('tc-file-field__inputs', { error: isRowIncomplete && value.people <= 0 })}
105+
max={10000}
106106
value={value.people || ''}
107107
onChange={this.handlePeopleChange}
108108
onBlur={this.resetPeople}
@@ -116,9 +116,9 @@ class TalentPickerRow extends React.PureComponent {
116116
Duration (months)
117117
</label>
118118
<PositiveNumberInput
119-
type="number"
120119
styleName="noMargin"
121120
className={cn('tc-file-field__inputs', {error: isRowIncomplete && value.duration <= 0 })}
121+
max={10000}
122122
value={value.duration || ''}
123123
onChange={this.handleDurationChange}
124124
onBlur={this.resetDuration}

0 commit comments

Comments
 (0)