1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
2
+ /* eslint-disable array-callback-return */
3
+ /* eslint-disable @typescript-eslint/restrict-template-expressions */
4
+ /* eslint-disable @typescript-eslint/no-unsafe-assignment */
5
+ /* eslint-disable no-param-reassign */
6
+ /* eslint-disable @typescript-eslint/no-unsafe-call */
7
+ /* eslint-disable @typescript-eslint/no-unsafe-member-access */
8
+ /* eslint-disable no-restricted-syntax */
1
9
import { useHistory } from 'react-router-dom' ;
10
+ import { useQuery } from '@apollo/client' ;
11
+ import React , { useState } from 'react' ;
12
+ import { ToggleButton , ToggleButtonGroup } from '@material-ui/lab' ;
2
13
import TableComponent from '../TableComponent/TableComponent' ;
3
- import { useProgressOverviewQuery , UserProgress } from '../../__generated__/types' ;
14
+ import {
15
+ CmStudentFieldsFragment ,
16
+ Target ,
17
+ useClassMissionMasteryQuery ,
18
+ } from '../../__generated__/types' ;
19
+ import { LIST_TARGETS_BY_COURSE } from '../../hooks/ListTargetsByCourse' ;
20
+ import SelectedLTStudentViewTable from './SelectedLTStudentViewTable' ;
4
21
5
22
function LTStudentViewTable ( ) {
6
- const { data : progressData } = useProgressOverviewQuery ( {
7
- variables : {
8
- course : 'Integrated Science' ,
9
- } ,
10
- } ) ;
23
+ const { data : missionMasteryData } = useClassMissionMasteryQuery ( ) ;
24
+
25
+ const [ selectedLT , setSlectedLT ] = useState < string | null > ( null ) ;
26
+
27
+ const handleLTSelection = (
28
+ event : React . MouseEvent < HTMLElement > ,
29
+ newSelectedLT : string | null
30
+ ) => {
31
+ setSlectedLT ( newSelectedLT ) ;
32
+ } ;
11
33
12
34
const history = useHistory ( ) ;
13
35
36
+ const { data : courseTargets } = useQuery ( LIST_TARGETS_BY_COURSE ) ;
37
+
38
+ if ( ! courseTargets ) {
39
+ return < div /> ;
40
+ }
41
+
14
42
const rowClicked = ( userName : string ) => {
15
43
history . push ( {
16
44
pathname : '/singleStudentMasteryOverview' ,
@@ -19,31 +47,30 @@ function LTStudentViewTable() {
19
47
} ;
20
48
21
49
const data : any [ ] = [ ] ;
22
- progressData ?. progressOverview . userProgress . map ( ( userProgress : UserProgress ) =>
23
- data . push ( {
24
- row : {
25
- section : 1 ,
26
- name : userProgress . userName ,
27
- recent : {
28
- status :
29
- userProgress . progress . length !== 0
30
- ? userProgress . progress [ userProgress . progress . length - 1 ] . taskId
31
- : '' ,
32
- style : {
33
- backgroundColor :
34
- userProgress . progress . length !== 0
35
- ? userProgress . progress [ userProgress . progress . length - 1 ] . status
36
- ? '#00b300'
37
- : '#ff6666'
38
- : '#a6a6a6' ,
39
- } ,
50
+ missionMasteryData ?. classMissionMastery ?. studentMissionMasteryList . map (
51
+ ( studentMissionMastery : CmStudentFieldsFragment ) =>
52
+ data . push ( {
53
+ row : {
54
+ section : '1' ,
55
+ name : `${ studentMissionMastery . student . lastName } ${ studentMissionMastery . student . firstName } ` ,
56
+ team : studentMissionMastery . student . team ,
57
+ recent : studentMissionMastery . currentTaskName ,
58
+ average : '' ,
59
+ progress : `${ ( studentMissionMastery . progress * 100 ) . toFixed ( 1 ) } %` ,
40
60
} ,
41
- average : '' ,
42
- progress : '%' ,
43
- } ,
44
- } )
61
+ } )
45
62
) ;
46
63
64
+ // TODO remove when names are populated
65
+ data . forEach ( ( dataEntry ) => {
66
+ if ( dataEntry . row . name . indexOf ( 'null' ) !== - 1 ) {
67
+ dataEntry . row . name = 'Mary Lee' ;
68
+ }
69
+ if ( dataEntry . row . name . length > 25 ) {
70
+ dataEntry . row . name = dataEntry . row . name . substring ( 0 , 25 ) ;
71
+ }
72
+ } ) ;
73
+
47
74
console . log ( data ) ;
48
75
49
76
const tableColumns = [
@@ -58,13 +85,13 @@ function LTStudentViewTable() {
58
85
Header : 'Student' ,
59
86
accessor : 'row.name' ,
60
87
} ,
88
+ {
89
+ Header : 'Team' ,
90
+ accessor : 'row.team' ,
91
+ } ,
61
92
{
62
93
Header : 'Recent' ,
63
94
accessor : 'row.recent' ,
64
- Cell : ( { value } : { value : any } ) => {
65
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
66
- return < > { value . status } </ > ;
67
- } ,
68
95
} ,
69
96
{
70
97
Header : 'Average' ,
@@ -83,27 +110,50 @@ function LTStudentViewTable() {
83
110
columns : [ ] ,
84
111
} ;
85
112
113
+ // Set handles the case of two learing targets with the same name
86
114
const learningTargetSet = new Set ( ) ;
87
115
88
- if ( progressData !== undefined ) {
89
- for ( const target of progressData ?. progressOverview . targets ) {
90
- data . map ( ( row ) => {
91
- row . row [ target . targetName ] = '' ;
116
+ courseTargets . targets . map ( ( target : Target ) => {
117
+ data . map ( ( row : any ) => {
118
+ row . row [ target . targetName ] = '' ;
119
+ } ) ;
120
+ if ( ! learningTargetSet . has ( target . targetName ) ) {
121
+ learningTargetSet . add ( target . targetName ) ;
122
+ learningTargetGroup . columns . push ( {
123
+ Header : target . description ,
124
+ accessor : `row.${ target . targetName } ` ,
92
125
} ) ;
93
- if ( ! learningTargetSet . has ( target . targetName ) ) {
94
- learningTargetSet . add ( target . targetName ) ;
95
- learningTargetGroup . columns . push ( {
96
- Header : target . targetName ,
97
- accessor : `row.${ target . targetName } ` ,
98
- } ) ;
99
- }
100
126
}
101
- tableColumns . push ( learningTargetGroup ) ;
102
- }
127
+ } ) ;
128
+ tableColumns . push ( learningTargetGroup ) ;
103
129
104
130
return (
105
- < div className = "base-table" >
106
- < TableComponent columns = { tableColumns } data = { data } rowClickFunction = { rowClicked } />
131
+ < div >
132
+ < ToggleButtonGroup
133
+ value = { selectedLT }
134
+ style = { { paddingLeft : '20px' } }
135
+ exclusive
136
+ onChange = { handleLTSelection }
137
+ >
138
+ { courseTargets . targets . map ( ( target : Target ) => {
139
+ return (
140
+ < ToggleButton value = { target . targetId } style = { { width : '100px' } } >
141
+ { target . targetName }
142
+ </ ToggleButton >
143
+ ) ;
144
+ } ) }
145
+ </ ToggleButtonGroup >
146
+
147
+ { selectedLT === null ? (
148
+ < div className = "base-table" >
149
+ < TableComponent columns = { tableColumns } data = { data } rowClickFunction = { rowClicked } />
150
+ </ div >
151
+ ) : (
152
+ < SelectedLTStudentViewTable
153
+ classMissionMastery = { missionMasteryData ?. classMissionMastery }
154
+ selectedLTId = { selectedLT }
155
+ />
156
+ ) }
107
157
</ div >
108
158
) ;
109
159
}
0 commit comments