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

Multiple plans #287

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"private": true,
"dependencies": {
"@apollo/client": "^3.3.15",
"@emotion/react": "^11.10.6",
"@emotion/styled": "^11.10.6",
"@mui/material": "^5.11.12",
"@nivo/bar": "^0.69.1",
"@nivo/core": "^0.69.0",
"@nivo/pie": "^0.69.0",
Expand Down
16 changes: 7 additions & 9 deletions site/src/pages/RoadmapPage/AddCoursePopup.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import React, { FC, ChangeEvent, useState, useEffect } from 'react';
import Form from 'react-bootstrap/Form';
import React, { FC, useState } from 'react';
import Button from 'react-bootstrap/Button';
import './AddCoursePopup.scss';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { moveCourse, setShowAddCourse, setShowSearch } from '../../store/slices/roadmapSlice';
import { ReportData } from '../../types/types';
import { useCookies } from 'react-cookie';
import Form from 'react-bootstrap/Form';
import Modal from 'react-bootstrap/Modal';
import { isMobile } from 'react-device-detect';
import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { moveCourse, setShowAddCourse } from '../../store/slices/roadmapSlice';
import './AddCoursePopup.scss';

interface AddCoursePopupProps {
}

const AddCoursePopup: FC<AddCoursePopupProps> = (props) => {
const dispatch = useAppDispatch();
const planner = useAppSelector(state => state.roadmap.yearPlans);
const showForm = useAppSelector(state => state.roadmap.showAddCourse);
const planner = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.yearPlans);
const showForm = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.showAddCourse);
const [year, setYear] = useState(-1);
const [quarter, setQuarter] = useState(-1);
const [validated, setValidated] = useState(false);
Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/RoadmapPage/Planner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const Planner: FC = () => {
const [cookies, setCookie] = useCookies(['user']);
const isFirstRenderer = useFirstRender();
const data = useAppSelector(selectYearPlans);
const transfers = useAppSelector(state => state.roadmap.transfers);
const transfers = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.transfers);

const [missingPrerequisites, setMissingPrerequisites] = useState(new Set<string>);

