Skip to content

Commit 5d290e8

Browse files
authored
Merge pull request #49 from CPSECapstone/studentOverviewBreakdown
Student overview breakdown
2 parents ab567b1 + 0c34c6b commit 5d290e8

File tree

5 files changed

+91
-20
lines changed

5 files changed

+91
-20
lines changed

src/Components/StudentOverview/LTStudentViewTable.tsx

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
/* eslint-disable no-plusplus */
2+
/* eslint-disable @typescript-eslint/no-unused-vars */
3+
/* eslint-disable @typescript-eslint/no-floating-promises */
14
/* eslint-disable @typescript-eslint/no-explicit-any */
25
/* eslint-disable array-callback-return */
36
/* eslint-disable @typescript-eslint/restrict-template-expressions */
@@ -14,11 +17,14 @@ import { ToggleButton, ToggleButtonGroup } from '@material-ui/lab';
1417
import TableComponent from '../TableComponent/TableComponent';
1518
import {
1619
CmStudentFieldsFragment,
20+
CtmObjectiveMasteryFieldsFragment,
1721
Target,
1822
useClassMissionMasteryQuery,
23+
useClassTargetMasteryQuery,
1924
} from '../../__generated__/types';
2025
import { LIST_TARGETS_BY_COURSE } from '../../hooks/ListTargetsByCourse';
2126
import SelectedLTStudentViewTable from './SelectedLTStudentViewTable';
27+
import { Mastery } from '../../Screens/ClassMastery/StudentMasteryRow';
2228

2329
interface LTStudentViewRow {
2430
row: {
@@ -38,6 +44,8 @@ function LTStudentViewTable() {
3844
const { data: missionMasteryData } = useClassMissionMasteryQuery();
3945

4046
const [selectedLT, setSlectedLT] = useState<string | null>(null);
47+
const [targetMasteryDatas, setTargetMasteryDatas] = useState<any[]>([]);
48+
const [fetchOnce, setFetchOnce] = useState<boolean>(false);
4149

4250
const handleLTSelection = (
4351
event: React.MouseEvent<HTMLElement>,
@@ -50,9 +58,41 @@ function LTStudentViewTable() {
5058

5159
const { data: courseTargets } = useQuery(LIST_TARGETS_BY_COURSE);
5260

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) {
5491
return <div />;
5592
}
93+
if (targetMasteryDatas.length === courseTargets.targets.length) {
94+
console.log('Target Mastery Datas: ', targetMasteryDatas);
95+
}
5696

5797
const rowClicked = (row: LTStudentViewRow) => {
5898
history.push({
@@ -83,8 +123,6 @@ function LTStudentViewTable() {
83123
};
84124
});
85125

86-
console.log(data);
87-
88126
const tableColumns = [
89127
{
90128
Header: 'Student Information',
@@ -109,10 +147,6 @@ function LTStudentViewTable() {
109147
Header: 'Average',
110148
accessor: 'row.average',
111149
},
112-
{
113-
Header: 'Progress',
114-
accessor: 'row.progress',
115-
},
116150
],
117151
},
118152
];
@@ -126,14 +160,37 @@ function LTStudentViewTable() {
126160
const learningTargetSet = new Set();
127161

128162
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+
129168
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++;
131181
});
132182
if (!learningTargetSet.has(target.targetName)) {
133183
learningTargetSet.add(target.targetName);
134184
learningTargetGroup.columns.push({
135185
Header: target.description,
136186
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+
),
137194
});
138195
}
139196
});

src/Components/StudentOverview/LearningTargetTab.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ function LearningTargetTab() {
3030
<TabPanel value="1">
3131
<LTStudentViewTable />
3232
</TabPanel>
33-
<TabPanel value="2">
34-
<LTTargetViewTable />
35-
</TabPanel>
33+
<TabPanel value="2">Not Implemented</TabPanel>
3634
</TabContext>
3735
);
3836
}

src/Components/StudentOverview/MissionsTab.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,9 @@ function MissionsTab() {
3131
className={value === '3' ? 'selected-inner-tab' : 'inner-tab'}
3232
/>
3333
</TabList>
34-
<TabPanel value="1">
35-
<MissionStudentViewTable />
36-
</TabPanel>
37-
<TabPanel value="2">Mission Task View Table</TabPanel>
38-
<TabPanel value="3">Mission Objective View Table</TabPanel>
34+
<TabPanel value="1">Not Implemented</TabPanel>
35+
<TabPanel value="2">Not Implemented</TabPanel>
36+
<TabPanel value="3">Not Implemented</TabPanel>
3937
</TabContext>
4038
);
4139
}

src/Components/StudentOverview/SelectedLTStudentViewTable.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable no-restricted-syntax */
12
/* eslint-disable @typescript-eslint/no-unsafe-return */
23
/* eslint-disable no-plusplus */
34
/* eslint-disable array-callback-return */
@@ -165,6 +166,22 @@ function SelectedLTStudentViewTable(classMissionMastery: any, selectedLTId: stri
165166
}
166167
);
167168

169+
data.forEach((dataEntry) => {
170+
let count = 0;
171+
for (const [key, value] of Object.entries(dataEntry.row)) {
172+
const value2: any = value;
173+
if (typeof value === 'object' && value !== null) {
174+
if (value2.status === 'MASTERED') {
175+
count++;
176+
}
177+
}
178+
dataEntry.row.progress = `${(
179+
(count / targetMasteryData.classTargetMastery.target.objectives.length) *
180+
100
181+
).toFixed(1)}%`;
182+
}
183+
});
184+
168185
return (
169186
<div>
170187
<div className="base-table">

src/Screens/ClassMastery/StudentMasteryRow.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ import { color } from '../../Components/constants.json';
55
type MasteryBarProps = { percentage: number };
66

77
const MasteryBar = styled.div`
8-
position: relative;
98
border-radius: 11px;
109
background-color: ${color.bgGrey};
1110
overflow: hidden;
11+
width: 100%;
12+
height: 100%;
1213
`;
1314

1415
const InnerBar = styled.div<MasteryBarProps>`
@@ -18,17 +19,17 @@ const InnerBar = styled.div<MasteryBarProps>`
1819
bottom: 0;
1920
background-color: ${({ percentage }) =>
2021
percentage > 0.66 ? color.green : percentage > 0.33 ? color.yellow : color.red};
21-
right: ${({ percentage }) => 100 - percentage * 100 + '%'};
22+
right: ${({ percentage }) => `${100 - percentage * 100}%`};
2223
> span {
2324
position: absolute;
24-
color: white;
25+
color: black;
2526
top: 4px;
2627
font-size: 14px;
2728
right: ${({ percentage }) => (percentage > 0.25 ? '5px' : '-33px')};
2829
}
2930
`;
3031

31-
function Mastery({ percentage }: MasteryBarProps) {
32+
export function Mastery({ percentage }: MasteryBarProps) {
3233
return (
3334
<MasteryBar>
3435
<InnerBar percentage={percentage}>

0 commit comments

Comments
 (0)