diff --git a/website/src/actions/timetables.test.ts b/website/src/actions/timetables.test.ts index 8d253ab282..87f78daccd 100644 --- a/website/src/actions/timetables.test.ts +++ b/website/src/actions/timetables.test.ts @@ -53,12 +53,13 @@ describe('fillTimetableBlanks', () => { const moduleBank = { modules: { CS1010S, CS3216 } }; const timetablesState = (semester: Semester, timetable: SemTimetableConfig) => ({ lessons: { [semester]: timetable }, + customisedModules: { [semester]: [] }, }); const semester = 1; const action = actions.validateTimetable(semester); test('do nothing if timetable is already full', () => { - const timetable = { + const timetable: SemTimetableConfig = { CS1010S: { Lecture: ['1'], Tutorial: ['1'], @@ -66,6 +67,7 @@ describe('fillTimetableBlanks', () => { }, }; + // TODO(zwliew): Correctly type all the `state: any` declarations in this function and the rest of the codebase. const state: any = { timetables: timetablesState(semester, timetable), moduleBank }; const dispatch = jest.fn(); action(dispatch, () => state); @@ -74,7 +76,7 @@ describe('fillTimetableBlanks', () => { }); test('fill missing lessons with randomly generated modules', () => { - const timetable = { + const timetable: SemTimetableConfig = { CS1010S: { Lecture: ['1'], Tutorial: ['1'], diff --git a/website/src/actions/timetables.ts b/website/src/actions/timetables.ts index c1a73c833c..ce7763badc 100644 --- a/website/src/actions/timetables.ts +++ b/website/src/actions/timetables.ts @@ -236,14 +236,9 @@ export function validateTimetable(semester: Semester) { const module = moduleBank.modules[moduleCode]; if (!module) return; - // If the module is customised, we do not validate it - if ( - timetables.customisedModules && - timetables.customisedModules[semester] && - timetables.customisedModules[semester].includes(moduleCode) - ) { - return; - } + // Do not validate customised modules. + if (timetables.customisedModules[semester]?.includes(moduleCode)) return; + const [validatedLessonConfig, changedLessonTypes] = validateModuleLessons( semester, lessonConfig, diff --git a/website/src/types/reducers.ts b/website/src/types/reducers.ts index 406c7bc658..24bb6b7389 100644 --- a/website/src/types/reducers.ts +++ b/website/src/types/reducers.ts @@ -113,7 +113,7 @@ export type SettingsState = { export type ColorMapping = { [moduleCode: string]: ColorIndex }; export type SemesterColorMap = { [semester: string]: ColorMapping }; export type HiddenModulesMap = { [semester: string]: ModuleCode[] }; -export type CustomisedModulesMap = { [semester: string]: ModuleCode[] }; +export type CustomisedModulesMap = { [semester: string]: ModuleCode[] | undefined }; export type TimetablesState = { readonly lessons: TimetableConfig; diff --git a/website/src/views/timetable/TimetableContent.tsx b/website/src/views/timetable/TimetableContent.tsx index a11d98b873..463f506022 100644 --- a/website/src/views/timetable/TimetableContent.tsx +++ b/website/src/views/timetable/TimetableContent.tsx @@ -509,6 +509,7 @@ function mapStateToProps(state: StoreState, ownProps: OwnProps) { const { semester, timetable } = ownProps; const { modules } = state.moduleBank; const timetableWithLessons = hydrateSemTimetableWithLessons(timetable, modules, semester); + // TODO(zwliew): fix the type signature of state.timetables.hidden[semester] const hiddenInTimetable = state.timetables.hidden[semester] || []; return { @@ -518,7 +519,7 @@ function mapStateToProps(state: StoreState, ownProps: OwnProps) { modules, activeLesson: state.app.activeLesson, customiseModule: state.app.customiseModule, - customisedModules: state.timetables.customisedModules[semester], + customisedModules: state.timetables.customisedModules[semester] ?? [], timetableOrientation: state.theme.timetableOrientation, showTitle: state.theme.showTitle, hiddenInTimetable,