generated from ctc-uci/npo-frontend-vite-template
-
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.
* base starter for statistic modal and table * fit modal to content size and remove comments * Revert "fit modal to content size and remove comments" This reverts commit 6e421f2. * fixed rev change * base css for StatTable * Season defaults to current one from published-schedule when opening stats modal * pass in allseasons prop ps->pstable->statModal->statTable to dynamically render all available seasons and years in the select dropdowns * style fixes * changed double dropdown to single dropdown, visibility issue * fixed select display bug --------- Co-authored-by: subinqkim <[email protected]> Co-authored-by: ThatMegamind <[email protected]> Co-authored-by: michellelin1 <[email protected]>
- Loading branch information
1 parent
9e801b7
commit 1cc3095
Showing
5 changed files
with
220 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
.container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.select-container { | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
display: flex; | ||
justify-content: center; | ||
} | ||
|
||
.table-container { | ||
margin-top: 20px; | ||
margin-bottom: 20px; | ||
border: 1px solid #e1e4e8; | ||
border-radius: 8px; | ||
overflow: hidden; | ||
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
.table-container th { | ||
background-color: #0e509c; | ||
color: white; | ||
padding: 15px; | ||
text-align: center; | ||
} | ||
|
||
.table-container tbody td { | ||
border-bottom: 1px solid #e1e4e8; | ||
padding: 15px; | ||
text-align: center; | ||
} | ||
|
||
.table-container tbody tr:last-child td:not(:first-child) { | ||
background-color: #f0f8ff; | ||
color: blue; | ||
} | ||
|
||
.table-container tbody tr:not(:last-child) td:last-child { | ||
background-color: #f0f8ff; | ||
color: blue; | ||
} | ||
|
||
.table-container tbody tr:last-child td:last-child { | ||
border: none; | ||
} | ||
|
||
.table-body tr:nth-child(even) { | ||
background-color: #f8f9fa; | ||
} | ||
|
||
.table-body tr:hover { | ||
background-color: #e2f3ff; | ||
transition: background-color 0.3s ease; | ||
} |
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,100 @@ | ||
import { useState, useEffect } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { NPOBackend } from '../../utils/auth_utils'; | ||
import { Box, Select } from '@chakra-ui/react'; | ||
import './StatTable.css'; | ||
|
||
const StatTable = ({ season, allSeasons }) => { | ||
const [stats, setStats] = useState([]); | ||
const [selectedSeason, setSelectedSeason] = useState(season); | ||
|
||
useEffect(() => { | ||
const fetchStats = async () => { | ||
try { | ||
const curSeason = selectedSeason.split(' ')[0]; | ||
const curYear = selectedSeason.split(' ')[1]; | ||
const response = await NPOBackend.get(`/published-schedule/stats?season=${curSeason.toLowerCase()}&year=${curYear}`); | ||
const data = response.data; | ||
setStats(data); | ||
} catch (error) { | ||
console.error('Error fetching statistics:', error); | ||
} | ||
}; | ||
|
||
fetchStats(); | ||
}, [selectedSeason]); | ||
|
||
const transformData = () => { | ||
const transformedData = {}; | ||
|
||
stats.forEach(stat => { | ||
const eventType = stat.eventType; | ||
const subject = stat.subject; | ||
const totalCount = parseInt(stat.totalCount); | ||
|
||
if (!transformedData[eventType]) { | ||
transformedData[eventType] = {}; | ||
} | ||
|
||
transformedData[eventType][subject] = totalCount; | ||
}); | ||
|
||
return transformedData; | ||
}; | ||
|
||
const transformedStats = transformData(); | ||
|
||
return ( | ||
<Box> | ||
<Box mt="1rem"> | ||
<Select | ||
textColor="black" | ||
value={selectedSeason} | ||
onChange={(e) => setSelectedSeason(e.target.value)} | ||
width="max-content" | ||
> | ||
{allSeasons.map(item => ( | ||
<option key={item} value={item}> | ||
{item} | ||
</option> | ||
)) | ||
} | ||
</Select> | ||
</Box> | ||
<div className='table-container'> | ||
<table> | ||
<thead> | ||
<tr> | ||
<th>Event Type</th> | ||
{Object.keys(transformedStats).length > 0 && | ||
Object.keys(transformedStats[Object.keys(transformedStats)[0]]).map(subject => ( | ||
<th key={subject} style={{ textTransform: 'capitalize' }}>{subject}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody className='table-body'> | ||
{Object.keys(transformedStats).map((eventType) => ( | ||
<React.Fragment key={eventType}> | ||
<tr className='table-data'> | ||
<td style={{ textTransform: 'capitalize' }}>{eventType}</td> | ||
{Object.keys(transformedStats[eventType]).map(subject => ( | ||
<td key={`${eventType}-${subject}`} >{transformedStats[eventType][subject]}</td> | ||
))} | ||
</tr> | ||
</React.Fragment> | ||
))} | ||
</tbody> | ||
</table> | ||
</div> | ||
</Box> | ||
); | ||
}; | ||
|
||
StatTable.propTypes = { | ||
season: PropTypes.string, | ||
year: PropTypes.string, | ||
allSeasons: PropTypes.array, | ||
}; | ||
|
||
export default StatTable; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import PropTypes from 'prop-types'; | ||
import { | ||
Modal, | ||
ModalOverlay, | ||
ModalContent, | ||
ModalBody, | ||
ModalCloseButton, | ||
} from '@chakra-ui/react'; | ||
import StatTable from '../../components/StatTable/StatTable'; | ||
|
||
const StatModal = ({ isOpen, onClose, season, allSeasons }) => { | ||
return ( | ||
<> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent maxWidth={'fit-content'}> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<StatTable season={season} allSeasons={allSeasons}/> | ||
</ModalBody> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
StatModal.propTypes = { | ||
isOpen: PropTypes.bool.isRequired, | ||
onClose: PropTypes.func.isRequired, | ||
season: PropTypes.string.isRequired, | ||
allSeasons: PropTypes.array.isRequired, | ||
}; | ||
|
||
export default StatModal; |