1
+ /* eslint-disable @typescript-eslint/no-unsafe-return */
1
2
/* eslint-disable no-plusplus */
2
3
/* eslint-disable array-callback-return */
3
4
/* eslint-disable no-param-reassign */
@@ -16,6 +17,25 @@ import {
16
17
useClassTargetMasteryQuery ,
17
18
} from '../../__generated__/types' ;
18
19
20
+ function genObjectiveGroup ( targetMasteryData : any ) : any {
21
+ const objectiveGorup : any = {
22
+ Header : 'Objectives' ,
23
+ columns : [ ] ,
24
+ } ;
25
+
26
+ targetMasteryData . classTargetMastery . target . objectives . map ( ( objective : any ) => {
27
+ objectiveGorup . columns . push ( {
28
+ Header : objective . objectiveName ,
29
+ accessor : `row.${ objective . objectiveId } ` ,
30
+ Cell : ( { value } : { value : any } ) => {
31
+ return < > { value . status } </ > ;
32
+ } ,
33
+ } ) ;
34
+ } ) ;
35
+
36
+ return objectiveGorup ;
37
+ }
38
+
19
39
function SelectedLTStudentViewTable ( classMissionMastery : any , selectedLTId : string | null ) {
20
40
const { data : targetMasteryData } = useClassTargetMasteryQuery ( {
21
41
variables : {
@@ -93,27 +113,8 @@ function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: stri
93
113
} ,
94
114
] ;
95
115
96
- const objectiveGorup : any = {
97
- Header : 'Objectives' ,
98
- columns : [ ] ,
99
- } ;
100
-
101
- // Set handles the case of two objectives with the same name
102
- const objectiveSet = new Set ( ) ;
103
-
104
- targetMasteryData . classTargetMastery . target . objectives . map ( ( objective : any ) => {
105
- if ( ! objectiveSet . has ( objective . objectiveId ) ) {
106
- objectiveSet . add ( objective . objectiveId ) ;
107
- objectiveGorup . columns . push ( {
108
- Header : objective . objectiveName ,
109
- accessor : `row.${ objective . objectiveId } ` ,
110
- Cell : ( { value } : { value : any } ) => {
111
- return < > { value . status } </ > ;
112
- } ,
113
- } ) ;
114
- }
115
- } ) ;
116
- tableColumns . push ( objectiveGorup ) ;
116
+ const objectiveGroup = genObjectiveGroup ( targetMasteryData ) ;
117
+ tableColumns . push ( objectiveGroup ) ;
117
118
118
119
// TODO This makes two massive assumptions:
119
120
// One that classMissionMastery and classTargetMastery are in the exact same student order
@@ -128,8 +129,8 @@ function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: stri
128
129
targetMasteryData . classTargetMastery . studentObjectiveMasteryList . map (
129
130
( studentObjectiveMastery : CtmStudentObjectiveMasteryFieldsFragment ) => {
130
131
if ( studentObjectiveMastery . objectiveMasteryList . length === 0 ) {
131
- objectiveSet . forEach ( ( objectiveId : any ) => {
132
- data [ index ] . row [ objectiveId ] = '' ;
132
+ objectiveGroup . columns . forEach ( ( column : any ) => {
133
+ data [ index ] . row [ column . accessor . substring ( 4 ) ] = '' ;
133
134
} ) ;
134
135
} else {
135
136
studentObjectiveMastery . objectiveMasteryList . map (
0 commit comments