Skip to content

Commit 61558e3

Browse files
committed
timetable: fix more nullability issues
1 parent f29b21a commit 61558e3

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

website/src/actions/timetables.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,21 @@ describe('fillTimetableBlanks', () => {
5353
const moduleBank = { modules: { CS1010S, CS3216 } };
5454
const timetablesState = (semester: Semester, timetable: SemTimetableConfig) => ({
5555
lessons: { [semester]: timetable },
56+
customisedModules: { [semester]: [] },
5657
});
5758
const semester = 1;
5859
const action = actions.validateTimetable(semester);
5960

6061
test('do nothing if timetable is already full', () => {
61-
const timetable = {
62+
const timetable: SemTimetableConfig = {
6263
CS1010S: {
6364
Lecture: ['1'],
6465
Tutorial: ['1'],
6566
Recitation: ['1'],
6667
},
6768
};
6869

70+
// TODO(zwliew): Correctly type all the `state: any` declarations in this function and the rest of the codebase.
6971
const state: any = { timetables: timetablesState(semester, timetable), moduleBank };
7072
const dispatch = jest.fn();
7173
action(dispatch, () => state);
@@ -74,7 +76,7 @@ describe('fillTimetableBlanks', () => {
7476
});
7577

7678
test('fill missing lessons with randomly generated modules', () => {
77-
const timetable = {
79+
const timetable: SemTimetableConfig = {
7880
CS1010S: {
7981
Lecture: ['1'],
8082
Tutorial: ['1'],

website/src/actions/timetables.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,9 @@ export function validateTimetable(semester: Semester) {
236236
const module = moduleBank.modules[moduleCode];
237237
if (!module) return;
238238

239-
// If the module is customised, we do not validate it
240-
if (
241-
timetables.customisedModules &&
242-
timetables.customisedModules[semester] &&
243-
timetables.customisedModules[semester].includes(moduleCode)
244-
) {
245-
return;
246-
}
239+
// Do not validate customised modules.
240+
if (timetables.customisedModules[semester]?.includes(moduleCode)) return;
241+
247242
const [validatedLessonConfig, changedLessonTypes] = validateModuleLessons(
248243
semester,
249244
lessonConfig,

website/src/types/reducers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export type SettingsState = {
113113
export type ColorMapping = { [moduleCode: string]: ColorIndex };
114114
export type SemesterColorMap = { [semester: string]: ColorMapping };
115115
export type HiddenModulesMap = { [semester: string]: ModuleCode[] };
116-
export type CustomisedModulesMap = { [semester: string]: ModuleCode[] };
116+
export type CustomisedModulesMap = { [semester: string]: ModuleCode[] | undefined };
117117

118118
export type TimetablesState = {
119119
readonly lessons: TimetableConfig;

website/src/views/timetable/TimetableContent.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,7 @@ function mapStateToProps(state: StoreState, ownProps: OwnProps) {
509509
const { semester, timetable } = ownProps;
510510
const { modules } = state.moduleBank;
511511
const timetableWithLessons = hydrateSemTimetableWithLessons(timetable, modules, semester);
512+
// TODO(zwliew): fix the type signature of state.timetables.hidden[semester]
512513
const hiddenInTimetable = state.timetables.hidden[semester] || [];
513514

514515
return {
@@ -518,7 +519,7 @@ function mapStateToProps(state: StoreState, ownProps: OwnProps) {
518519
modules,
519520
activeLesson: state.app.activeLesson,
520521
customiseModule: state.app.customiseModule,
521-
customisedModules: state.timetables.customisedModules[semester],
522+
customisedModules: state.timetables.customisedModules[semester] ?? [],
522523
timetableOrientation: state.theme.timetableOrientation,
523524
showTitle: state.theme.showTitle,
524525
hiddenInTimetable,

0 commit comments

Comments
 (0)