Skip to content

Commit 82e87d7

Browse files
committed
Restructured so that props are not mutated
1 parent 9f5f43c commit 82e87d7

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

esp/public/media/scripts/program/modules/scheduling_checks.jsx

+20-10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@ var SchedulingCheck = React.createClass({
4343
}
4444
};
4545
},
46+
47+
updateTableState: function (state) {
48+
/*this.state.tableState = {
49+
greyed: state.greyed,
50+
sort: state.sort
51+
};*/
52+
this.state.tableState = state;
53+
},
4654

4755
handleClick: function () {
4856
if (this.state.open) {
@@ -96,7 +104,7 @@ var SchedulingCheck = React.createClass({
96104
var data = JSON.parse(this.state.data); // Might not work on old browsers
97105
var table;
98106
if (data.headings.length == 0) {
99-
table = <SelectTable rows = {data.body} header = {false} saveState = {this.state.tableState} />;
107+
table = <SelectTable rows = {data.body} header = {false} saveState = {this.state.tableState} updateTableState = {this.updateTableState} />;
100108
} else {
101109
var columns = [];
102110
for (i = 0; i < data.headings.length; i++) {
@@ -106,7 +114,7 @@ var SchedulingCheck = React.createClass({
106114
columns[i] = {key: String(i), label: " "};
107115
}
108116
}
109-
table = <SelectTable rows = {data.body} columns = {columns} header = {true} saveState = {this.state.tableState} />;
117+
table = <SelectTable rows = {data.body} columns = {columns} header = {true} saveState = {this.state.tableState} updateTableState = {this.updateTableState} />;
110118
}
111119
body = <div>
112120
<div className="placeholder">
@@ -149,19 +157,21 @@ var SelectTable = React.createClass({
149157

150158
propTypes: {
151159
rows: React.PropTypes.array.isRequired,
152-
savestate: React.PropTypes.shape({
160+
saveState: React.PropTypes.shape({
153161
greyed: React.PropTypes.object.isRequired,
154162
sort: React.PropTypes.any.isRequired
155163
}).isRequired,
156164
header: React.PropTypes.bool.isRequired,
157-
columns: React.PropTypes.object
165+
columns: React.PropTypes.array,
166+
updateTableState: React.PropTypes.func.isRequired
158167
},
159168

160169
getInitialState: function(){
161170
// We will store the sorted column and whether each row is greyed out
162-
return {sort: this.props.saveState.sort, greyed: this.props.saveState.greyed};
171+
return {sort: this.props.saveState.sort, greyed: this.props.saveState.greyed };
163172
},
164173
render: function(){
174+
this.props.updateTableState(this.state);
165175
var me = this,
166176
// clone the rows
167177
items = this.props.rows.slice()
@@ -204,13 +214,13 @@ var SelectTable = React.createClass({
204214
},
205215

206216
onClickHeader: function( e, column ){
207-
this.props.saveState.sort = column;
208217
this.setState( {sort: column} );
209218
},
210219

211-
onClickRow: function( e, item ){
212-
this.state.greyed[item] = !this.state.greyed[item];
213-
this.props.saveState.greyed[item] = this.state.greyed[item];
214-
this.setState(); // so that it actually updates
220+
onClickRow: function( e, item ){
221+
// kind of kludgy but I can't figure out how to do this more nicely
222+
newgreyed = jQuery.extend({}, this.state.greyed);
223+
newgreyed[item] = !newgreyed[item];
224+
this.setState( {greyed: newgreyed} );
215225
}
216226
});

0 commit comments

Comments
 (0)