Repository: icssc/AntAlmanac
Pull request #711 (2023-09-29 03:04:43)

Fix Added Pane Course Grouping
## Summary
<img width="548" alt="Screenshot 2023-09-28 at 8 04 25 PM" src="https://github.com/icssc/AntAlmanac/assets/100006999/6a7b486a-701f-4d64-85c0-93cf63c8cfff">

This piece of filtering was too general for the courses that shared the same courseNumber and deptCode (EECS 298, BIO SCI 199, etc). Because they all have different course titles, however, the fix is simply to narrow down the filter even more with `.courseTitle`.

Old Code ->
```typescript
        let formattedCourse = formattedCourses.find(
            (needleCourse) =>
                needleCourse.courseNumber === course.courseNumber && needleCourse.deptCode === course.deptCode
```

## Test Plan
Make sure courses like BIO SCI 199 are properly grouped, as well as that no other functionality has been broken.

## Issues
Closes #

<!-- [Optional]
## Future Followup
-->


github-actions[bot]: Deployed staging instance to https://staging-711.antalmanac.com
<!-- Sticky Pull Request Commentstaging url -->

Patch:
diff --git a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
index facdb8b1..0981b0d8 100644
--- a/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
+++ b/apps/antalmanac/src/components/RightPane/AddedCourses/AddedCoursePane.tsx
@@ -54,7 +54,9 @@ function getCourses() {
     for (const course of currentCourses) {
         let formattedCourse = formattedCourses.find(
             (needleCourse) =>
-                needleCourse.courseNumber === course.courseNumber && needleCourse.deptCode === course.deptCode
+                needleCourse.courseNumber === course.courseNumber &&
+                needleCourse.deptCode === course.deptCode &&
+                needleCourse.courseTitle === course.courseTitle
         );
 
         if (formattedCourse) {
@@ -306,7 +308,7 @@ function AddedSectionsGrid() {
                 <Grid container spacing={2} padding={0}>
                     {courses.map((course) => {
                         return (
-                            <Grid item md={12} xs={12} key={course.deptCode + course.courseNumber}>
+                            <Grid item md={12} xs={12} key={course.deptCode + course.courseNumber + course.courseTitle}>
                                 <SectionTableLazyWrapper
                                     courseDetails={course}
                                     term={course.term}
diff --git a/apps/antalmanac/src/components/dialogs/RenameSchedule.tsx b/apps/antalmanac/src/components/dialogs/RenameSchedule.tsx
index 50f76183..8ee66fc0 100644
--- a/apps/antalmanac/src/components/dialogs/RenameSchedule.tsx
+++ b/apps/antalmanac/src/components/dialogs/RenameSchedule.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useState, useEffect } from 'react';
+import { useCallback, useState, useEffect, useMemo } from 'react';
 import {
     Box,
     Button,
@@ -39,6 +39,10 @@ function RenameScheduleDialog(props: ScheduleNameDialogProps) {
 
     const [name, setName] = useState(scheduleNames[index]);
 
+    const disabled = useMemo(() => {
+        return name?.trim() === '';
+    }, [name]);
+
     const handleCancel = useCallback(() => {
         onClose?.({}, 'escapeKeyDown');
         setName(scheduleNames[index]);
@@ -93,10 +97,10 @@ function RenameScheduleDialog(props: ScheduleNameDialogProps) {
             </DialogContent>
 
             <DialogActions>
-                <Button onClick={handleCancel} color={isDarkMode() ? 'secondary' : 'primary'}>
+                <Button onClick={handleCancel} color={'inherit'}>
                     Cancel
                 </Button>
-                <Button onClick={submitName} variant="contained" color="primary" disabled={name.trim() === ''}>
+                <Button onClick={submitName} variant="contained" color="primary" disabled={disabled}>
                     Rename Schedule
                 </Button>
             </DialogActions>


Test patch:
diff --git a/apps/antalmanac/tests/schedule.test.ts b/apps/antalmanac/tests/schedule.test.ts
deleted file mode 100644
index 09894443..00000000
--- a/apps/antalmanac/tests/schedule.test.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import { describe, test, expect } from 'vitest';
-import { Schedules } from '../src/stores/Schedules';
-
-describe('schedule logic', () => {
-    const scheduleStore = new Schedules();
-
-    test('no error when loading undefined schedule', () => {
-        expect(() => scheduleStore.getScheduleName(69)).not.toThrowError();
-    });
-});
diff --git a/apps/antalmanac/tests/schedule.test.tsx b/apps/antalmanac/tests/schedule.test.tsx
new file mode 100644
index 00000000..41e4d890
--- /dev/null
+++ b/apps/antalmanac/tests/schedule.test.tsx
@@ -0,0 +1,16 @@
+import { describe, test, expect } from 'vitest';
+import { render } from '@testing-library/react';
+import { Schedules } from '$stores/Schedules';
+import RenameScheduleDialog from '$components/dialogs/RenameSchedule';
+
+describe('schedule logic', () => {
+    const scheduleStore = new Schedules();
+
+    test('no error when loading undefined schedule', () => {
+        expect(() => scheduleStore.getScheduleName(100)).not.toThrowError();
+    });
+
+    test('does not error if schedule name is undefined', () => {
+        expect(() => render(<RenameScheduleDialog index={100} open />)).not.toThrowError();
+    });
+});