Skip to content

Commit eee8865

Browse files
Robert MiddletonRobert Middleton
authored andcommitted
Separated generation of objective group for selectedLTStudentViewTable.
1 parent ee94539 commit eee8865

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

src/Components/StudentOverview/SelectedLTStudentViewTable.tsx

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable @typescript-eslint/no-unsafe-return */
12
/* eslint-disable no-plusplus */
23
/* eslint-disable array-callback-return */
34
/* eslint-disable no-param-reassign */
@@ -16,6 +17,25 @@ import {
1617
useClassTargetMasteryQuery,
1718
} from '../../__generated__/types';
1819

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+
1939
function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: string | null) {
2040
const { data: targetMasteryData } = useClassTargetMasteryQuery({
2141
variables: {
@@ -93,27 +113,8 @@ function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: stri
93113
},
94114
];
95115

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);
117118

118119
// TODO This makes two massive assumptions:
119120
// One that classMissionMastery and classTargetMastery are in the exact same student order
@@ -128,8 +129,8 @@ function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: stri
128129
targetMasteryData.classTargetMastery.studentObjectiveMasteryList.map(
129130
(studentObjectiveMastery: CtmStudentObjectiveMasteryFieldsFragment) => {
130131
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)] = '';
133134
});
134135
} else {
135136
studentObjectiveMastery.objectiveMasteryList.map(

0 commit comments

Comments
 (0)