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

Prerequisite unmet popup in search results #458

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
18 changes: 16 additions & 2 deletions site/src/component/SearchHitContainer/SearchHitContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { SearchIndex, CourseGQLData, ProfessorGQLData } from '../../types/types'
import SearchPagination from '../SearchPagination/SearchPagination';
import noResultsImg from '../../asset/no-results-crop.webp';
import { useFirstRender } from '../../hooks/firstRenderer';
import { validateCourse } from '../../helpers/planner';

// TODO: CourseHitItem and ProfessorHitem should not need index
// investigate: see if you can refactor respective components to use course id/ucinetid for keys instead then remove index from props
interface SearchHitContainerProps {
index: SearchIndex;
CourseHitItem: FC<CourseGQLData & { index: number }>;
CourseHitItem: FC<CourseGQLData & { index: number; requiredCourses?: string[] }>;
ProfessorHitItem?: FC<ProfessorGQLData & { index: number }>;
}

Expand All @@ -22,8 +23,21 @@ const SearchResults = ({
CourseHitItem,
ProfessorHitItem,
}: Required<SearchHitContainerProps> & { results: CourseGQLData[] | ProfessorGQLData[] }) => {
const roadmap = useAppSelector((state) => state.roadmap);
const allExistingCourses = roadmap?.plans[roadmap.currentPlanIndex].content.yearPlans.flatMap((yearPlan) =>
yearPlan.quarters.flatMap((quarter) =>
quarter.courses.map((course) => course.department + ' ' + course.courseNumber),
),
);
if (index === 'courses') {
return (results as CourseGQLData[]).map((course, i) => <CourseHitItem key={course.id} index={i} {...course} />);
return (results as CourseGQLData[]).map((course, i) => {
const requiredCourses = Array.from(
validateCourse(new Set(allExistingCourses), course.prerequisiteTree, new Set(), course.corequisites),
);
return (
<CourseHitItem key={course.id} index={i} {...course} {...(requiredCourses.length > 0 && { requiredCourses })} />
);
});
} else {
return (results as ProfessorGQLData[]).map((professor, i) => (
<ProfessorHitItem key={professor.ucinetid} index={i} {...professor} />
Expand Down
4 changes: 2 additions & 2 deletions site/src/pages/RoadmapPage/Course.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import ThemeContext from '../../style/theme-context';

interface CourseProps extends CourseGQLData {
requiredCourses?: string[];
unmatchedPrerequisites?: string[];
onDelete?: () => void;
}

Expand All @@ -29,7 +30,6 @@ const Course: FC<CourseProps> = (props) => {
terms,
onDelete,
} = props;

const CoursePopover = (
<Popover id={'course-popover-' + id}>
<Popover.Content>
Expand Down Expand Up @@ -81,7 +81,7 @@ const Course: FC<CourseProps> = (props) => {
<span className="units">, {minUnits === maxUnits ? minUnits : `${minUnits}-${maxUnits}`} units</span>
</span>
<OverlayTrigger trigger={['hover', 'focus']} placement="auto" overlay={CoursePopover} delay={100}>
<InfoCircle className="info-circle" />
<InfoCircle />
</OverlayTrigger>
{requiredCourses && (
<OverlayTrigger trigger={['hover', 'focus']} placement="right" overlay={WarningPopover} delay={100}>
Expand Down
Loading