forked from pennlabs/penn-courses
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from pennlabs/aag/req-panel
Link backend and requirements panel + fix drag/drop v0
- Loading branch information
Showing
13 changed files
with
272 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 18 additions & 6 deletions
24
frontend/degree-plan/components/FourYearPlan/CoursesPlanned.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 85 additions & 43 deletions
128
frontend/degree-plan/components/Requirements/ReqPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,99 @@ | ||
import Icon from '@mdi/react'; | ||
import { mdiNoteEditOutline, mdiArrowLeft, mdiPlus } from '@mdi/js'; | ||
import { useEffect, useState } from 'react'; | ||
import { PanelTopBar } from '@/pages/FourYearPlanPage'; | ||
import SelectListDropdown from '../FourYearPlan/SelectListDropdown'; | ||
import SwitchFromList from '../FourYearPlan/SwitchFromList'; | ||
import Requirement from './Requirement'; | ||
import axios from 'axios'; | ||
import Rule from './Requirement'; | ||
import { Degree, DegreePlan } from '@/types'; | ||
import styled from '@emotion/styled'; | ||
import { PanelBody, PanelContainer, PanelHeader } from '@/components/FourYearPlan/PlanPanel' | ||
import { useSWRCrud } from '@/hooks/swrcrud'; | ||
import { set, update } from 'lodash'; | ||
import { useSWRConfig } from 'swr'; | ||
|
||
const requirementDropdownListStyle = { | ||
maxHeight: '90%', | ||
width: '100%', | ||
overflowY: 'scroll', | ||
overflowY: 'auto', | ||
paddingRight: '15px', | ||
paddingLeft: '15px', | ||
marginTop: '10px' | ||
} | ||
|
||
const ReqPanel = ({majors, currentMajor, highlightReqId, setCurrentMajor, setMajors, setSearchClosed, setDegreeModalOpen, handleSearch, setHighlightReqId}:any) => { | ||
const [editMode, setEditMode] = useState(false); | ||
const [majorData, setMajorData] = useState({}); | ||
|
||
useEffect(() => { | ||
const getMajor = async () => { | ||
// const res = await axios.get(`/degree/degrees/${currentMajor.id}`); | ||
// console.log(res.data); | ||
// setMajorData(res.data); | ||
// return; | ||
} | ||
if (currentMajor.id) getMajor(); | ||
}, [currentMajor]) | ||
const EmptyPanelContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
padding: 2rem; | ||
text-align: center; | ||
`; | ||
|
||
const EmptyPanelImage = styled.img` | ||
max-width: min(60%, 40vw); | ||
`; | ||
|
||
const EmptyPanel = () => { | ||
return ( | ||
<EmptyPanelContainer> | ||
<EmptyPanelImage src="/images/empty-state-cal.svg" /> | ||
There's nothing here so far... add a degree to get started! | ||
</EmptyPanelContainer> | ||
) | ||
} | ||
|
||
interface ReqPanelProps { | ||
activeDegreePlan: DegreePlan | null; | ||
isLoading: boolean; | ||
} | ||
const ReqPanel = ({activeDegreePlan, isLoading, highlightReqId, setSearchClosed, handleSearch, setHighlightReqId}: ReqPanelProps) => { | ||
const degrees = activeDegreePlan?.degrees; | ||
const [activeDegreeId, setActiveDegreeId] = useState<Degree["id"] | undefined>(undefined); | ||
const [activeDegree, setActiveDegree] = useState<Degree | undefined>(undefined); | ||
useEffect(() => { | ||
if (!activeDegreeId && degrees?.length) { | ||
setActiveDegreeId(degrees[0].id); | ||
} | ||
}, [activeDegreeId, activeDegreePlan]) | ||
|
||
useEffect(() => { | ||
if (activeDegreeId && degrees) { | ||
setActiveDegree(degrees.find(degree => degree.id === activeDegreeId)); | ||
} | ||
}) | ||
|
||
return( | ||
<> | ||
<PanelTopBar> | ||
<SelectListDropdown | ||
allItems={[]} | ||
active={undefined} | ||
selectItem={setCurrentMajor} | ||
itemType={"major or degree"} | ||
mutators={{ | ||
copy: () => {}, | ||
remove: () => {}, | ||
rename: () => {}, | ||
create: () => {} | ||
}} | ||
/> | ||
</PanelTopBar> | ||
<div style={requirementDropdownListStyle}> | ||
{majorData && majorData.rules && majorData.rules.map((requirement: any) => ( | ||
<Requirement requirement={requirement} setSearchClosed={setSearchClosed} parent={null} handleSearch={handleSearch} setHighlightReqId={setHighlightReqId} highlightReqId={highlightReqId} key={requirement.id}/> | ||
))} | ||
</div> | ||
</> | ||
); | ||
const { update: updateDegreeplan } = useSWRCrud<DegreePlan>('/api/degree/degreeplans/'); | ||
|
||
return( | ||
<PanelContainer> | ||
<PanelHeader> | ||
<SelectListDropdown | ||
allItems={degrees || []} | ||
active={activeDegree} | ||
selectItem={(id: Degree["id"]) => setActiveDegreeId(id)} | ||
getItemName={(degree: Degree) => `${degree.major}, ${degree.degree}`} | ||
itemType={"major or degree"} | ||
mutators={{ | ||
remove: (degree) => { | ||
updateDegreeplan( | ||
{degree_ids: activeDegreePlan?.degree_ids?.filter(id => id !== degree.id) || []}, | ||
activeDegreePlan?.id | ||
) | ||
if (degree.id === activeDegreeId) setActiveDegreeId(undefined); | ||
}, | ||
create: () => updateDegreeplan( | ||
{degree_ids: [...(activeDegreePlan?.degree_ids || []), 1867]}, // TODO: this is a placeholder, we need to add a new degree | ||
activeDegreePlan?.id | ||
)?.then(() => setActiveDegreeId(1867)), | ||
}} | ||
/> | ||
</PanelHeader> | ||
<PanelBody> | ||
{activeDegree?.rules?.map((rule: any) => ( | ||
<Rule rule={rule} setSearchClosed={setSearchClosed} handleSearch={handleSearch} setHighlightReqId={setHighlightReqId} highlightReqId={highlightReqId} key={rule.id}/> | ||
)) | ||
|| <EmptyPanel /> | ||
} | ||
</PanelBody> | ||
</PanelContainer> | ||
); | ||
} | ||
export default ReqPanel; |
Oops, something went wrong.