From 1f9a11de14429238259bfad731c882b4b7271a07 Mon Sep 17 00:00:00 2001 From: Allen Nian <37233580+anian100@users.noreply.github.com> Date: Wed, 23 Sep 2020 18:07:49 +1200 Subject: [PATCH] [CPM-63] added course regulation tooltips in plan page (#80) * added course regulation tooltips in plan page * remove unused imports * added course regulation tooltips in plan page Co-authored-by: Nisarag Co-authored-by: Richard * remove unused imports * Update comment Co-authored-by: Nisarag Co-authored-by: Richard Co-authored-by: Dalton --- client/src/pages/Plan/Plan.js | 3 ++- client/src/pages/Plan/Year.js | 34 +++++++++++++++++++++++++------- client/src/pages/Plan/usePlan.js | 4 +++- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/client/src/pages/Plan/Plan.js b/client/src/pages/Plan/Plan.js index 800f6628..b0073aa1 100644 --- a/client/src/pages/Plan/Plan.js +++ b/client/src/pages/Plan/Plan.js @@ -19,6 +19,7 @@ const Plan = () => { realCourses, programme, plan: { endYear, startYear, courseAllocations }, + unfilteredRealCourses, setCourseAllocations, } = usePlan(); const [searchTerm, setSearchTerm] = useState(""); @@ -91,7 +92,7 @@ const Plan = () => { {years.map((year) => ( - + ))} diff --git a/client/src/pages/Plan/Year.js b/client/src/pages/Plan/Year.js index df1850dc..833cbf24 100644 --- a/client/src/pages/Plan/Year.js +++ b/client/src/pages/Plan/Year.js @@ -1,10 +1,11 @@ import React from "react"; -import { Flex, Stack, Text } from "@chakra-ui/core"; +import { Flex, Stack, Text, Icon } from "@chakra-ui/core"; +import ReactTooltip from "react-tooltip"; import { useDrag, useDrop } from "react-dnd"; import { ItemTypes } from "./ItemTypes"; import { colors as c } from "../../colors"; -const CourseTile = ({ courseName }) => { +const CourseTile = ({ courseName, courses }) => { const [{ isDragging }, drag] = useDrag({ item: { courseName, type: ItemTypes.COURSE_TILE }, collect: (monitor) => ({ @@ -12,6 +13,20 @@ const CourseTile = ({ courseName }) => { }), }); + const getCourseRegulations = () => { + const foundCourses = courses.find((course) => { + return course.courseCode === courseName; + }); + if (!foundCourses) return "Course not in database."; + const { prerequisites, corequisites, restrictions, informalEquivalents } = foundCourses; + const tooltipString = []; + prerequisites.length && tooltipString.push(`Prerequisites: ${prerequisites}
`); + corequisites.length && tooltipString.push(`Corequisites: ${corequisites}
`); + restrictions.length && tooltipString.push(`Restrictions: ${restrictions}
`); + informalEquivalents.length && tooltipString.push(`Informal Equivalents: ${informalEquivalents}
`); + return tooltipString.join(""); + }; + const opacity = isDragging ? 0.4 : 1; return ( @@ -20,6 +35,7 @@ const CourseTile = ({ courseName }) => { justify="center" style={{ opacity }} align="center" + flexDirection="row" borderWidth="1px" width="90%" backgroundColor={c.darkGrey} @@ -28,14 +44,18 @@ const CourseTile = ({ courseName }) => { ref={drag} cursor="pointer" > - + {courseName} + + {getCourseRegulations()} + + ); }; -const SemesterBox = ({ semester, data, year, updateData }) => { +const SemesterBox = ({ semester, data, year, updateData, courses }) => { const [{ canDrop, isOver }, drop] = useDrop({ accept: [ItemTypes.COURSE_PILL, ItemTypes.COURSE_TILE, ItemTypes.COURSE_REQUIREMENT_PILL], drop: ({ courseName }, monitor) => { @@ -80,7 +100,7 @@ const SemesterBox = ({ semester, data, year, updateData }) => { {data .filter((x) => x.semester === semester && x.year === year) .map((course, idx) => ( - + ))} @@ -88,7 +108,7 @@ const SemesterBox = ({ semester, data, year, updateData }) => { ); }; -const Year = ({ year, data, updateData }) => { +const Year = ({ year, data, updateData, courses }) => { return ( @@ -98,7 +118,7 @@ const Year = ({ year, data, updateData }) => { {["S1", "S2"].map((semester) => ( - + ))} diff --git a/client/src/pages/Plan/usePlan.js b/client/src/pages/Plan/usePlan.js index ba08ea12..18368e3d 100644 --- a/client/src/pages/Plan/usePlan.js +++ b/client/src/pages/Plan/usePlan.js @@ -52,6 +52,7 @@ const usePlan = () => { const [programme, setProgramme] = useState({ regulations }); const { planId } = useParams(); const [realCourses, setRealCourses] = useState([]); + const [unfilteredRealCourses, setUnfilteredRealCourses] = useState([]); const [plan, setPlan] = useState([]); const initPage = useCallback(async () => { @@ -66,6 +67,7 @@ const usePlan = () => { ]) .then((values) => { const [realCourses, plan, students, programs] = values; + setUnfilteredRealCourses(realCourses); const unique = [...new Set(plan.courseAllocations.map((item) => item.course))]; setRealCourses(realCourses.filter((val) => !unique.includes(val.courseCode))); setPlan(plan); @@ -91,7 +93,7 @@ const usePlan = () => { }); }; - return { student, realCourses, programme, plan, setCourseAllocations }; + return { student, realCourses, programme, plan, unfilteredRealCourses, setCourseAllocations }; }; export default usePlan;