Expand Down
2 changes: 1 addition & 1 deletion site/src/pages/RoadmapPage/Quarter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface QuarterProps {
const Quarter: FC<QuarterProps> = ({ year, yearIndex, quarterIndex, data }) => {
const dispatch = useAppDispatch();
let quarterTitle = data.name.charAt(0).toUpperCase() + data.name.slice(1);
const invalidCourses = useAppSelector(state => state.roadmap.invalidCourses);
const invalidCourses = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.invalidCourses);

const [showQuarterMenu, setShowQuarterMenu] = useState(false);
const [target, setTarget] = useState<any>(null!);
Expand Down
6 changes: 6 additions & 0 deletions site/src/pages/RoadmapPage/RoadmapMultiplan.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.multi-plan-selector {
display: flex;
flex-direction: row;
justify-content: space-between;
height: 60px;
}
163 changes: 163 additions & 0 deletions site/src/pages/RoadmapPage/RoadmapMultiplan.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import Button from '@mui/material/Button';
import Dialog from '@mui/material/Dialog';
import DialogContent from '@mui/material/DialogContent';
import DialogTitle from '@mui/material/DialogTitle';
import FormControl from '@mui/material/FormControl';
import InputLabel from '@mui/material/InputLabel';
import MenuItem from '@mui/material/MenuItem';
import Select from '@mui/material/Select';
import TextField from '@mui/material/TextField';
import { FC, useState } from "react";
import { TextArea } from 'semantic-ui-react';
import { useAppDispatch, useAppSelector } from "src/store/hooks";
import { addRoadmapPlan, deleteRoadmapPlan, initialState, setPlanIndex, setPlanName } from "../../store/slices/roadmapSlice";
import { Box } from '@mui/material';
import Dropdown from 'react-bootstrap/esm/Dropdown';
import "./RoadmapMultiplan.scss";
import * as Icon from "react-bootstrap-icons";


const RoadmapMultiplan: FC = () => {
const dispatch = useAppDispatch();
const allPlans = useAppSelector(state => state.roadmap);
const [currentPlanIndex, setCurrentPlanIndex] = useState(allPlans.currentPlanIndex);
const [isOpen, setIsOpen] = useState(false);
const [isEdit, setIsEdit] = useState(false);
const [isDelete, setIsDelete] = useState(false);
const [newPlanName, setNewPlanName] = useState(allPlans.plans[allPlans.currentPlanIndex].name);

// name: name of the plan, content: stores the content of plan
const { name, content } = allPlans.plans[currentPlanIndex];

const addNewPlan = (name: string) => {
dispatch(addRoadmapPlan({ name: name, content: initialState }));
};

const deleteCurrentPlan = () => {
setCurrentPlanIndex(0);
dispatch(setPlanIndex(0));
dispatch(deleteRoadmapPlan({ planIndex: currentPlanIndex }));
setIsDelete(false);
};

const handleSubmitNewPlan = () => {
setIsOpen(false);
addNewPlan(newPlanName);
const newIndex = allPlans.plans.length;
setCurrentPlanIndex(newIndex);
dispatch(setPlanIndex(newIndex));
};


const modifyPlanName = () => {
setIsEdit(false);
dispatch(setPlanName({ index: allPlans.currentPlanIndex, name: newPlanName }));
};


return (
<div className="multi-plan-selector">
<Box sx={{ display: "flex", gap: 2, flexDirection: "row", alignItems: "center" }}>
<Dropdown>
<Dropdown.Toggle id="dropdown-basic">
<Icon.PenFill style={{ width: "50%", height: "50%", marginRight: 5 }} />
</Dropdown.Toggle>
<Dropdown.Menu>
<Dropdown.Item onClick={() => setIsEdit(true)}>Edit Plan Name</Dropdown.Item>
<Dropdown.Item onClick={() => setIsOpen(true)}>Add Plan</Dropdown.Item>
</Dropdown.Menu>
</Dropdown>
<FormControl variant="standard" sx={{ m: 1, minWidth: 120, marginBottom: 3 }}>
<InputLabel style={{ width: "min-content" }} id="demo-simple-select-standard-label">{name}</InputLabel>
<Select
labelId="demo-simple-select-standard-label"
id="demo-simple-select-standard"
sx={{ width: "auto" }}
value={""}
label={name}
onChange={(e) => {
let newIndex = +(e.target.value);
// console.log("selected index", newIndex);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// console.log("selected index", newIndex);

dispatch(setPlanIndex(newIndex));
setCurrentPlanIndex(newIndex);
}}
>
{
allPlans.plans.map((plan, index) => {
return <MenuItem value={index}>
{plan.name}
</MenuItem>
})
}
</Select>
<Dialog
open={isOpen}
onClose={() => setIsOpen(false)}
PaperProps={{ sx: { width: "30%", height: "20%" } }}
style={{ marginTop: 20 }}
>
<DialogTitle>New Plan</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
id="name"
label="Plan Name"
type="email"
fullWidth
variant="standard"
placeholder="plan name"
onChange={(e) => { setNewPlanName(e.target.value) }}
style={{ width: "100%" }}
/>
<Button style={{ float: "right" }} onClick={() => handleSubmitNewPlan()}>Submit</Button>
</DialogContent>
</Dialog>
<Dialog
open={isEdit}
onClose={() => setIsEdit(false)}
PaperProps={{ sx: { width: "30%", height: "20%" } }}
style={{ marginTop: 20 }}
>
<DialogTitle>Edit Plan Name</DialogTitle>
<DialogContent>
<TextField
autoFocus
margin="dense"
id="name"
label=""
type="email"
fullWidth
variant="standard"
placeholder=""
defaultValue={allPlans.plans[allPlans.currentPlanIndex].name}
onChange={(e) => { setNewPlanName(e.target.value) }}
style={{ width: "100%" }}
/>
<Button style={{ float: "right" }} onClick={() => modifyPlanName()}>Submit</Button>
</DialogContent>
</Dialog>
<Dialog
open={isDelete}
onClose={() => setIsDelete(false)}
PaperProps={{ sx: { width: "30%", height: "20%" } }}
style={{ marginTop: 20 }}
>
<DialogTitle>Delete Plan</DialogTitle>
<DialogContent>
<p>Are you sure about deleting current plan?</p>
<Box sx={{ display: "flex", flexDirection: "row", justifyContent: "flex-end" }}>
<Button onClick={() => setIsDelete(false)}>Cancel</Button>
<Button sx={{ color: "red" }} onClick={() => deleteCurrentPlan()}>Delete</Button>
</Box>
</DialogContent>
</Dialog>
</FormControl>
</Box>
<Button style={{ alignItems: "center", color: "red", marginTop: 10, height: 30 }} onClick={() => setIsDelete(true)}>Delete Plan</Button>
</div>
);
};


export default RoadmapMultiplan;
4 changes: 2 additions & 2 deletions site/src/pages/RoadmapPage/Transfer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ const TransferEntry: FC<TransferEntryProps> = (props) => {

const Transfer: FC<MissingCoursesProps> = ({ missingPrereqNames }) => {
const dispatch = useAppDispatch();
const transfers = useAppSelector(state => state.roadmap.transfers);
const show = useAppSelector(state => state.roadmap.showTransfer);
const transfers = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.transfers);
const show = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.showTransfer);
const handleClose = () => dispatch(setShowTransfer(false));

console.log("missing courses: ", missingPrereqNames);
Expand Down
4 changes: 3 additions & 1 deletion site/src/pages/RoadmapPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import { useAppDispatch, useAppSelector } from '../../store/hooks';
import { moveCourse, deleteCourse } from '../../store/slices/roadmapSlice';
import AddCoursePopup from './AddCoursePopup';
import { isMobile, isBrowser } from 'react-device-detect';
import RoadmapMultiplan from './RoadmapMultiplan';

const RoadmapPage: FC = () => {
const dispatch = useAppDispatch();
const showSearch = useAppSelector(state => state.roadmap.showSearch);
const showSearch = useAppSelector(state => state.roadmap.plans[state.roadmap.currentPlanIndex].content.showSearch);

const onDragEnd = useCallback((result: DropResult) => {
if (result.reason === 'DROP') {
Expand Down Expand Up @@ -88,6 +89,7 @@ const RoadmapPage: FC = () => {

return (
<>
<RoadmapMultiplan />
<div className='roadmap-page'>
<AddCoursePopup />
<DragDropContext onDragEnd={onDragEnd} onDragUpdate={onDragUpdate}>
Expand Down
Loading