Skip to content

Commit

Permalink
timetable: fix more nullability issues
Browse files Browse the repository at this point in the history
  • Loading branch information
zwliew committed Aug 4, 2023
1 parent 0faf6e1 commit 60a3650
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
6 changes: 4 additions & 2 deletions website/src/actions/timetables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,21 @@ 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'],
Recitation: ['1'],
},
};

// 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);
Expand All @@ -74,7 +76,7 @@ describe('fillTimetableBlanks', () => {
});

test('fill missing lessons with randomly generated modules', () => {
const timetable = {
const timetable: SemTimetableConfig = {
CS1010S: {
Lecture: ['1'],
Tutorial: ['1'],
Expand Down
11 changes: 3 additions & 8 deletions website/src/actions/timetables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion website/src/types/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion website/src/views/timetable/TimetableContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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,
Expand Down

0 comments on commit 60a3650

Please sign in to comment.