@@ -35,7 +35,7 @@ export default class AssessmentHistory extends React.PureComponent<IBaseProps, A
35
35
let courseName = props . match . params . courseName ;
36
36
37
37
if ( ! courseName ) {
38
- return Promise . resolve ( ) ;
38
+ return Promise . resolve ( { } as Certification ) ;
39
39
}
40
40
41
41
return fetch ( "/courses/" + courseName , {
@@ -45,11 +45,11 @@ export default class AssessmentHistory extends React.PureComponent<IBaseProps, A
45
45
return results . json ( ) ;
46
46
} )
47
47
. then ( data => {
48
- this . setState ( { certification : data as Certification } ) ;
48
+ return data as Certification ;
49
49
} ) ;
50
50
}
51
51
52
- loadSessionCollection ( props : IBaseProps ) {
52
+ loadSessionCollection ( props : IBaseProps , certification : Certification ) {
53
53
let courseName = props . match . params . courseName ;
54
54
55
55
if ( ! courseName ) {
@@ -63,17 +63,24 @@ export default class AssessmentHistory extends React.PureComponent<IBaseProps, A
63
63
return results . json ( ) ;
64
64
} )
65
65
. then ( ( sessions : Array < AssessmentSession > ) => {
66
- this . setState ( { previousSessions : sessions } ) ;
66
+ this . setState ( {
67
+ certification : certification ,
68
+ previousSessions : sessions
69
+ } ) ;
67
70
} ) ;
68
71
}
69
72
70
- componentDidMount ( ) {
71
- this . loadCertification ( this . props )
72
- . then ( ( ) => {
73
- this . loadSessionCollection ( this . props ) ;
73
+ loadHandler ( props : IBaseProps ) {
74
+ this . loadCertification ( props )
75
+ . then ( certification => {
76
+ this . loadSessionCollection ( props , certification ) ;
74
77
} ) ;
75
78
}
76
79
80
+ componentDidMount ( ) {
81
+ this . loadHandler ( this . props ) ;
82
+ }
83
+
77
84
reset ( ) {
78
85
this . setState ( this . getDefaultState ( ) ) ;
79
86
}
@@ -83,7 +90,7 @@ export default class AssessmentHistory extends React.PureComponent<IBaseProps, A
83
90
this . reset ( ) ;
84
91
}
85
92
86
- this . loadSessionCollection ( props ) ;
93
+ this . loadHandler ( props ) ;
87
94
}
88
95
89
96
render ( ) {
@@ -97,7 +104,14 @@ export default class AssessmentHistory extends React.PureComponent<IBaseProps, A
97
104
sortable . push ( item ) ;
98
105
}
99
106
100
- sortable . sort ( ( a , b ) => ( a [ 1 ] as number ) - ( b [ 1 ] as number ) ) ;
107
+ sortable = sortable . filter ( arr => this . state . certification . questions && this . state . certification . questions . some ( q => q . id === arr [ 0 ] ) ) ;
108
+ sortable = sortable . map ( arr => {
109
+ let question = this . state . certification . questions . find ( q => q . id === arr [ 0 ] ) ;
110
+
111
+ return [ question . key , arr [ 1 ] , question . position ]
112
+ } ) ;
113
+
114
+ sortable = sortable . sort ( ( a , b ) => ( a [ 2 ] as number ) - ( b [ 2 ] as number ) ) ;
101
115
102
116
if ( this . props . match . params . courseName ) {
103
117
content = (
0 commit comments