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

Add support for removing marks from a course #1186

Merged
merged 4 commits into from
Aug 18, 2024
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: 1 addition & 1 deletion backend/server/routers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class CourseMark(BaseModel):
model_config = ConfigDict(extra='forbid')

course: str
mark: Mark
mark: Mark = None

class CourseCodes(BaseModel):
model_config = ConfigDict(extra='forbid')
Expand Down
7 changes: 2 additions & 5 deletions frontend/src/components/EditMarkModal/EditMarkModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@ const EditMarkModal = ({ code, open, onCancel }: Props) => {
const updateMarkMutation = useMutation({
mutationFn: (courseMark: CourseMark) => updateCourseMark(token, courseMark),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
Expand All @@ -43,7 +40,7 @@ const EditMarkModal = ({ code, open, onCancel }: Props) => {
},
onError: (err) => {
// eslint-disable-next-line no-console
console.error('Error at unscheduleCourseMutation: ', err);
console.error('Error at updateMarkMutation:', err);
}
});

Expand All @@ -58,7 +55,7 @@ const EditMarkModal = ({ code, open, onCancel }: Props) => {
} else if (letterGrades.includes(markValue as Grade)) {
// mark is a letter grade
updateMarkMutation.mutate({ course: code, mark: markValue as Grade });
} else if (markValue === '') {
} else if (markValue === '' || markValue === undefined) {
updateMarkMutation.mutate({ course: code, mark: undefined });
} else {
message.error('Could not update mark. Please enter a valid mark or letter grade');
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/PlannerButton/PlannerButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const PlannerButton = ({ course, isAddedInPlanner }: PlannerButtonProps) => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
}
});

Expand Down
22 changes: 18 additions & 4 deletions frontend/src/pages/TermPlanner/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,31 @@ const ContextMenu = ({ code, plannedFor, ignoreFromProgression }: Props) => {
const showEditMark = () => setOpenModal(true);
const handleUnschedule = useMutation({
mutationFn: (data: UnscheduleCourse) => unscheduleCourse(token, data),
onSuccess: () =>
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['planner']
})
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
}
});
const handleDelete = useMutation({
mutationFn: (courseCode: string) => removeCourse(token, courseCode),
onSuccess: () =>
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['planner']
})
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
}
});
const handleInfo = () => {
navigate('/course-selector');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ const OptionsHeader = () => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
},
onError: (err) => {
// eslint-disable-next-line no-console
Expand Down
9 changes: 9 additions & 0 deletions frontend/src/pages/TermPlanner/TermPlanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ const TermPlanner = () => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
Expand Down Expand Up @@ -163,6 +166,9 @@ const TermPlanner = () => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
Expand Down Expand Up @@ -195,6 +201,9 @@ const TermPlanner = () => {
queryClient.invalidateQueries({
queryKey: ['planner']
});
queryClient.invalidateQueries({
queryKey: ['courses']
});
queryClient.invalidateQueries({
queryKey: ['validate']
});
Expand Down
Loading