github.com/minio/console@v1.4.1/web-app/src/screens/Console/Dashboard/Prometheus/widgetUtils.tsx (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import React from "react"; 18 import { IDashboardPanel, widgetType } from "./types"; 19 import BarChartWidget from "./Widgets/BarChartWidget"; 20 import LinearGraphWidget from "./Widgets/LinearGraphWidget"; 21 import PieChartWidget from "./Widgets/PieChartWidget"; 22 import SimpleWidget from "./Widgets/SimpleWidget"; 23 import SingleRepWidget from "./Widgets/SingleRepWidget"; 24 import SingleValueWidget from "./Widgets/SingleValueWidget"; 25 import CapacityItem from "./Widgets/CapacityItem"; 26 import DashboardItemBox from "../DashboardItemBox"; 27 import HealActivityRenderer, { 28 SimpleWidgetRenderProps, 29 } from "./Widgets/HealActivityRenderer"; 30 import ScanActivityRenderer from "./Widgets/ScanActivityRenderer"; 31 import UptimeActivityRenderer from "./Widgets/UptimeActivityRenderer"; 32 33 export const componentToUse = ( 34 value: IDashboardPanel, 35 timeStart: any, 36 timeEnd: any, 37 loading: boolean, 38 apiPrefix: string, 39 zoomActivated: boolean = false, 40 ) => { 41 switch (value.type) { 42 case widgetType.singleValue: 43 return ( 44 <SingleValueWidget 45 title={value.title} 46 panelItem={value} 47 timeStart={timeStart} 48 timeEnd={timeEnd} 49 apiPrefix={apiPrefix} 50 /> 51 ); 52 case widgetType.simpleWidget: 53 let renderFn; 54 let CmpToRender: any = null; 55 if (value.id === 80) { 56 CmpToRender = HealActivityRenderer; 57 } else if (value.id === 81) { 58 CmpToRender = ScanActivityRenderer; 59 } else if (value.id === 1) { 60 CmpToRender = UptimeActivityRenderer; 61 } 62 63 if ([80, 81, 1].includes(value.id)) { 64 renderFn = ({ 65 valueToRender, 66 loading, 67 title, 68 id, 69 iconWidget, 70 }: SimpleWidgetRenderProps) => { 71 return ( 72 <CmpToRender 73 valueToRender={valueToRender} 74 loading={loading} 75 title={title} 76 id={id} 77 iconWidget={iconWidget} 78 /> 79 ); 80 }; 81 } 82 return ( 83 <SimpleWidget 84 title={value.title} 85 panelItem={value} 86 timeStart={timeStart} 87 timeEnd={timeEnd} 88 apiPrefix={apiPrefix} 89 iconWidget={value.widgetIcon} 90 renderFn={renderFn} 91 /> 92 ); 93 case widgetType.pieChart: 94 if (value.id === 50) { 95 return ( 96 <DashboardItemBox> 97 <CapacityItem 98 value={value} 99 timeStart={timeStart} 100 timeEnd={timeEnd} 101 apiPrefix={apiPrefix} 102 /> 103 </DashboardItemBox> 104 ); 105 } 106 return ( 107 <PieChartWidget 108 title={value.title} 109 panelItem={value} 110 timeStart={timeStart} 111 timeEnd={timeEnd} 112 apiPrefix={apiPrefix} 113 /> 114 ); 115 case widgetType.linearGraph: 116 case widgetType.areaGraph: 117 return ( 118 <LinearGraphWidget 119 title={value.title} 120 panelItem={value} 121 timeStart={timeStart} 122 timeEnd={timeEnd} 123 hideYAxis={value.disableYAxis} 124 xAxisFormatter={value.xAxisFormatter} 125 yAxisFormatter={value.yAxisFormatter} 126 apiPrefix={apiPrefix} 127 areaWidget={value.type === widgetType.areaGraph} 128 zoomActivated={zoomActivated} 129 /> 130 ); 131 case widgetType.barChart: 132 return ( 133 <BarChartWidget 134 title={value.title} 135 panelItem={value} 136 timeStart={timeStart} 137 timeEnd={timeEnd} 138 apiPrefix={apiPrefix} 139 zoomActivated={zoomActivated} 140 /> 141 ); 142 case widgetType.singleRep: 143 const fillColor = value.fillColor ? value.fillColor : value.color; 144 return ( 145 <SingleRepWidget 146 title={value.title} 147 panelItem={value} 148 timeStart={timeStart} 149 timeEnd={timeEnd} 150 propLoading={loading} 151 color={value.color as string} 152 fillColor={fillColor as string} 153 apiPrefix={apiPrefix} 154 /> 155 ); 156 default: 157 return null; 158 } 159 };