Skip to content

Commit b8027c7

Browse files
authored
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>
1 parent 9b06748 commit b8027c7

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

portal-ui/src/screens/Console/Dashboard/Prometheus/PrDashboard.tsx

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import Grid from "@mui/material/Grid";
2121
import { Theme } from "@mui/material/styles";
2222
import createStyles from "@mui/styles/createStyles";
2323
import withStyles from "@mui/styles/withStyles";
24-
import { GridSize } from "@mui/material";
24+
import { GridSize, useMediaQuery } from "@mui/material";
2525
import {
2626
actionsTray,
2727
widgetContainerCommon,
@@ -39,6 +39,7 @@ import { componentToUse } from "./widgetUtils";
3939
import ZoomWidget from "./ZoomWidget";
4040
import { AppState } from "../../../../store";
4141
import DateRangeSelector from "../../Common/FormComponents/DateRangeSelector/DateRangeSelector";
42+
import { useTheme } from "@mui/styles";
4243

4344
interface IPrDashboard {
4445
classes: any;
@@ -92,13 +93,22 @@ const PrDashboard = ({
9293
useState<IDashboardPanel[]>(panelsConfiguration);
9394
const [curTab, setCurTab] = useState<number>(0);
9495

96+
const theme = useTheme();
97+
const biggerThanMd = useMediaQuery(theme.breakpoints.up("md"));
98+
9599
const panels = useCallback(
96100
(tabName: string, filterPanels?: number[][] | null) => {
97101
return filterPanels?.map((panelLine, indexLine) => {
98102
const totalPanelsContained = panelLine.length;
99103

100104
let perc = Math.floor(12 / totalPanelsContained);
101105

106+
if (!biggerThanMd && totalPanelsContained >= 4) {
107+
perc = 6;
108+
} else if (!biggerThanMd && totalPanelsContained >= 3) {
109+
perc = 12;
110+
}
111+
102112
if (perc < 1) {
103113
perc = 1;
104114
} else if (perc > 12) {
@@ -122,9 +132,9 @@ const PrDashboard = ({
122132
key={`widget-${panelInline}-${indexPanel}`}
123133
className={classes.widgetPanelDelimiter}
124134
item
125-
xs={7}
126-
sm={8}
127-
md={6}
135+
xs={12}
136+
sm={perc as GridSize}
137+
md={perc as GridSize}
128138
lg={perc as GridSize}
129139
>
130140
<Grid item xs={12}>
@@ -177,6 +187,7 @@ const PrDashboard = ({
177187
classes.dashboardRow,
178188
classes.widgetPanelDelimiter,
179189
panelInformation,
190+
biggerThanMd,
180191
]
181192
);
182193

@@ -231,11 +242,18 @@ const PrDashboard = ({
231242

232243
const summaryPanels = [
233244
[66, 44, 500, 501],
234-
[50, 502],
235245
[80, 81, 1],
236246
[68, 52],
237247
[63, 70],
238248
];
249+
250+
if (biggerThanMd) {
251+
summaryPanels.splice(1, 0, [50, 502]);
252+
} else {
253+
summaryPanels.splice(1, 0, [50]);
254+
summaryPanels.splice(1, 0, [502]);
255+
}
256+
239257
const resourcesPanels = [
240258
[76, 77],
241259
[11, 8],

portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/BarChartWidget.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17-
import React, { useEffect, useState, Fragment } from "react";
17+
import React, { Fragment, useEffect, useState } from "react";
1818
import { connect } from "react-redux";
1919
import {
2020
Bar,
2121
BarChart,
22+
Cell,
2223
ResponsiveContainer,
2324
Tooltip,
2425
XAxis,
2526
YAxis,
26-
Cell,
2727
} from "recharts";
28-
import { CircularProgress } from "@mui/material";
28+
import { CircularProgress, useMediaQuery } from "@mui/material";
2929
import { Theme } from "@mui/material/styles";
3030
import createStyles from "@mui/styles/createStyles";
3131
import withStyles from "@mui/styles/withStyles";
@@ -39,6 +39,7 @@ import { widgetDetailsToPanel } from "../utils";
3939
import { ErrorResponseHandler } from "../../../../../common/types";
4040
import api from "../../../../../common/api";
4141
import { openZoomPage } from "../../actions";
42+
import { useTheme } from "@mui/styles";
4243

4344
interface IBarChartWidget {
4445
classes: any;
@@ -153,6 +154,9 @@ const BarChartWidget = ({
153154
});
154155
}
155156

157+
const theme = useTheme();
158+
const biggerThanMd = useMediaQuery(theme.breakpoints.up("md"));
159+
156160
return (
157161
<div className={zoomActivated ? "" : classes.singleValueContainer}>
158162
{!zoomActivated && (
@@ -194,6 +198,7 @@ const BarChartWidget = ({
194198
tickLine={false}
195199
axisLine={false}
196200
width={150}
201+
hide={!biggerThanMd}
197202
/>
198203
{barChartConfiguration.map((bar) => (
199204
<Bar

portal-ui/src/screens/Console/Dashboard/Prometheus/Widgets/LinearGraphWidget.tsx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
XAxis,
2626
YAxis,
2727
} from "recharts";
28-
import { CircularProgress } from "@mui/material";
28+
import { CircularProgress, useMediaQuery } from "@mui/material";
2929
import { Theme } from "@mui/material/styles";
3030
import createStyles from "@mui/styles/createStyles";
3131
import withStyles from "@mui/styles/withStyles";
@@ -39,6 +39,7 @@ import { ErrorResponseHandler } from "../../../../../common/types";
3939
import api from "../../../../../common/api";
4040
import LineChartTooltip from "./tooltips/LineChartTooltip";
4141
import { openZoomPage } from "../../actions";
42+
import { useTheme } from "@mui/styles";
4243

4344
interface ILinearGraphWidget {
4445
classes: any;
@@ -183,6 +184,9 @@ const LinearGraphWidget = ({
183184
return <circle cx={cx} cy={cy} r={3} strokeWidth={0} fill="#07264A" />;
184185
};
185186

187+
const theme = useTheme();
188+
const biggerThanMd = useMediaQuery(theme.breakpoints.up("md"));
189+
186190
return (
187191
<div className={zoomActivated ? "" : classes.singleValueContainer}>
188192
{!zoomActivated && (
@@ -305,24 +309,26 @@ const LinearGraphWidget = ({
305309
<br />
306310
</Fragment>
307311
)}
308-
<div className={classes.legendChart}>
309-
{linearConfiguration.map((section, index) => {
310-
return (
311-
<div
312-
className={classes.singleLegendContainer}
313-
key={`legend-${section.keyLabel}-${index.toString()}`}
314-
>
312+
{biggerThanMd && (
313+
<div className={classes.legendChart}>
314+
{linearConfiguration.map((section, index) => {
315+
return (
315316
<div
316-
className={classes.colorContainer}
317-
style={{ backgroundColor: section.lineColor }}
318-
/>
319-
<div className={classes.legendLabel}>
320-
{section.keyLabel}
317+
className={classes.singleLegendContainer}
318+
key={`legend-${section.keyLabel}-${index.toString()}`}
319+
>
320+
<div
321+
className={classes.colorContainer}
322+
style={{ backgroundColor: section.lineColor }}
323+
/>
324+
<div className={classes.legendLabel}>
325+
{section.keyLabel}
326+
</div>
321327
</div>
322-
</div>
323-
);
324-
})}
325-
</div>
328+
);
329+
})}
330+
</div>
331+
)}
326332
</Fragment>
327333
)}
328334
</React.Fragment>

0 commit comments

Comments
 (0)