1
+ /* eslint-disable no-plusplus */
2
+ /* eslint-disable @typescript-eslint/no-unused-vars */
3
+ /* eslint-disable @typescript-eslint/no-floating-promises */
1
4
/* eslint-disable @typescript-eslint/no-explicit-any */
2
5
/* eslint-disable array-callback-return */
3
6
/* eslint-disable @typescript-eslint/restrict-template-expressions */
@@ -14,11 +17,14 @@ import { ToggleButton, ToggleButtonGroup } from '@material-ui/lab';
14
17
import TableComponent from '../TableComponent/TableComponent' ;
15
18
import {
16
19
CmStudentFieldsFragment ,
20
+ CtmObjectiveMasteryFieldsFragment ,
17
21
Target ,
18
22
useClassMissionMasteryQuery ,
23
+ useClassTargetMasteryQuery ,
19
24
} from '../../__generated__/types' ;
20
25
import { LIST_TARGETS_BY_COURSE } from '../../hooks/ListTargetsByCourse' ;
21
26
import SelectedLTStudentViewTable from './SelectedLTStudentViewTable' ;
27
+ import { Mastery } from '../../Screens/ClassMastery/StudentMasteryRow' ;
22
28
23
29
interface LTStudentViewRow {
24
30
row : {
@@ -38,6 +44,8 @@ function LTStudentViewTable() {
38
44
const { data : missionMasteryData } = useClassMissionMasteryQuery ( ) ;
39
45
40
46
const [ selectedLT , setSlectedLT ] = useState < string | null > ( null ) ;
47
+ const [ targetMasteryDatas , setTargetMasteryDatas ] = useState < any [ ] > ( [ ] ) ;
48
+ const [ fetchOnce , setFetchOnce ] = useState < boolean > ( false ) ;
41
49
42
50
const handleLTSelection = (
43
51
event : React . MouseEvent < HTMLElement > ,
@@ -50,9 +58,41 @@ function LTStudentViewTable() {
50
58
51
59
const { data : courseTargets } = useQuery ( LIST_TARGETS_BY_COURSE ) ;
52
60
53
- if ( ! courseTargets ) {
61
+ React . useEffect ( ( ) => {
62
+ if ( ! courseTargets || fetchOnce ) {
63
+ return ;
64
+ }
65
+ setFetchOnce ( true ) ;
66
+ const token = localStorage . getItem ( 'jwt' ) ;
67
+
68
+ for ( const target of courseTargets . targets ) {
69
+ fetch ( 'https://18wi8h43il.execute-api.us-east-1.amazonaws.com/dev-flipted/graphql' , {
70
+ method : 'POST' ,
71
+ headers : {
72
+ 'Content-Type' : 'application/json' ,
73
+ Accept : 'application/json' ,
74
+ authorization : token ? `${ token } ` : '' ,
75
+ } ,
76
+ body : JSON . stringify ( {
77
+ query :
78
+ 'query ClassTargetMastery($targetId: String!) {\n classTargetMastery(targetId: $targetId) {\n target {\n ...CTMTargetField\n __typename\n }\n studentObjectiveMasteryList {\n ...CTMStudentObjectiveMasteryFields\n __typename\n }\n __typename\n }\n}\n\nfragment CTMTargetField on Target {\n targetId\n targetName\n objectives {\n ...CTMObjectiveField\n __typename\n }\n __typename\n}\n\nfragment CTMObjectiveField on Objective {\n objectiveId\n objectiveName\n __typename\n}\n\nfragment CTMStudentObjectiveMasteryFields on StudentObjectiveMastery {\n student {\n studentId\n email\n __typename\n }\n objectiveMasteryList {\n ...CTMObjectiveMasteryFields\n __typename\n }\n __typename\n}\n\nfragment CTMObjectiveMasteryFields on ObjectiveMastery {\n objectiveId\n mastery\n __typename\n}\n' ,
79
+ variables : { targetId : target . targetId } ,
80
+ } ) ,
81
+ } )
82
+ . then ( ( r ) => r . json ( ) )
83
+ . then ( ( data ) => {
84
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
85
+ setTargetMasteryDatas ( ( cur : any [ ] ) => [ ...cur , data ] ) ;
86
+ } ) ;
87
+ }
88
+ } , [ courseTargets , targetMasteryDatas , fetchOnce ] ) ;
89
+
90
+ if ( ! courseTargets || targetMasteryDatas . length < courseTargets . targets . length ) {
54
91
return < div /> ;
55
92
}
93
+ if ( targetMasteryDatas . length === courseTargets . targets . length ) {
94
+ console . log ( 'Target Mastery Datas: ' , targetMasteryDatas ) ;
95
+ }
56
96
57
97
const rowClicked = ( row : LTStudentViewRow ) => {
58
98
history . push ( {
@@ -83,8 +123,6 @@ function LTStudentViewTable() {
83
123
} ;
84
124
} ) ;
85
125
86
- console . log ( data ) ;
87
-
88
126
const tableColumns = [
89
127
{
90
128
Header : 'Student Information' ,
@@ -109,10 +147,6 @@ function LTStudentViewTable() {
109
147
Header : 'Average' ,
110
148
accessor : 'row.average' ,
111
149
} ,
112
- {
113
- Header : 'Progress' ,
114
- accessor : 'row.progress' ,
115
- } ,
116
150
] ,
117
151
} ,
118
152
] ;
@@ -126,14 +160,37 @@ function LTStudentViewTable() {
126
160
const learningTargetSet = new Set ( ) ;
127
161
128
162
courseTargets . targets . map ( ( target : Target ) => {
163
+ let index = 0 ;
164
+ const targetMastery = targetMasteryDatas . find (
165
+ ( x ) => x . data . classTargetMastery . target . targetId === target . targetId
166
+ ) ;
167
+
129
168
data . map ( ( row : any ) => {
130
- row . row [ target . targetName ] = '' ;
169
+ let count = 0 ;
170
+ targetMastery . data . classTargetMastery . studentObjectiveMasteryList [
171
+ index
172
+ ] . objectiveMasteryList . map ( ( objectiveMastery : CtmObjectiveMasteryFieldsFragment ) => {
173
+ if ( objectiveMastery . mastery === 'MASTERED' ) {
174
+ count += 3 ;
175
+ } else if ( objectiveMastery . mastery === 'NEARLY_MASTERED' ) {
176
+ count ++ ;
177
+ }
178
+ } ) ;
179
+ row . row [ target . targetName ] = count ;
180
+ index ++ ;
131
181
} ) ;
132
182
if ( ! learningTargetSet . has ( target . targetName ) ) {
133
183
learningTargetSet . add ( target . targetName ) ;
134
184
learningTargetGroup . columns . push ( {
135
185
Header : target . description ,
136
186
accessor : `row.${ target . targetName } ` ,
187
+ Cell : ( { cell : { value } } : { cell : any } ) => (
188
+ < Mastery
189
+ percentage = {
190
+ value / ( targetMastery . data . classTargetMastery . target . objectives . length * 3 )
191
+ }
192
+ />
193
+ ) ,
137
194
} ) ;
138
195
}
139
196
} ) ;
0 commit comments