Skip to content

Commit f2fc199

Browse files
committed
Don't save list row value if it didn't change
1 parent a48734f commit f2fc199

File tree

1 file changed

+30
-11
lines changed

1 file changed

+30
-11
lines changed

src/containers/list-monitor.jsx

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class ListMonitor extends React.Component {
2626
this.state = {
2727
activeIndex: null,
2828
activeValue: null,
29+
inputDidChange: false,
2930
width: props.width || 100,
3031
height: props.height || 200
3132
};
@@ -39,18 +40,26 @@ class ListMonitor extends React.Component {
3940

4041
this.setState({
4142
activeIndex: index,
42-
activeValue: safeStringify(this.props.value[index])
43+
activeValue: safeStringify(this.props.value[index]),
44+
inputDidChange: false
4345
});
4446
}
4547

4648
handleDeactivate () {
4749
// Submit any in-progress value edits on blur
4850
if (this.state.activeIndex !== null) {
49-
const {vm, targetId, id: variableId} = this.props;
50-
const newListValue = getVariableValue(vm, targetId, variableId);
51-
newListValue[this.state.activeIndex] = this.state.activeValue;
52-
setVariableValue(vm, targetId, variableId, newListValue);
53-
this.setState({activeIndex: null, activeValue: null});
51+
if (this.state.inputDidChange) {
52+
const {vm, targetId, id: variableId} = this.props;
53+
const newListValue = getVariableValue(vm, targetId, variableId);
54+
newListValue[this.state.activeIndex] = this.state.activeValue;
55+
setVariableValue(vm, targetId, variableId, newListValue);
56+
}
57+
58+
this.setState({
59+
activeIndex: null,
60+
activeValue: null,
61+
inputDidChange: false
62+
});
5463
}
5564
}
5665

@@ -76,7 +85,8 @@ class ListMonitor extends React.Component {
7685
const newIndex = this.wrapListIndex(previouslyActiveIndex + navigateDirection, this.props.value.length);
7786
this.setState({
7887
activeIndex: newIndex,
79-
activeValue: safeStringify(this.props.value[newIndex])
88+
activeValue: safeStringify(this.props.value[newIndex]),
89+
inputDidChange: false
8090
});
8191
e.preventDefault(); // Stop default tab behavior, handled by this state change
8292
} else if (e.key === 'Enter') {
@@ -91,13 +101,17 @@ class ListMonitor extends React.Component {
91101
const newIndex = this.wrapListIndex(previouslyActiveIndex + newValueOffset, newListValue.length);
92102
this.setState({
93103
activeIndex: newIndex,
94-
activeValue: newListItemValue
104+
activeValue: newListItemValue,
105+
inputDidChange: false
95106
});
96107
}
97108
}
98109

99110
handleInput (e) {
100-
this.setState({activeValue: e.target.value});
111+
this.setState({
112+
activeValue: e.target.value,
113+
inputDidChange: true
114+
});
101115
}
102116

103117
handleRemove (e) {
@@ -111,7 +125,8 @@ class ListMonitor extends React.Component {
111125
const newActiveIndex = Math.min(newListValue.length - 1, this.state.activeIndex);
112126
this.setState({
113127
activeIndex: newActiveIndex,
114-
activeValue: safeStringify(newListValue[newActiveIndex])
128+
activeValue: safeStringify(newListValue[newActiveIndex]),
129+
inputDidChange: false
115130
});
116131
}
117132

@@ -120,7 +135,11 @@ class ListMonitor extends React.Component {
120135
const {vm, targetId, id: variableId} = this.props;
121136
const newListValue = getVariableValue(vm, targetId, variableId).concat(['']);
122137
setVariableValue(vm, targetId, variableId, newListValue);
123-
this.setState({activeIndex: newListValue.length - 1, activeValue: ''});
138+
this.setState({
139+
activeIndex: newListValue.length - 1,
140+
activeValue: '',
141+
inputDidChange: false
142+
});
124143
}
125144

126145
handleResizeMouseDown (e) {

0 commit comments

Comments
 (0)