Skip to content

Commit d6944cc

Browse files
authored
Added zoom option to line charts & bar charts in prometheus dashboard (#1104)
1 parent ebaa194 commit d6944cc

File tree

12 files changed

+438
-124
lines changed

12 files changed

+438
-124
lines changed

portal-ui/src/screens/Console/Common/FormComponents/ModalError/ModalError.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ import { setErrorSnackMessage } from "../../../../../actions";
4242
import { snackBarMessage } from "../../../../../types";
4343
import {
4444
setModalErrorSnackMessage,
45-
setModalSnackMessage,
4645
} from "../../../../../actions";
4746

4847
interface ImodalErrorProps {

portal-ui/src/screens/Console/Common/FormComponents/common/styleLibrary.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ export const widgetCommon = {
431431
borderBottom: "#eef1f4 1px solid",
432432
paddingBottom: 14,
433433
marginBottom: 5,
434+
display: "flex" as const,
435+
justifyContent: "space-between" as const,
434436
},
435437
contentContainer: {
436438
justifyContent: "center" as const,
@@ -470,6 +472,26 @@ export const widgetCommon = {
470472
overflow: "hidden" as const,
471473
textOverflow: "ellipsis" as const,
472474
},
475+
zoomChartCont: {
476+
position: "relative" as const,
477+
height: 340,
478+
width: "100%",
479+
},
480+
zoomChartIcon: {
481+
backgroundColor: "transparent",
482+
border: 0,
483+
padding: 0,
484+
cursor: "pointer",
485+
"& svg": {
486+
color: "#D0D0D0",
487+
height: 16,
488+
},
489+
"&:hover": {
490+
"& svg": {
491+
color: "#404143",
492+
},
493+
},
494+
},
473495
};
474496

475497
export const widgetContainerCommon = {

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

Lines changed: 39 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,26 @@ import {
2525
actionsTray,
2626
widgetContainerCommon,
2727
} from "../../Common/FormComponents/common/styleLibrary";
28-
import { IDashboardPanel, widgetType } from "./types";
28+
import { IDashboardPanel } from "./types";
2929
import { getWidgetsWithValue, panelsConfiguration } from "./utils";
3030
import { TabPanel } from "../../../shared/tabs";
3131
import { ErrorResponseHandler } from "../../../../common/types";
3232
import { setErrorSnackMessage } from "../../../../actions";
33-
import SingleValueWidget from "./Widgets/SingleValueWidget";
34-
import LinearGraphWidget from "./Widgets/LinearGraphWidget";
35-
import BarChartWidget from "./Widgets/BarChartWidget";
36-
import PieChartWidget from "./Widgets/PieChartWidget";
37-
import SingleRepWidget from "./Widgets/SingleRepWidget";
3833
import DateTimePickerWrapper from "../../Common/FormComponents/DateTimePickerWrapper/DateTimePickerWrapper";
3934
import api from "../../../../common/api";
4035
import SyncIcon from "../../../../icons/SyncIcon";
4136
import TabSelector from "../../Common/TabSelector/TabSelector";
42-
import SimpleWidget from "./Widgets/SimpleWidget";
4337
import MergedWidgets from "./MergedWidgets";
38+
import { componentToUse } from "./widgetUtils";
39+
import ZoomWidget from "./ZoomWidget";
40+
import { AppState } from "../../../../store";
4441

4542
interface IPrDashboard {
4643
classes: any;
4744
displayErrorMessage: typeof setErrorSnackMessage;
4845
apiPrefix?: string;
46+
zoomOpen: boolean;
47+
zoomWidget: null | IDashboardPanel;
4948
}
5049

5150
const styles = (theme: Theme) =>
@@ -82,6 +81,8 @@ const PrDashboard = ({
8281
classes,
8382
displayErrorMessage,
8483
apiPrefix = "admin",
84+
zoomOpen,
85+
zoomWidget,
8586
}: IPrDashboard) => {
8687
const [timeStart, setTimeStart] = useState<any>(null);
8788
const [timeEnd, setTimeEnd] = useState<any>(null);
@@ -92,88 +93,6 @@ const PrDashboard = ({
9293

9394
const panels = useCallback(
9495
(tabName: string, filterPanels?: number[][] | null) => {
95-
const componentToUse = (value: IDashboardPanel, index: number) => {
96-
switch (value.type) {
97-
case widgetType.singleValue:
98-
return (
99-
<SingleValueWidget
100-
title={value.title}
101-
panelItem={value}
102-
timeStart={timeStart}
103-
timeEnd={timeEnd}
104-
propLoading={loading}
105-
apiPrefix={apiPrefix}
106-
/>
107-
);
108-
case widgetType.simpleWidget:
109-
return (
110-
<SimpleWidget
111-
title={value.title}
112-
panelItem={value}
113-
timeStart={timeStart}
114-
timeEnd={timeEnd}
115-
propLoading={loading}
116-
apiPrefix={apiPrefix}
117-
iconWidget={value.widgetIcon}
118-
/>
119-
);
120-
case widgetType.pieChart:
121-
return (
122-
<PieChartWidget
123-
title={value.title}
124-
panelItem={value}
125-
timeStart={timeStart}
126-
timeEnd={timeEnd}
127-
propLoading={loading}
128-
apiPrefix={apiPrefix}
129-
/>
130-
);
131-
case widgetType.linearGraph:
132-
case widgetType.areaGraph:
133-
return (
134-
<LinearGraphWidget
135-
title={value.title}
136-
panelItem={value}
137-
timeStart={timeStart}
138-
timeEnd={timeEnd}
139-
propLoading={loading}
140-
hideYAxis={value.disableYAxis}
141-
xAxisFormatter={value.xAxisFormatter}
142-
yAxisFormatter={value.yAxisFormatter}
143-
apiPrefix={apiPrefix}
144-
areaWidget={value.type === widgetType.areaGraph}
145-
/>
146-
);
147-
case widgetType.barChart:
148-
return (
149-
<BarChartWidget
150-
title={value.title}
151-
panelItem={value}
152-
timeStart={timeStart}
153-
timeEnd={timeEnd}
154-
propLoading={loading}
155-
apiPrefix={apiPrefix}
156-
/>
157-
);
158-
case widgetType.singleRep:
159-
const fillColor = value.fillColor ? value.fillColor : value.color;
160-
return (
161-
<SingleRepWidget
162-
title={value.title}
163-
panelItem={value}
164-
timeStart={timeStart}
165-
timeEnd={timeEnd}
166-
propLoading={loading}
167-
color={value.color as string}
168-
fillColor={fillColor as string}
169-
apiPrefix={apiPrefix}
170-
/>
171-
);
172-
default:
173-
return null;
174-
}
175-
};
176-
17796
return filterPanels?.map((panelLine, indexLine) => {
17897
const totalPanelsContained = panelLine.length;
17998

@@ -216,16 +135,28 @@ const PrDashboard = ({
216135
title={panelInfo.title}
217136
leftComponent={componentToUse(
218137
panelInfo.mergedPanels[0],
219-
0
138+
timeStart,
139+
timeEnd,
140+
loading,
141+
apiPrefix
220142
)}
221143
rightComponent={componentToUse(
222144
panelInfo.mergedPanels[1],
223-
1
145+
timeStart,
146+
timeEnd,
147+
loading,
148+
apiPrefix
224149
)}
225150
/>
226151
</Fragment>
227152
) : (
228-
componentToUse(panelInfo, indexPanel)
153+
componentToUse(
154+
panelInfo,
155+
timeStart,
156+
timeEnd,
157+
loading,
158+
apiPrefix
159+
)
229160
)}
230161
</Fragment>
231162
) : null}
@@ -313,6 +244,16 @@ const PrDashboard = ({
313244

314245
return (
315246
<Fragment>
247+
{zoomOpen && (
248+
<ZoomWidget
249+
modalOpen={zoomOpen}
250+
timeStart={timeStart}
251+
timeEnd={timeEnd}
252+
widgetRender={0}
253+
value={zoomWidget}
254+
apiPrefix={apiPrefix}
255+
/>
256+
)}
316257
<Grid
317258
item
318259
xs={12}
@@ -379,11 +320,13 @@ const PrDashboard = ({
379320
</Fragment>
380321
);
381322
};
382-
/*
383-
<
384-
*/
385323

386-
const connector = connect(null, {
324+
const mapState = (state: AppState) => ({
325+
zoomOpen: state.dashboard.zoom.openZoom,
326+
zoomWidget: state.dashboard.zoom.widgetRender,
327+
});
328+
329+
const connector = connect(mapState, {
387330
displayErrorMessage: setErrorSnackMessage,
388331
});
389332

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

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { MaterialUiPickersDate } from "@material-ui/pickers/typings/date";
2929
import { CircularProgress } from "@material-ui/core";
3030
import { createStyles, Theme, withStyles } from "@material-ui/core/styles";
31+
import ZoomOutMapIcon from "@material-ui/icons/ZoomOutMap";
3132
import { IBarChartConfiguration } from "./types";
3233
import { widgetCommon } from "../../../Common/FormComponents/common/styleLibrary";
3334
import BarChartTooltip from "./tooltips/BarChartTooltip";
@@ -36,6 +37,7 @@ import { IDashboardPanel } from "../types";
3637
import { widgetDetailsToPanel } from "../utils";
3738
import { ErrorResponseHandler } from "../../../../../common/types";
3839
import api from "../../../../../common/api";
40+
import { openZoomPage } from "../../actions";
3941

4042
interface IBarChartWidget {
4143
classes: any;
@@ -46,6 +48,8 @@ interface IBarChartWidget {
4648
propLoading: boolean;
4749
displayErrorMessage: any;
4850
apiPrefix: string;
51+
zoomActivated?: boolean;
52+
openZoomPage: typeof openZoomPage;
4953
}
5054

5155
const styles = (theme: Theme) =>
@@ -84,6 +88,8 @@ const BarChartWidget = ({
8488
propLoading,
8589
displayErrorMessage,
8690
apiPrefix,
91+
zoomActivated = false,
92+
openZoomPage,
8793
}: IBarChartWidget) => {
8894
const [loading, setLoading] = useState<boolean>(true);
8995
const [data, setData] = useState<any>([]);
@@ -147,15 +153,31 @@ const BarChartWidget = ({
147153
}
148154

149155
return (
150-
<div className={classes.singleValueContainer}>
151-
<div className={classes.titleContainer}>{title}</div>
156+
<div className={zoomActivated ? "" : classes.singleValueContainer}>
157+
{!zoomActivated && (
158+
<div className={classes.titleContainer}>
159+
{title}{" "}
160+
<button
161+
onClick={() => {
162+
openZoomPage(panelItem);
163+
}}
164+
className={classes.zoomChartIcon}
165+
>
166+
<ZoomOutMapIcon />
167+
</button>
168+
</div>
169+
)}
152170
{loading && (
153171
<div className={classes.loadingAlign}>
154172
<CircularProgress />
155173
</div>
156174
)}
157175
{!loading && (
158-
<div className={classes.contentContainer}>
176+
<div
177+
className={
178+
zoomActivated ? classes.zoomChartCont : classes.contentContainer
179+
}
180+
>
159181
<ResponsiveContainer width="99%">
160182
<BarChart
161183
data={data as object[]}
@@ -178,7 +200,7 @@ const BarChartWidget = ({
178200
dataKey={bar.dataKey}
179201
fill={bar.color}
180202
background={bar.background}
181-
barSize={12}
203+
barSize={zoomActivated ? 25 : 12}
182204
>
183205
{barChartConfiguration.length === 1 ? (
184206
<Fragment>
@@ -214,6 +236,7 @@ const BarChartWidget = ({
214236

215237
const connector = connect(null, {
216238
displayErrorMessage: setErrorSnackMessage,
239+
openZoomPage: openZoomPage,
217240
});
218241

219242
export default withStyles(styles)(connector(BarChartWidget));

0 commit comments

Comments
 (0)