@@ -37,7 +37,7 @@ var SchedulingCheck = React.createClass({
37
37
open : false ,
38
38
failed : false ,
39
39
timestamp : "never" ,
40
- tableState : {
40
+ tableState : { // gets modified by functions in the definition of SelectTable
41
41
greyed : { } ,
42
42
sort : - 1
43
43
}
@@ -96,23 +96,17 @@ var SchedulingCheck = React.createClass({
96
96
var data = JSON . parse ( this . state . data ) ; // Might not work on old browsers
97
97
var table ;
98
98
if ( data . headings . length == 0 ) {
99
- var settings = {
100
- header : false
101
- } ;
102
- table = < SelectTable rows = { data . body } settings = { settings } saveState = { this . state . tableState } /> ;
99
+ table = < SelectTable rows = { data . body } header = { false } saveState = { this . state . tableState } /> ;
103
100
} else {
104
101
var columns = [ ] ;
105
102
for ( i = 0 ; i < data . headings . length ; i ++ ) {
106
- if ( ! ! data . headings [ i ] ) {
103
+ if ( data . headings [ i ] ) {
107
104
columns [ i ] = { key : String ( i ) , label : data . headings [ i ] } ;
108
105
} else {
109
106
columns [ i ] = { key : String ( i ) , label : " " } ;
110
107
}
111
108
}
112
- var settings = {
113
- header : true
114
- } ;
115
- table = < SelectTable rows = { data . body } columns = { columns } settings = { settings } saveState = { this . state . tableState } /> ;
109
+ table = < SelectTable rows = { data . body } columns = { columns } header = { true } saveState = { this . state . tableState } /> ;
116
110
}
117
111
body = < div >
118
112
< div className = "placeholder" >
@@ -151,57 +145,61 @@ var RefreshButton = React.createClass({
151
145
152
146
153
147
// Modified from react-json-table example code.
154
- // Required props: rows, saveState (with sort and greyed attributes), settings (with header attribute)
155
148
var SelectTable = React . createClass ( {
149
+
150
+ propTypes : {
151
+ rows : React . PropTypes . array . isRequired ,
152
+ savestate : React . PropTypes . shape ( {
153
+ greyed : React . PropTypes . object . isRequired ,
154
+ sort : React . PropTypes . any . isRequired
155
+ } ) . isRequired ,
156
+ header : React . PropTypes . bool . isRequired ,
157
+ columns : React . PropTypes . object
158
+ } ,
159
+
156
160
getInitialState : function ( ) {
157
161
// We will store the sorted column and whether each row is greyed out
158
- return { sort : this . props . saveState . sort , greyed : this . props . saveState . greyed } ;
162
+ return { sort : this . props . saveState . sort , greyed : this . props . saveState . greyed } ;
159
163
} ,
160
164
render : function ( ) {
161
165
var me = this ,
162
166
// clone the rows
163
167
items = this . props . rows . slice ( )
164
168
;
165
- // Sort the table
166
- if ( this . state . sort ) {
167
- items . sort ( function ( a , b ) {
168
- return a [ me . state . sort ] > b [ me . state . sort ] ? 1 : - 1 ;
169
+
170
+ items = _ . sortBy ( items , function ( item ) {
171
+ return item [ me . state . sort ] ;
169
172
} ) ;
170
- }
171
173
172
- if ( this . props . columns == undefined ) {
173
- return < JsonTable
174
- rows = { items }
175
- settings = { this . getSettings ( ) }
176
- onClickHeader = { this . onClickHeader }
177
- onClickRow = { this . onClickRow }
178
- /> ;
179
- } else {
180
- return < JsonTable
181
- rows = { items }
182
- columns = { this . props . columns }
183
- settings = { this . getSettings ( ) }
184
- onClickHeader = { this . onClickHeader }
185
- onClickRow = { this . onClickRow }
186
- /> ;
187
- }
174
+
175
+ return < JsonTable
176
+ rows = { items }
177
+ columns = { this . props . columns }
178
+ settings = { this . getSettings ( ) }
179
+ onClickHeader = { this . onClickHeader }
180
+ onClickRow = { this . onClickRow }
181
+ /> ;
188
182
} ,
189
183
190
184
getSettings : function ( ) {
191
185
var me = this ;
192
186
// We will add some classes to the selected rows and cells
193
187
return {
194
188
headerClass : function ( current , key ) {
195
- if ( me . state . sort == key )
189
+ if ( me . state . sort == key ) {
196
190
return current + ' headerSelected' ;
197
- return current ;
191
+ } else {
192
+ return current ;
193
+ }
198
194
} ,
199
195
rowClass : function ( current , item ) {
200
- if ( me . state . greyed [ item ] )
196
+ if ( me . state . greyed [ item ] ) {
201
197
return current + ' rowGreyed' ;
202
- return current ;
198
+ } else {
199
+ return current ;
200
+ }
203
201
} ,
204
- header : this . props . settings . header
202
+ header : this . props . header
205
203
} ;
206
204
} ,
207
205
0 commit comments