-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathSectionTable.tsx
More file actions
226 lines (209 loc) · 8.38 KB
/
Copy pathSectionTable.tsx
File metadata and controls
226 lines (209 loc) · 8.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
import { Assessment, Route, ShowChart as ShowChartIcon } from '@mui/icons-material';
import { Alert, Box, Paper, Table, TableCell, TableContainer, TableHead, TableRow } from '@mui/material';
import { useMemo } from 'react';
import { CourseInfoBar } from '$components/RightPane/SectionTable/CourseInfo/CourseInfoBar';
import { CourseInfoButton } from '$components/RightPane/SectionTable/CourseInfo/CourseInfoButton';
import { CourseInfoSearchButton } from '$components/RightPane/SectionTable/CourseInfo/CourseInfoSearchButton';
import { EnrollmentColumnHeader } from '$components/RightPane/SectionTable/EnrollmentColumnHeader';
import { EnrollmentHistoryPopup } from '$components/RightPane/SectionTable/EnrollmentHistoryPopup';
import GradesPopup from '$components/RightPane/SectionTable/GradesPopup';
import { SectionTableProps } from '$components/RightPane/SectionTable/SectionTable.types';
import { SectionTableBody } from '$components/RightPane/SectionTable/SectionTableBody/SectionTableBody';
import { useIsMobile } from '$hooks/useIsMobile';
import analyticsEnum from '$lib/analytics/analytics';
import { useColumnStore, SECTION_TABLE_COLUMNS, type SectionTableColumn } from '$stores/ColumnStore';
import { useTimeFormatStore } from '$stores/SettingsStore';
import { useTabStore } from '$stores/TabStore';
const TOTAL_NUM_COLUMNS = SECTION_TABLE_COLUMNS.length;
interface TableHeaderColumnDetails {
label: string;
width?: string;
}
const tableHeaderColumns: Record<Exclude<SectionTableColumn, 'action'>, TableHeaderColumnDetails> = {
sectionCode: {
label: 'Code',
width: '8%',
},
sectionDetails: {
label: 'Type',
width: '8%',
},
instructors: {
label: 'Instructors',
width: '15%',
},
gpa: {
label: 'GPA',
width: '5%',
},
dayAndTime: {
label: 'Times',
width: '15%',
},
location: {
label: 'Places',
width: '8%',
},
sectionEnrollment: {
label: 'Enrollment',
width: '9%',
},
restrictions: {
label: 'Restr',
width: '8%',
},
status: {
label: 'Status',
width: '8%',
},
syllabus: {
label: 'Syllabus',
width: '8%',
},
};
const tableHeaderColumnEntries = Object.entries(tableHeaderColumns);
function SectionTable(props: SectionTableProps) {
const { courseDetails, term, allowHighlight, scheduleNames, analyticsCategory, missingSections = [] } = props;
const { isMilitaryTime } = useTimeFormatStore();
const [activeColumns] = useColumnStore((store) => [store.activeColumns]);
const [activeTab] = useTabStore((store) => [store.activeTab]);
const isMobile = useIsMobile();
const courseId = useMemo(() => {
return courseDetails.deptCode.replaceAll(' ', '') + courseDetails.courseNumber;
}, [courseDetails.deptCode, courseDetails.courseNumber]);
const formattedTime = useMemo(() => {
if (!courseDetails.updatedAt) return null;
const date = new Date(courseDetails.updatedAt);
if (isNaN(date.getTime())) return null;
const timeString = date.toLocaleTimeString(undefined, {
hour: '2-digit',
minute: '2-digit',
hour12: !isMilitaryTime,
});
return timeString.replace(/^0(\d)/, '$1');
}, [courseDetails.updatedAt, isMilitaryTime]);
/**
* Limit table width to force side scrolling.
*/
const width = 780;
const tableMinWidth = useMemo(() => {
const numActiveColumns = activeColumns.length;
return (width * numActiveColumns) / TOTAL_NUM_COLUMNS;
}, [activeColumns]);
return (
<>
<Box
sx={{
display: 'flex',
alignItems: 'center',
gap: '4px',
marginBottom: '8px',
marginTop: '4px',
}}
>
<CourseInfoBar
deptCode={courseDetails.deptCode}
courseTitle={courseDetails.courseTitle}
courseNumber={courseDetails.courseNumber}
prerequisiteLink={courseDetails.prerequisiteLink}
analyticsCategory={analyticsCategory}
/>
{activeTab !== 2 ? null : <CourseInfoSearchButton courseDetails={courseDetails} term={term} />}
<CourseInfoButton
analyticsCategory={analyticsCategory}
analyticsAction={analyticsEnum.classSearch.actions.CLICK_REVIEWS}
text="Planner"
icon={<Route />}
redirectLink={`https://antalmanac.com/planner/course/${encodeURIComponent(courseId)}`}
/>
<CourseInfoButton
analyticsCategory={analyticsCategory}
analyticsAction={analyticsEnum.classSearch.actions.CLICK_ZOTISTICS}
text="Zotistics"
icon={<Assessment />}
popupContent={
<GradesPopup
deptCode={courseDetails.deptCode}
courseNumber={courseDetails.courseNumber}
isMobile={isMobile}
/>
}
/>
<CourseInfoButton
analyticsCategory={analyticsCategory}
analyticsAction={analyticsEnum.classSearch.actions.CLICK_PAST_ENROLLMENT}
text="Past Enrollment"
icon={<ShowChartIcon />}
popupContent={
<EnrollmentHistoryPopup
department={courseDetails.deptCode}
courseNumber={courseDetails.courseNumber}
/>
}
/>
</Box>
{missingSections?.length > 0 && (
<Alert
severity="warning"
sx={{
mb: 1,
'& .MuiAlert-message': {
display: 'flex',
alignItems: 'center',
},
}}
>
Missing required sections: {missingSections.join(', ')}
</Alert>
)}
<TableContainer
component={Paper}
sx={{ margin: '8px 0px 8px 0px', width: '100%' }}
elevation={0}
variant="outlined"
>
<Table
size="small"
sx={{
minWidth: `${tableMinWidth}px`,
width: '100%',
tableLayout: 'fixed',
}}
>
<TableHead>
<TableRow>
<TableCell
sx={{
padding: 0,
width: isMobile ? '6%' : '8%',
}}
/>
{tableHeaderColumnEntries
.filter(([column]) => activeColumns.includes(column as SectionTableColumn))
.map(([column, { label, width }]) => (
<TableCell
key={column}
sx={{
width: width,
padding: 0,
}}
>
{label === 'Enrollment' ? <EnrollmentColumnHeader label={label} /> : label}
</TableCell>
))}
</TableRow>
</TableHead>
<SectionTableBody
courseDetails={courseDetails}
term={term}
allowHighlight={allowHighlight}
scheduleNames={scheduleNames}
analyticsCategory={analyticsCategory}
formattedTime={formattedTime}
/>
</Table>
</TableContainer>
</>
);
}
export default SectionTable;