-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…package-Selection-View #2809 Workpackage Selection View
- Loading branch information
Showing
5 changed files
with
257 additions
and
7 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
91 changes: 91 additions & 0 deletions
91
src/frontend/src/pages/HomePage/components/WorkPackageSelect.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 |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Box, Card, Typography, useTheme } from '@mui/material'; | ||
import { useEffect, useRef, useState } from 'react'; | ||
import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; | ||
|
||
interface CustomSelectProps { | ||
options: string[]; | ||
onSelect: (selectedOption: number) => void; | ||
selected?: number; | ||
} | ||
|
||
const WorkPackageSelect: React.FC<CustomSelectProps> = ({ options, onSelect, selected = 0 }) => { | ||
const theme = useTheme(); | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
const dropdownRef = useRef<HTMLDivElement>(null); | ||
|
||
const handleSelect = (option: string) => { | ||
setIsOpen(false); | ||
onSelect(options.indexOf(option)); | ||
}; | ||
|
||
const handleClickOutside = (event: MouseEvent) => { | ||
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { | ||
setIsOpen(false); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
if (isOpen) { | ||
document.addEventListener('mousedown', handleClickOutside); | ||
} else { | ||
document.removeEventListener('mousedown', handleClickOutside); | ||
} | ||
}, [isOpen]); | ||
|
||
return ( | ||
<Box ref={dropdownRef} sx={{ position: 'relative' }}> | ||
<Typography | ||
onClick={() => setIsOpen(!isOpen)} | ||
variant="h5" | ||
sx={{ paddingX: 2, paddingY: 1, display: 'inline-block', cursor: 'pointer' }} | ||
> | ||
<ExpandMoreIcon sx={{ ml: -1, paddingRight: 0.5 }} /> | ||
{options[selected]} | ||
</Typography> | ||
{isOpen && ( | ||
<Box onClick={() => setIsOpen(!isOpen)} sx={{ position: 'absolute', top: '-40%', cursor: 'pointer' }}> | ||
<Card sx={{ my: 2, background: theme.palette.background.paper }} variant="outlined"> | ||
<Typography | ||
sx={{ | ||
paddingX: 2, | ||
paddingY: 1, | ||
position: 'relative', | ||
'&:hover': { | ||
backgroundColor: theme.palette.action.hover | ||
} | ||
}} | ||
variant="h5" | ||
> | ||
{options[selected]} | ||
</Typography> | ||
{options | ||
.filter((option) => option !== options.at(selected)) | ||
.map((option) => ( | ||
<Typography | ||
key={option} | ||
onClick={() => { | ||
handleSelect(option); | ||
}} | ||
sx={{ | ||
cursor: 'pointer', | ||
paddingX: 2, | ||
paddingY: 1, | ||
backgroundColor: theme.palette.background.paper, | ||
position: 'relative', | ||
'&:hover': { | ||
backgroundColor: theme.palette.action.hover | ||
} | ||
}} | ||
variant="h5" | ||
> | ||
{option} | ||
</Typography> | ||
))} | ||
</Card> | ||
</Box> | ||
)} | ||
</Box> | ||
); | ||
}; | ||
|
||
export default WorkPackageSelect; |
129 changes: 129 additions & 0 deletions
129
src/frontend/src/pages/HomePage/components/WorkPackagesSelectionView.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 |
---|---|---|
@@ -0,0 +1,129 @@ | ||
import { WorkPackage } from 'shared'; | ||
import { Box, Card, CardContent, useTheme } from '@mui/material'; | ||
import { | ||
getInProgressWorkPackages, | ||
getOverdueWorkPackages, | ||
getUpcomingWorkPackages | ||
} from '../../../utils/work-package.utils'; | ||
import { useCurrentUser } from '../../../hooks/users.hooks'; | ||
import WorkPackageCard from './WorkPackageCard'; | ||
import WorkPackageSelect from './WorkPackageSelect'; | ||
import React, { useState } from 'react'; | ||
import EmptyPageBlockDisplay from './EmptyPageBlockDisplay'; | ||
import CheckCircleOutlineOutlinedIcon from '@mui/icons-material/CheckCircleOutlineOutlined'; | ||
|
||
const NoWorkPackages: React.FC = () => { | ||
return ( | ||
<EmptyPageBlockDisplay | ||
icon={<CheckCircleOutlineOutlinedIcon sx={{ fontSize: 70 }} />} | ||
heading={`You're all set!`} | ||
message={'You have no pending work packages of this type!'} | ||
/> | ||
); | ||
}; | ||
|
||
const WorkPackagesSelectionView: React.FC = () => { | ||
const user = useCurrentUser(); | ||
const theme = useTheme(); | ||
|
||
const teamsAsHead = user.teamsAsHead ?? []; | ||
const teamsAsLead = user.teamsAsLead ?? []; | ||
const teamsAsLeadership = [...teamsAsHead, ...teamsAsLead]; | ||
|
||
const relevantWPs = teamsAsLeadership.map((team) => team.projects.map((project) => project.workPackages)).flat(2); | ||
|
||
const upcomingWPs: WorkPackage[] = getUpcomingWorkPackages(relevantWPs); | ||
const inProgressWPs: WorkPackage[] = getInProgressWorkPackages(relevantWPs); | ||
const overdueWPs: WorkPackage[] = getOverdueWorkPackages(relevantWPs); | ||
|
||
// options for selection | ||
const workPackageOptions: [string, WorkPackage[]][] = [ | ||
[`Upcoming Work Packages (${upcomingWPs.length})`, upcomingWPs], | ||
[`In Progress Work Packages (${inProgressWPs.length})`, inProgressWPs], | ||
[`Overdue Work Packages (${overdueWPs.length})`, overdueWPs] | ||
]; | ||
|
||
let defaultFirstDisplay = 2; | ||
if (workPackageOptions[2][1].length === 0) { | ||
defaultFirstDisplay = 1; | ||
if (workPackageOptions[1][1].length === 0) { | ||
defaultFirstDisplay = 0; | ||
} | ||
} | ||
|
||
const [currentDisplayedWPs, setCurrentDisplayedWPs] = useState<number>(defaultFirstDisplay); | ||
|
||
// destructuring tuple to get wps of selected option | ||
const [, currentWps] = workPackageOptions[currentDisplayedWPs]; | ||
|
||
const WorkPackagesDisplay = (workPackages: WorkPackage[]) => ( | ||
<Box | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'row', | ||
flexWrap: 'wrap', | ||
overflow: 'auto', | ||
width: '100%', | ||
gap: 2 | ||
}} | ||
> | ||
{workPackages.map((wp) => ( | ||
<WorkPackageCard wp={wp} /> | ||
))} | ||
</Box> | ||
); | ||
|
||
return ( | ||
<Card | ||
sx={{ | ||
height: '100%', | ||
background: theme.palette.background.paper | ||
}} | ||
variant="outlined" | ||
> | ||
<CardContent | ||
sx={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
height: '100%', | ||
flexWrap: 'nowrap' | ||
}} | ||
> | ||
<WorkPackageSelect | ||
options={workPackageOptions.map((wp) => wp[0])} | ||
onSelect={setCurrentDisplayedWPs} | ||
selected={currentDisplayedWPs} | ||
/> | ||
<Box | ||
sx={{ | ||
mt: 2, | ||
display: 'flex', | ||
flex: 1, | ||
flexDirection: 'column', | ||
gap: 2, | ||
overflowX: 'hidden', | ||
overflowY: 'auto', | ||
'&::-webkit-scrollbar': { | ||
width: '20px' | ||
}, | ||
'&::-webkit-scrollbar-track': { | ||
backgroundColor: 'transparent' | ||
}, | ||
'&::-webkit-scrollbar-thumb': { | ||
backgroundColor: theme.palette.primary.main, | ||
borderRadius: '20px', | ||
border: '6px solid transparent', | ||
backgroundClip: 'content-box' | ||
}, | ||
scrollbarWidth: 'auto', | ||
scrollbarColor: `${theme.palette.primary.main} transparent` | ||
}} | ||
> | ||
{currentWps.length === 0 ? <NoWorkPackages /> : WorkPackagesDisplay(currentWps)} | ||
</Box> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; | ||
|
||
export default WorkPackagesSelectionView; |
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