@@ -7,68 +7,78 @@ export interface IProps {
7
7
rejection : string ;
8
8
}
9
9
10
- export interface IState { }
10
+ export interface IState {
11
+ collapseFalsy : boolean ;
12
+ }
11
13
12
14
export class TransSummary extends Component < IProps , IState > {
13
- render ( ) {
15
+ state = { collapseFalsy : true } ;
16
+
17
+ renderParameterValues ( ) {
18
+ const params = this . props . trans . params ( ) ;
19
+ const paramsByType = Object . keys ( params ) . reduce ( ( buckets , key ) => {
20
+ const val = params [ key ] ;
21
+ const bucket = val === undefined ? 'undefined' : val === null ? 'null' : val === '' ? 'empty string' : 'other' ;
22
+ buckets [ bucket ] [ key ] = val ;
23
+ return buckets ;
24
+ } , { undefined : { } , null : { } , 'empty string' : { } , other : { } } ) ;
25
+
26
+ const falsyBuckets = Object . keys ( paramsByType )
27
+ . filter ( key => key !== 'other' )
28
+ . map ( key => ( { key, count : Object . keys ( paramsByType [ key ] ) . length } ) )
29
+ . filter ( bucket => ! ! bucket . count ) ;
30
+ const falsyTotal = falsyBuckets . reduce ( ( acc , bucket ) => acc + bucket . count , 0 ) ;
31
+
32
+ const collapse = this . state . collapseFalsy ;
33
+
14
34
return (
15
- < table className = "uirTranVis_transSummary" >
16
- < tbody >
17
- < tr > < td > From State:</ td > < td > { this . props . trans . from ( ) . name || '(root)' } </ td > </ tr >
18
- < tr > < td > To State:</ td > < td > { this . props . trans . to ( ) . name || '(root)' } </ td > </ tr >
19
- < tr >
20
- < td colSpan = { 1 } > Parameters:</ td >
21
- < td colSpan = { 1 } >
22
- < KeysAndValues
23
- data = { this . props . trans . params ( ) }
24
- labels = { { section : '' , modalTitle : 'Parameter value: ' } }
25
- classes = { { outerdiv : '' , keyvaldiv : 'uirTranVis_keyValue' , section : '' , _key : '' , value : '' } } >
26
- </ KeysAndValues >
27
- </ td >
28
- </ tr >
35
+ < div className = "uirTranVis_keysAndValues" >
36
+ < KeysAndValues
37
+ data = { paramsByType . other }
38
+ labels = { { section : '' , modalTitle : 'Parameter value: ' } }
39
+ classes = { { outerdiv : '' , keyvaldiv : 'uirTranVis_keyValue' , section : '' , _key : '' , value : '' } } />
29
40
30
- < tr >
31
- < td > Outcome:</ td >
32
- < td >
33
- { this . props . status }
34
- { this . props . rejection
35
- ? < span > : { this . props . rejection } </ span >
36
- : null }
37
- </ td >
38
- </ tr >
39
- </ tbody >
40
- </ table >
41
+ { ! ! falsyTotal && (
42
+ < a href = "" onClick = { ( ) => this . setState ( { collapseFalsy : ! collapse } ) } >
43
+ { collapse ? 'show' : 'hide' } { falsyTotal } { falsyBuckets . map ( bucket => bucket . key ) . join ( ' or ' ) } parameter values
44
+ </ a >
45
+ ) }
46
+
47
+ { ! this . state . collapseFalsy && (
48
+ falsyBuckets . map ( bucket => (
49
+ < KeysAndValues key = { bucket . key }
50
+ data = { paramsByType [ bucket . key ] }
51
+ labels = { { section : '' , modalTitle : 'Parameter value: ' } }
52
+ classes = { { outerdiv : '' , keyvaldiv : 'uirTranVis_keyValue' , section : '' , _key : '' , value : '' } } />
53
+ ) )
54
+ ) }
55
+ </ div >
41
56
)
42
57
}
43
58
44
- render2 ( ) {
59
+ render ( ) {
45
60
return (
46
- < table className = "uirTranVis_transSummary" >
47
- < tbody >
48
- < tr > < td > From State:</ td > < td > { this . props . trans . from ( ) . name || '(root)' } </ td > </ tr >
49
- < tr > < td > To State:</ td > < td > { this . props . trans . to ( ) . name || '(root)' } </ td > </ tr >
50
- < tr >
51
- < td colSpan = { 1 } > Parameters:</ td >
52
- < td colSpan = { 1 } >
53
- < KeysAndValues
54
- data = { this . props . trans . params ( ) }
55
- labels = { { section : '' , modalTitle : 'Parameter value: ' } }
56
- classes = { { outerdiv : '' , keyvaldiv : 'uirTranVis_keyValue' , section : '' , _key : '' , value : '' } } >
57
- </ KeysAndValues >
58
- </ td >
59
- </ tr >
61
+ < div className = "uirTranVis_transSummary" >
62
+ < div className = "uirTranVis_summaryData" >
63
+ < span > From:</ span > < strong > { this . props . trans . from ( ) . name || '(root)' } </ strong >
64
+ </ div >
65
+
66
+ < div className = "uirTranVis_summaryData" >
67
+ < span > To:</ span > < strong > { this . props . trans . to ( ) . name || '(root)' } </ strong >
68
+ </ div >
69
+
70
+ < div className = "uirTranVis_summaryData" >
71
+ < span > Result:</ span >
72
+ < div >
73
+ < strong > { this . props . status } </ strong >
74
+ { this . props . rejection ? < span > : { this . props . rejection } </ span > : null }
75
+ </ div >
76
+ </ div >
77
+
78
+ < div className = "uirTranVis_summaryHeading" > Parameter Values: </ div >
60
79
61
- < tr >
62
- < td > Outcome:</ td >
63
- < td >
64
- { this . props . status }
65
- { this . props . rejection
66
- ? < span > : { this . props . rejection } </ span >
67
- : null }
68
- </ td >
69
- </ tr >
70
- </ tbody >
71
- </ table >
80
+ { this . renderParameterValues ( ) }
81
+ </ div >
72
82
)
73
83
}
74
84
}
0 commit comments