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

Adding index to filtering logic for generic/NUPath course deletions #782

Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions packages/frontend/components/Plan/Plan.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@ export const Plan: React.FC<PlanProps> = ({

const removeCourseFromTermInCurrPlan = (
course: ScheduleCourse2<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => {
const updatedPlan = removeCourseFromTerm(
course,
courseIndex,
termYear,
termSeason,
plan
Expand Down
10 changes: 8 additions & 2 deletions packages/frontend/components/Plan/ScheduleTerm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ScheduleTermProps {
/** Function to remove a course from a given term in the plan being displayed. */
removeCourseFromTermInCurrPlan: (
course: ScheduleCourse2<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => void;
Expand Down Expand Up @@ -72,13 +73,18 @@ export const ScheduleTerm: React.FC<ScheduleTermProps> = ({
season={scheduleTerm.season}
credits={totalCreditsInTerm(scheduleTerm)}
/>
{scheduleTerm.classes.map((scheduleCourse) => (
{scheduleTerm.classes.map((scheduleCourse, courseIndex) => (
<DraggableScheduleCourse
coReqErr={termCoReqErr?.[courseToString(scheduleCourse)]}
preReqErr={termPreReqErr?.[courseToString(scheduleCourse)]}
scheduleCourse={scheduleCourse}
removeCourse={(course: ScheduleCourse2<unknown>) =>
removeCourseFromTermInCurrPlan(course, yearNum, scheduleTerm.season)
removeCourseFromTermInCurrPlan(
course,
courseIndex,
yearNum,
scheduleTerm.season
)
}
isEditable
key={scheduleCourse.id}
Expand Down
1 change: 1 addition & 0 deletions packages/frontend/components/Plan/ScheduleYear.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ interface ScheduleYearProps extends ToggleYearProps {
/** Function to remove a course from a given term in the plan being displayed. */
removeCourseFromTermInCurrPlan: (
course: ScheduleCourse2<unknown>,
courseIndex: number,
termYear: number,
termSeason: SeasonEnum
) => void;
Expand Down
6 changes: 5 additions & 1 deletion packages/frontend/utils/plan/removeCourseFromTerm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { findTerm } from "./findTerm";
*/
export const removeCourseFromTerm = (
courseToRemove: ScheduleCourse2<unknown>,
courseToRemoveIndex: number,
termYear: number,
termSeason: SeasonEnum,
plan: PlanModel<string>
Expand All @@ -19,7 +20,10 @@ export const removeCourseFromTerm = (

// remove the course
term.classes = term.classes.filter(
(course) => !isEqualCourses(course, courseToRemove)
(course, index) =>
index != courseToRemoveIndex ||
(index == courseToRemoveIndex &&
!isEqualCourses(course, courseToRemove))
);
});

Expand Down
Loading