Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requirement builder with the new data format #588

Merged
merged 6 commits into from
Dec 4, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/Modals/NewCourse/NewCourseModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default defineComponent({
components: { CourseSelector, TeleportModal, SelectedRequirementEditor },
emits: {
'close-course-modal': () => true,
'add-course': (course: CornellCourseRosterCourse, requirementID: string) =>
typeof course === 'object' && typeof requirementID === 'string',
'add-course': (course: CornellCourseRosterCourse, choice: FirestoreCourseOptInOptOutChoices) =>
typeof course === 'object' && typeof choice === 'object',
},
data() {
return {
Expand Down Expand Up @@ -98,7 +98,7 @@ export default defineComponent({
selectedCourse,
store.state.groupedRequirementFulfillmentReport,
store.state.toggleableRequirementChoices,
/* deprecated AppOverriddenFulfillmentChoices */ {}
store.state.overriddenFulfillmentChoices
);
const requirementsThatAllowDoubleCounting: string[] = [];
Expand Down Expand Up @@ -137,7 +137,15 @@ export default defineComponent({
},
addCourse() {
if (this.selectedCourse == null) return;
this.$emit('add-course', this.selectedCourse, this.selectedRequirementID);
this.$emit('add-course', this.selectedCourse, {
optOut: this.relatedRequirements
.filter(it => it.id !== this.selectedRequirementID)
.map(it => it.id),
acknowledgedCheckerWarningOptIn: this.selfCheckRequirements
.filter(it => it.id !== this.selectedRequirementID)
.map(it => it.id),
arbitraryOptIn: {},
});
this.closeCurrentModal();
},
onSelectedChange(selected: string) {
Expand Down
41 changes: 37 additions & 4 deletions src/components/Requirements/IncompleteSelfCheck.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@ import store from '@/store';
import {
cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData,
addCourseToSemester,
addCourseToSelectableRequirements,
updateRequirementChoice,
} from '@/global-firestore-data';
import { canFulfillChecker } from '@/requirements/requirement-frontend-utils';
import {
canFulfillChecker,
getAllEligibleRelatedRequirementIds,
} from '@/requirements/requirement-frontend-utils';

import NewSelfCheckCourseModal from '@/components/Modals/NewCourse/NewSelfCheckCourseModal.vue';

Expand Down Expand Up @@ -150,12 +153,42 @@ export default defineComponent({
},
addExistingCourse(option: string) {
this.showDropdown = false;
addCourseToSelectableRequirements(this.selfCheckCourses[option].uniqueID, this.subReqId);
updateRequirementChoice(this.selfCheckCourses[option].uniqueID, choice => ({
...choice,
// Since we edit from a self-check requirement,
// we know it must be `acknowledgedCheckerWarningOptIn`.
acknowledgedCheckerWarningOptIn: Array.from(
new Set([...choice.acknowledgedCheckerWarningOptIn, this.subReqId])
),
// Keep existing behavior of keeping it connected to at most one requirement.
optOut: getAllEligibleRelatedRequirementIds(
this.selfCheckCourses[option].crseId,
store.state.groupedRequirementFulfillmentReport,
store.state.toggleableRequirementChoices
),
}));
},
addNewCourse(course: CornellCourseRosterCourse, season: FirestoreSemesterSeason, year: number) {
this.showDropdown = false;
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(course);
addCourseToSemester(year, season, newCourse, this.subReqId, this.$gtag);
addCourseToSemester(
year,
season,
newCourse,
// Since the course is new, we know the old choice does not exist.
() => ({
arbitraryOptIn: {},
// Since we edit from a self-check requirement,
// we know it must be `acknowledgedCheckerWarningOptIn`.
acknowledgedCheckerWarningOptIn: [this.subReqId],
optOut: getAllEligibleRelatedRequirementIds(
newCourse.crseId,
store.state.groupedRequirementFulfillmentReport,
store.state.toggleableRequirementChoices
),
}),
this.$gtag
);
},
openCourseModal() {
this.isCourseModalOpen = true;
Expand Down
11 changes: 3 additions & 8 deletions src/components/Requirements/RequirementSelfCheckSlots.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import IncompleteSelfCheck from '@/components/Requirements/IncompleteSelfCheck.v

import store from '@/store';
import {
convertFirestoreSemesterCourseToCourseTaken,
getMatchedRequirementFulfillmentSpecification,
courseIsAPIB,
} from '@/requirements/requirement-frontend-utils';
Expand All @@ -39,13 +38,9 @@ export default defineComponent({
computed: {
fulfilledSelfCheckCourses(): readonly CourseTaken[] {
// selectedCourses are courses that fulfill the requirement based on user-choice
// they are taken from derivedSelectableRequirementData
const selectedFirestoreCourses =
store.state.derivedSelectableRequirementData.requirementToCoursesMap[
this.requirementFulfillment.requirement.id
] || [];
const selectedCourses = selectedFirestoreCourses.map(
convertFirestoreSemesterCourseToCourseTaken
// they are taken from requirement graph
const selectedCourses = store.state.requirementFulfillmentGraph.getConnectedCoursesFromRequirement(
this.requirementFulfillment.requirement.id
);

// fulfillableCourses are the courses that can fulfill this requirement
Expand Down
31 changes: 23 additions & 8 deletions src/components/Semester/Semester.vue
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ import {
addCourseToSemester,
deleteCourseFromSemester,
deleteAllCoursesFromSemester,
addCoursesToSelectableRequirements,
updateRequirementChoices,
} from '@/global-firestore-data';
import { updateSubjectColorData } from '@/store';
import store, { updateSubjectColorData } from '@/store';
import { getAllEligibleRelatedRequirementIds } from '@/requirements/requirement-frontend-utils';

type ComponentRef = { $el: HTMLDivElement };

Expand Down Expand Up @@ -239,11 +240,24 @@ export default defineComponent({
courses,
})
);
const newChoices: Record<string, string> = {};
newCourses.forEach(({ uniqueID, requirementID }) => {
if (requirementID) newChoices[uniqueID] = requirementID;
updateRequirementChoices(oldChoices => {
const choices = { ...oldChoices };
newCourses.forEach(({ uniqueID, requirementID, crseId }) => {
if (requirementID == null) return;
const choice = choices[uniqueID] || {
arbitraryOptIn: {},
acknowledgedCheckerWarningOptIn: [],
optOut: [],
};
const optOut = getAllEligibleRelatedRequirementIds(
crseId,
store.state.groupedRequirementFulfillmentReport,
store.state.toggleableRequirementChoices
).filter(it => it !== requirementID);
choices[uniqueID] = { ...choice, optOut };
});
return choices;
SamChou19815 marked this conversation as resolved.
Show resolved Hide resolved
});
addCoursesToSelectableRequirements(newChoices);
},
},
// Add space for a course if there is a "shadow" of it, decrease if it is from the current sem
Expand Down Expand Up @@ -330,9 +344,10 @@ export default defineComponent({
closeConfirmationModal() {
this.isConfirmationOpen = false;
},
addCourse(data: CornellCourseRosterCourse, requirementID: string) {
addCourse(data: CornellCourseRosterCourse, choice: FirestoreCourseOptInOptOutChoices) {
const newCourse = cornellCourseRosterCourseToFirebaseSemesterCourseWithGlobalData(data);
addCourseToSemester(this.year, this.season, newCourse, requirementID, this.$gtag);
// Since the course is new, we know the old choice does not exist.
addCourseToSemester(this.year, this.season, newCourse, () => choice, this.$gtag);

const courseCode = `${data.subject} ${data.catalogNbr}`;
this.openConfirmationModal(`Added ${courseCode} to ${this.season} ${this.year}`);
Expand Down
8 changes: 4 additions & 4 deletions src/global-firestore-data/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export {
} from './semesters';
export { default as chooseToggleableRequirementOption } from './toggleable-requirement-choices';
export {
addCourseToSelectableRequirements,
addCoursesToSelectableRequirements,
deleteCourseFromSelectableRequirements,
} from './selectable-requirement-choices';
updateRequirementChoice,
updateRequirementChoices,
deleteCourseFromRequirementChoices,
} from './override-fulfillment-choices';
46 changes: 46 additions & 0 deletions src/global-firestore-data/override-fulfillment-choices.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { overriddenFulfillmentChoicesCollection } from '../firebase-frontend-config';
import store from '../store';

export const updateRequirementChoice = (
courseUniqueID: string | number,
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices
): void => {
overriddenFulfillmentChoicesCollection.doc(store.state.currentFirebaseUser.email).set({
...store.state.overriddenFulfillmentChoices,
[courseUniqueID]: choiceUpdater(
store.state.overriddenFulfillmentChoices[courseUniqueID] || {
arbitraryOptIn: {},
acknowledgedCheckerWarningOptIn: [],
optOut: [],
}
),
});
};

export const updateRequirementChoices = (
updater: (
oldChoices: FirestoreOverriddenFulfillmentChoices
) => FirestoreOverriddenFulfillmentChoices
): void => {
overriddenFulfillmentChoicesCollection
.doc(store.state.currentFirebaseUser.email)
.set(updater(store.state.overriddenFulfillmentChoices));
};

export const deleteCourseFromRequirementChoices = (courseUniqueID: string | number): void =>
deleteCoursesFromRequirementChoices([courseUniqueID]);

export const deleteCoursesFromRequirementChoices = (
courseUniqueIds: readonly (string | number)[]
): void => {
const courseUniqueIdStrings = new Set(courseUniqueIds.map(uniqueId => uniqueId.toString()));
overriddenFulfillmentChoicesCollection
.doc(store.state.currentFirebaseUser.email)
.set(
Object.fromEntries(
Object.entries(store.state.overriddenFulfillmentChoices).filter(
([uniqueId]) => !courseUniqueIdStrings.has(uniqueId)
)
)
);
};
80 changes: 0 additions & 80 deletions src/global-firestore-data/selectable-requirement-choices.ts

This file was deleted.

22 changes: 10 additions & 12 deletions src/global-firestore-data/semesters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import { GTag, GTagEvent } from '../gtag';
import { sortedSemesters } from '../utilities';

import {
addCourseToSelectableRequirements,
deleteCourseFromSelectableRequirements,
deleteCoursesFromSelectableRequirements,
} from './selectable-requirement-choices';
updateRequirementChoice,
deleteCourseFromRequirementChoices,
deleteCoursesFromRequirementChoices,
} from './override-fulfillment-choices';

export const editSemesters = (
updater: (oldSemesters: readonly FirestoreSemester[]) => readonly FirestoreSemester[]
Expand Down Expand Up @@ -81,7 +81,7 @@ export const deleteSemester = (
GTagEvent(gtag, 'delete-semester');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCoursesFromSelectableRequirements(semester.courses.map(course => course.uniqueID));
deleteCoursesFromRequirementChoices(semester.courses.map(course => course.uniqueID));
editSemesters(oldSemesters => oldSemesters.filter(sem => !semesterEquals(sem, year, season)));
}
};
Expand All @@ -90,7 +90,7 @@ export const addCourseToSemester = (
year: number,
season: FirestoreSemesterSeason,
newCourse: FirestoreSemesterCourse,
requirementID?: string,
choiceUpdater: (choice: FirestoreCourseOptInOptOutChoices) => FirestoreCourseOptInOptOutChoices,
Copy link
Contributor

@hahnbeelee hahnbeelee Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does choiceUpdater work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a function that takes in the current choice as parameter and return the updated choice.

gtag?: GTag
): void => {
GTagEvent(gtag, 'add-course');
Expand All @@ -106,9 +106,7 @@ export const addCourseToSemester = (
if (semesterFound) return newSemestersWithCourse;
return [...oldSemesters, createSemester(year, season, [newCourse])];
});
if (requirementID) {
addCourseToSelectableRequirements(newCourse.uniqueID, requirementID);
}
updateRequirementChoice(newCourse.uniqueID, choiceUpdater);
};

export const deleteCourseFromSemester = (
Expand All @@ -120,7 +118,7 @@ export const deleteCourseFromSemester = (
GTagEvent(gtag, 'delete-course');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCourseFromSelectableRequirements(courseUniqueID);
deleteCourseFromRequirementChoices(courseUniqueID);
editSemesters(oldSemesters =>
oldSemesters.map(sem => ({
...sem,
Expand All @@ -140,7 +138,7 @@ export const deleteAllCoursesFromSemester = (
GTagEvent(gtag, 'delete-semester-courses');
const semester = store.state.semesters.find(sem => semesterEquals(sem, year, season));
if (semester) {
deleteCoursesFromSelectableRequirements(semester.courses.map(course => course.uniqueID));
deleteCoursesFromRequirementChoices(semester.courses.map(course => course.uniqueID));
editSemesters(oldSemesters =>
oldSemesters.map(sem => ({
...sem,
Expand All @@ -160,7 +158,7 @@ export const deleteCourseFromSemesters = (courseUniqueID: number, gtag?: GTag):
return { ...semester, courses: coursesWithoutDeleted };
})
);
deleteCourseFromSelectableRequirements(courseUniqueID);
deleteCourseFromRequirementChoices(courseUniqueID);
};

// exposed for testing
Expand Down
Loading