forked from OpenStackweb/summit-admin
-
Notifications
You must be signed in to change notification settings - Fork 4
feat: move show dashboard to mui #967
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
Open
priscila-moneo
wants to merge
3
commits into
master
Choose a base branch
from
feature/move-show-dashboard-mui
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,40 @@ | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import Box from "@mui/material/Box"; | ||
| import Card from "@mui/material/Card"; | ||
| import CardHeader from "@mui/material/CardHeader"; | ||
| import Divider from "@mui/material/Divider"; | ||
| import Typography from "@mui/material/Typography"; | ||
|
|
||
| function DashboardSection({ title, children, variant }) { | ||
| if (variant === "card") { | ||
| return ( | ||
| <Card elevation={0}> | ||
| <CardHeader title={title} /> | ||
| <Divider /> | ||
| {children} | ||
| </Card> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <Box> | ||
| <Box sx={{ bgcolor: "background.light_gray", px: 2, py: 2 }}> | ||
| <Typography variant="body2">{title}</Typography> | ||
| </Box> | ||
| {children} | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| DashboardSection.propTypes = { | ||
| title: PropTypes.string.isRequired, | ||
| children: PropTypes.node.isRequired, | ||
| variant: PropTypes.oneOf(["card"]) | ||
| }; | ||
|
|
||
| DashboardSection.defaultProps = { | ||
| variant: undefined | ||
| }; | ||
|
|
||
| export default DashboardSection; | ||
This file contains hidden or 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,46 @@ | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import Divider from "@mui/material/Divider"; | ||
| import Grid2 from "@mui/material/Grid2"; | ||
| import DashboardSection from "./dashboard-section"; | ||
| import SummitDashboardStat from "./summit-dashboard-stat"; | ||
|
|
||
| const GRID_COLUMNS = 12; | ||
|
|
||
| function DashboardStatSection({ title, rows }) { | ||
| return ( | ||
| <DashboardSection title={title} variant="card"> | ||
| {rows.map((group, i) => { | ||
| if (!group.length) return null; | ||
| const size = Math.floor(GRID_COLUMNS / group.length); | ||
| const key = group[0]?.title ?? `group-${i}`; | ||
| return ( | ||
| <React.Fragment key={key}> | ||
| {i > 0 && <Divider />} | ||
| <Grid2 container> | ||
| {group.map(({ title: label, stat: value }) => ( | ||
| <Grid2 key={label} size={size}> | ||
| <SummitDashboardStat label={label} value={value} /> | ||
| </Grid2> | ||
| ))} | ||
| </Grid2> | ||
| </React.Fragment> | ||
| ); | ||
| })} | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| </DashboardSection> | ||
| ); | ||
| } | ||
|
|
||
| DashboardStatSection.propTypes = { | ||
| title: PropTypes.string.isRequired, | ||
| rows: PropTypes.arrayOf( | ||
| PropTypes.arrayOf( | ||
| PropTypes.shape({ | ||
| title: PropTypes.string.isRequired, | ||
| stat: PropTypes.number | ||
| }) | ||
| ) | ||
| ).isRequired | ||
| }; | ||
|
|
||
| export default DashboardStatSection; | ||
50 changes: 50 additions & 0 deletions
50
src/pages/summits/components/summit-dashboard-date-range.js
This file contains hidden or 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,50 @@ | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import Box from "@mui/material/Box"; | ||
| import Typography from "@mui/material/Typography"; | ||
| import RemoveIcon from "@mui/icons-material/Remove"; | ||
| import { formatDate } from "../../../utils/methods"; | ||
| import { DATETIME_FORMAT } from "../../../utils/constants"; | ||
|
|
||
| function SummitDashboardDateRange({ label, startTs, endTs, tzName }) { | ||
| if (!startTs || !endTs) return null; | ||
|
|
||
| return ( | ||
| <Box | ||
| sx={{ | ||
| display: "flex", | ||
| alignItems: "center", | ||
| height: 75, | ||
| px: 2, | ||
| borderBottom: 1, | ||
| borderColor: "divider" | ||
| }} | ||
| > | ||
| <Box sx={{ minWidth: 120 }}> | ||
| <Typography variant="body2">{label}</Typography> | ||
| </Box> | ||
| <Typography variant="body1"> | ||
| {formatDate(startTs, tzName, DATETIME_FORMAT)} | ||
| </Typography> | ||
| <RemoveIcon sx={{ mx: 2, fontSize: 16 }} /> | ||
| <Typography variant="body1"> | ||
| {formatDate(endTs, tzName, DATETIME_FORMAT)} | ||
| </Typography> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| SummitDashboardDateRange.propTypes = { | ||
| label: PropTypes.string.isRequired, | ||
| startTs: PropTypes.number, | ||
| endTs: PropTypes.number, | ||
| tzName: PropTypes.string | ||
| }; | ||
|
|
||
| SummitDashboardDateRange.defaultProps = { | ||
| startTs: null, | ||
| endTs: null, | ||
| tzName: undefined | ||
| }; | ||
|
|
||
| export default SummitDashboardDateRange; |
This file contains hidden or 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,26 @@ | ||
| import React from "react"; | ||
| import PropTypes from "prop-types"; | ||
| import Box from "@mui/material/Box"; | ||
| import Typography from "@mui/material/Typography"; | ||
|
|
||
| function SummitDashboardStat({ label, value }) { | ||
| return ( | ||
| <Box sx={{ p: 2 }}> | ||
| <Typography variant="body2" color="text.secondary" gutterBottom> | ||
| {label} | ||
| </Typography> | ||
| <Typography variant="h3">{value}</Typography> | ||
| </Box> | ||
| ); | ||
| } | ||
|
|
||
| SummitDashboardStat.propTypes = { | ||
| label: PropTypes.string.isRequired, | ||
| value: PropTypes.number | ||
| }; | ||
|
|
||
| SummitDashboardStat.defaultProps = { | ||
| value: 0 | ||
| }; | ||
|
|
||
| export default SummitDashboardStat; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix PropTypes inconsistency for
variant.Line 33 restricts
varianttooneOf(["card"]), but Line 37 defaults it toundefined. This creates a PropTypes validation warning sinceundefinedis not in the allowed values. The component logic (Line 10) correctly handlesundefinedby rendering the non-card variant.🐛 Proposed fix
Option 1: Remove the
oneOfrestriction if only "card" is needed as an explicit signal:DashboardSection.propTypes = { title: PropTypes.string.isRequired, children: PropTypes.node.isRequired, - variant: PropTypes.oneOf(["card"]) + variant: PropTypes.string };Option 2: Make the PropTypes match the runtime behavior by allowing both "card" and undefined:
DashboardSection.propTypes = { title: PropTypes.string.isRequired, children: PropTypes.node.isRequired, - variant: PropTypes.oneOf(["card"]) + variant: PropTypes.oneOf(["card", undefined]) };📝 Committable suggestion
🤖 Prompt for AI Agents