88 ButtonToolbar ,
99 Col ,
1010 Glyphicon ,
11- Label ,
1211 Panel ,
1312 Row ,
1413 Table
@@ -18,7 +17,6 @@ import {browserHistory, Link} from 'react-router'
1817import * as gtfsPlusActions from '../actions/gtfsplus'
1918import { getGtfsPlusSpec } from '../../common/util/config'
2019import type { Props as ContainerProps } from '../containers/ActiveGtfsPlusVersionSummary'
21- import type { GtfsSpecTable } from '../../types'
2220import type { GtfsPlusReducerState , ManagerUserState } from '../../types/reducers'
2321
2422type Issue = {
@@ -37,17 +35,11 @@ type Props = ContainerProps & {
3735 user : ManagerUserState
3836}
3937
40- type State = {
41- expanded : boolean ,
42- tableExpanded : any
43- }
44-
45- type IssueFilter = Issue => boolean
38+ type State = { expanded : boolean }
4639
4740export default class GtfsPlusVersionSummary extends Component < Props , State > {
4841 state = {
49- expanded : false ,
50- tableExpanded : { }
42+ expanded : false
5143 }
5244
5345 componentDidMount ( ) {
@@ -75,18 +67,12 @@ export default class GtfsPlusVersionSummary extends Component<Props, State> {
7567 }
7668
7769 _getTableLevelIssues = ( tableId : string ) : ?Array < Issue > => {
78- return this . _getIssues ( tableId , issue => issue . rowIndex === - 1 )
79- }
80-
81- _getIssues = ( tableId : string , filter : ?IssueFilter ) : ?Array < Issue > => {
8270 const { issuesForTable} = this . props
8371 if ( ! issuesForTable ) return null
8472 if ( ! ( tableId in issuesForTable ) ) return null
85-
86- // Filter table level issues or row issues using the specified filter.
87- filter = filter || ( ( ) => true )
88- const issues = issuesForTable [ tableId ] . filter ( filter )
89- return ( issues . length > 0 ? issues : null )
73+ // Table level issues are identified by not having -1 for row index.
74+ const tableLevelIssues = issuesForTable [ tableId ] . filter ( issue => issue . rowIndex === - 1 )
75+ return tableLevelIssues . length > 0 ? tableLevelIssues : null
9076 }
9177
9278 feedStatus ( ) {
@@ -124,68 +110,6 @@ export default class GtfsPlusVersionSummary extends Component<Props, State> {
124110 this . setState ( { expanded : ! expanded } )
125111 }
126112
127- _toggleTableExpanded = ( tableName : string ) : void => {
128- const { tableExpanded } = this . state
129- const newTableExpanded = Object . assign ( tableExpanded )
130- newTableExpanded [ tableName ] = ! newTableExpanded [ tableName ]
131-
132- this . setState ( { tableExpanded : newTableExpanded } )
133- }
134-
135- renderIssues = ( table : GtfsSpecTable ) => {
136- const { tableExpanded } = this . state
137- const isExpanded = tableExpanded [ table . name ]
138- const issueCount = this . validationIssueCount ( table . id )
139- const tableLevelIssues = this . _getTableLevelIssues ( table . id )
140- const allIssues = this . _getIssues ( table . id )
141- allIssues && allIssues . sort (
142- ( issue1 , issue2 ) => issue1 . rowIndex - issue2 . rowIndex
143- )
144-
145- return (
146- < div >
147- < small >
148- < Button
149- bsSize = 'small'
150- bsStyle = 'link'
151- onClick = { ( ) => this . _toggleTableExpanded ( table . name ) }
152- >
153- < small >
154- < Glyphicon
155- glyph = { isExpanded ? 'triangle-bottom' : 'triangle-right' }
156- style = { { marginRight : '0.5em' } } />
157- </ small >
158- { issueCount } validation { issueCount !== 1 ? 'issues' : 'issue' }
159- { tableLevelIssues && issueCount && ` (${ tableLevelIssues . length } /${ issueCount } blocking)` }
160- </ Button >
161-
162- { isExpanded && < Table condensed style = { { margin : 0 } } >
163- < thead >
164- < tr >
165- < th > Line</ th >
166- < th > Column</ th >
167- < th > Issue</ th >
168- </ tr >
169- </ thead >
170- < tbody >
171- { allIssues && allIssues . map ( ( issue , index ) =>
172- < tr key = { index } >
173- < td > { issue . rowIndex + 2 } </ td > { /* This is the line number in the file */ }
174- < td > { issue . fieldName } </ td >
175- < td >
176- { issue . description }
177- { ' ' }
178- { issue . rowIndex === - 1 && < Label bsStyle = 'danger' htmlFor > BLOCKING</ Label > }
179- </ td >
180- </ tr >
181- ) }
182- </ tbody >
183- </ Table > }
184- </ small >
185- </ div >
186- )
187- }
188-
189113 render ( ) {
190114 const {
191115 gtfsplus,
@@ -274,7 +198,7 @@ export default class GtfsPlusVersionSummary extends Component<Props, State> {
274198 < Row >
275199 < Col xs = { 12 } >
276200 < Panel >
277- < Table fill >
201+ < Table striped fill >
278202 < thead >
279203 < tr >
280204 < th > Table</ th >
@@ -283,51 +207,44 @@ export default class GtfsPlusVersionSummary extends Component<Props, State> {
283207 < th > Validation Issues</ th >
284208 </ tr >
285209 </ thead >
286- { /* FIXME: reinstate this <tbody> after switching to React 16. */ }
287- { /**
288- * Change the behavior as follows:
289- * - Table-level issues are still critical and blocking and and displayed in red.
290- * - Per-row issues are still amber warnings and non-blocking,
291- * but will now be displayed individually instead of being aggregated.
292- * Maybe only display the first 25 issues to avoid long rendering times???
293- * - Issues are displayed on a full-width sub-table for better readability,
294- * in the same "row" as the issue summary.
295- * - Tables are sorted alphabetically.
296- */ }
297- { getGtfsPlusSpec ( )
298- . sort ( ( table1 , table2 ) => table1 . name . localeCompare ( table2 . name ) )
299- . map ( ( table , index ) => {
300- const issueCount = this . validationIssueCount ( table . id )
301- const tableLevelIssues = this . _getTableLevelIssues ( table . id )
302- const hasIssues = + issueCount > 0
303- const className = tableLevelIssues
304- ? 'danger'
305- : ( hasIssues ? 'warning' : '' )
210+ < tbody >
211+ { getGtfsPlusSpec ( )
212+ . sort ( ( table1 , table2 ) => table1 . name . localeCompare ( table2 . name ) )
213+ . map ( ( table , index ) => {
214+ const issueCount = this . validationIssueCount ( table . id )
215+ const tableLevelIssues = this . _getTableLevelIssues ( table . id )
306216
307- return (
308- // FIXME: Use <React.Fragment key={index}> (React 16+ only.)
309- < tbody key = { index } >
217+ return (
310218 < tr
311- className = { className }
312- rowSpan = { hasIssues ? 2 : 1 }
219+ rowSpan = { tableLevelIssues ? 2 : 1 }
220+ key = { index }
221+ className = { tableLevelIssues
222+ ? 'danger'
223+ : + issueCount > 0 && 'warning'
224+ }
313225 style = { { color : this . isTableIncluded ( table . id ) === 'Yes' ? 'black' : 'lightGray' } } >
314- < td > { table . name } </ td >
226+ < td >
227+ { table . name }
228+ { tableLevelIssues
229+ ? < small >
230+ < br />
231+ { tableLevelIssues . length } critical table issue(s):
232+ < ul >
233+ { tableLevelIssues . map ( ( issue , i ) =>
234+ < li key = { i } > { issue . fieldName } : { issue . description } </ li > ) }
235+ </ ul >
236+ </ small >
237+ : null
238+ }
239+ </ td >
315240 < td > { this . isTableIncluded ( table . id ) } </ td >
316241 < td > { this . tableRecordCount ( table . id ) } </ td >
317242 < td > { issueCount } </ td >
243+ < td />
318244 </ tr >
319- { hasIssues && (
320- < tr className = { className } >
321- < td colSpan = '4' style = { { borderTop : 'none' } } >
322- { this . renderIssues ( table ) }
323- </ td >
324- </ tr >
325- ) }
326- </ tbody >
327- // </React.Fragment>
328- )
329- } ) }
330- { /* </tbody> */ }
245+ )
246+ } ) }
247+ </ tbody >
331248 </ Table >
332249 </ Panel >
333250 </ Col >
0 commit comments