Skip to content

Commit af00ed8

Browse files
authored
Merge pull request #573 from ibi-group/fix-trip-pattern-name
Fix pattern name editor bug
2 parents 401ff4d + 1ed1b64 commit af00ed8

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

lib/common/components/EditableTextField.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,22 @@ export default class EditableTextField extends Component<Props, State> {
4747
}
4848

4949
componentWillReceiveProps (nextProps: Props) {
50-
if (this.state.value !== nextProps.value) {
51-
// Update value if externally changed.
52-
this.setState({ value: nextProps.value })
50+
const {initialValue, isEditing, value} = this.state
51+
const {value: nextValue} = nextProps
52+
const valueChanged = this.props.value !== nextValue
53+
if (value !== nextValue && valueChanged && !isEditing) {
54+
// Update value if externally changed, but only if the field is not being
55+
// actively edited. This update accounts for cases where the value this
56+
// field represents has been updated (perhaps due to a request to the
57+
// server), but if the user is already editing the field, we don't want to
58+
// interrupt that input.
59+
this.setState({ value: nextValue })
5360
}
54-
if (this.state.initialValue !== nextProps.value) {
61+
if (initialValue !== nextValue) {
5562
// Update initial value if externally changed.
56-
this.setState({ initialValue: nextProps.value })
63+
// TODO: investigate whether this conditional case fully accounts for the
64+
// above conditional.
65+
this.setState({ initialValue: nextValue })
5766
}
5867
}
5968

@@ -141,6 +150,8 @@ export default class EditableTextField extends Component<Props, State> {
141150
<FormGroup data-test-id='editable-text-field-edit-container'>
142151
<InputGroup>
143152
<FormControl
153+
/* eslint-disable-next-line jsx-a11y/no-autofocus */
154+
autoFocus
144155
type={type.toLowerCase()}
145156
min={min}
146157
step={step}

0 commit comments

Comments
 (0)