From b8027c7bf5449d32e226d6e1a68ca48581ae5524 Mon Sep 17 00:00:00 2001 From: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> Date: Thu, 4 Nov 2021 16:03:33 -0700 Subject: [PATCH] Make Dashboard reactive in xs and sm to full screen (#1189) * Make Dashboard reactive in xs and sm to full screen Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> * Dynamic Widgets Signed-off-by: Daniel Valdivia <18384552+dvaldivia@users.noreply.github.com> --- .../Dashboard/Prometheus/PrDashboard.tsx | 28 ++++++++++--- .../Prometheus/Widgets/BarChartWidget.tsx | 11 +++-- .../Prometheus/Widgets/LinearGraphWidget.tsx | 40 +++++++++++-------- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx b/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx index 97f7b2a25..45f6e3d4b 100644 --- a/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx +++ b/portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx @@ -21,7 +21,7 @@ import Grid from "@mui/material/Grid"; import { Theme } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; import withStyles from "@mui/styles/withStyles"; -import { GridSize } from "@mui/material"; +import { GridSize, useMediaQuery } from "@mui/material"; import { actionsTray, widgetContainerCommon, @@ -39,6 +39,7 @@ import { componentToUse } from "./widgetUtils"; import ZoomWidget from "./ZoomWidget"; import { AppState } from "../../../../store"; import DateRangeSelector from "../../Common/FormComponents/DateRangeSelector/DateRangeSelector"; +import { useTheme } from "@mui/styles"; interface IPrDashboard { classes: any; @@ -92,6 +93,9 @@ const PrDashboard = ({ useState(panelsConfiguration); const [curTab, setCurTab] = useState(0); + const theme = useTheme(); + const biggerThanMd = useMediaQuery(theme.breakpoints.up("md")); + const panels = useCallback( (tabName: string, filterPanels?: number[][] | null) => { return filterPanels?.map((panelLine, indexLine) => { @@ -99,6 +103,12 @@ const PrDashboard = ({ let perc = Math.floor(12 / totalPanelsContained); + if (!biggerThanMd && totalPanelsContained >= 4) { + perc = 6; + } else if (!biggerThanMd && totalPanelsContained >= 3) { + perc = 12; + } + if (perc < 1) { perc = 1; } else if (perc > 12) { @@ -122,9 +132,9 @@ const PrDashboard = ({ key={`widget-${panelInline}-${indexPanel}`} className={classes.widgetPanelDelimiter} item - xs={7} - sm={8} - md={6} + xs={12} + sm={perc as GridSize} + md={perc as GridSize} lg={perc as GridSize} > @@ -177,6 +187,7 @@ const PrDashboard = ({ classes.dashboardRow, classes.widgetPanelDelimiter, panelInformation, + biggerThanMd, ] ); @@ -231,11 +242,18 @@ const PrDashboard = ({ const summaryPanels = [ [66, 44, 500, 501], - [50, 502], [80, 81, 1], [68, 52], [63, 70], ]; + + if (biggerThanMd) { + summaryPanels.splice(1, 0, [50, 502]); + } else { + summaryPanels.splice(1, 0, [50]); + summaryPanels.splice(1, 0, [502]); + } + const resourcesPanels = [ [76, 77], [11, 8], diff --git a/portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/BarChartWidget.tsx b/portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/BarChartWidget.tsx index 3d1cd0569..743670e12 100644 --- a/portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/BarChartWidget.tsx +++ b/portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/BarChartWidget.tsx @@ -14,18 +14,18 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -import React, { useEffect, useState, Fragment } from "react"; +import React, { Fragment, useEffect, useState } from "react"; import { connect } from "react-redux"; import { Bar, BarChart, + Cell, ResponsiveContainer, Tooltip, XAxis, YAxis, - Cell, } from "recharts"; -import { CircularProgress } from "@mui/material"; +import { CircularProgress, useMediaQuery } from "@mui/material"; import { Theme } from "@mui/material/styles"; import createStyles from "@mui/styles/createStyles"; import withStyles from "@mui/styles/withStyles"; @@ -39,6 +39,7 @@ import { widgetDetailsToPanel } from "../utils"; import { ErrorResponseHandler } from "../../../../../common/types"; import api from "../../../../../common/api"; import { openZoomPage } from "../../actions"; +import { useTheme } from "@mui/styles"; interface IBarChartWidget { classes: any; @@ -153,6 +154,9 @@ const BarChartWidget = ({ }); } + const theme = useTheme(); + const biggerThanMd = useMediaQuery(theme.breakpoints.up("md")); + return (
{!zoomActivated && ( @@ -194,6 +198,7 @@ const BarChartWidget = ({ tickLine={false} axisLine={false} width={150} + hide={!biggerThanMd} /> {barChartConfiguration.map((bar) => ( ; }; + const theme = useTheme(); + const biggerThanMd = useMediaQuery(theme.breakpoints.up("md")); + return (
{!zoomActivated && ( @@ -305,24 +309,26 @@ const LinearGraphWidget = ({
)} -
- {linearConfiguration.map((section, index) => { - return ( -
+ {biggerThanMd && ( +
+ {linearConfiguration.map((section, index) => { + return (
-
- {section.keyLabel} + className={classes.singleLegendContainer} + key={`legend-${section.keyLabel}-${index.toString()}`} + > +
+
+ {section.keyLabel} +
-
- ); - })} -
+ ); + })} +
+ )} )}