1
1
import React , { useState } from 'react' ;
2
2
import { all , solo as soloStyle } from './sizeSwitch' ;
3
+ import '../stylesheets/GrafanaGraph.scss' ;
3
4
4
5
interface EventChartProps {
5
6
metricName : string ;
@@ -11,6 +12,8 @@ interface EventChartProps {
11
12
// width: number;
12
13
// }
13
14
15
+ type TimeFrame = '5m' | '15m' | '1h' | '2h' | '1d' | '2d' | '3d' ;
16
+
14
17
15
18
16
19
/**
@@ -22,6 +25,8 @@ const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
22
25
const { metricName, token } = props ;
23
26
const [ graphType , setGraphType ] = useState ( "timeseries" ) ;
24
27
const [ type , setType ] = useState ( [ 'timeserie' ] ) ;
28
+ const [ timeFrame , setTimeFrame ] = useState ( '5m' ) ;
29
+
25
30
// const [solo, setSolo] = useState<SoloStyles | null>(null);
26
31
console . log ( "graphType: " , graphType )
27
32
console . log ( "type: " , type )
@@ -42,10 +47,6 @@ const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
42
47
console . log ( "uid: " , uid )
43
48
console . log ( "parsedName: " , parsedName )
44
49
45
- let currentType ;
46
-
47
-
48
-
49
50
const handleSelectionChange = async ( event ) => {
50
51
//setGraphType(event.target.value);
51
52
setType ( [ ...type , graphType ] ) ;
@@ -62,55 +63,70 @@ const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
62
63
63
64
64
65
return (
65
- < div className = "chart" data-testid = "Grafana Event Chart" >
66
- < h2 > { `${ parsedName } - ${ graphType } ` } </ h2 >
67
- < div >
68
- < select name = "graphType" id = "graphType" onChange = { handleSelectionChange } >
66
+ < div className = "chart" id = "Grafana_Event_Chart" >
67
+ < h2 > { `${ parsedName } --- ${ graphType } ` } </ h2 >
68
+ < div id = "selection" >
69
+ < label htmlFor = "timeFrame" > Graph Type: </ label >
70
+ < select name = "timeFrame" id = "timeFrame" onChange = { handleSelectionChange } >
69
71
< option value = "timeseries" > Time Series</ option >
70
72
< option value = "barchart" > Bar Chart</ option >
71
73
< option value = "stat" > Stat</ option >
72
74
< option value = "gauge" > Gauge</ option >
73
75
< option value = "table" > Table</ option >
74
76
< option value = "histogram" > Histogram</ option >
75
77
</ select >
78
+
79
+ < label htmlFor = "graphType" > Time Frame: </ label >
80
+ < select name = "graphType" id = "graphType" onChange = { ( e ) => setTimeFrame ( e . target . value as TimeFrame ) } >
81
+ < option value = { '5m' } > 5 minutes</ option >
82
+ < option value = { '15m' } > 15 minutes</ option >
83
+ < option value = { '1h' } > 1 hour</ option >
84
+ < option value = { '2h' } > 2 hours</ option >
85
+ < option value = { '1d' } > 1 day</ option >
86
+ < option value = { '2d' } > 2 days</ option >
87
+ < option value = { '3d' } > 3 days</ option >
88
+ </ select >
76
89
</ div >
77
90
{ /* create chart using grafana iframe tag*/ }
78
91
{ /* {type[type.length - 1] !== graphType ?
79
92
<iframe src={`http://localhost:32000/d-solo/${uid}/${parsedName}?orgId=1&refresh=10s&from=now-5m&to=now&panelId=1` } width="650" height="400" ></iframe>
80
93
: <iframe src={`http://localhost:32000/d-solo/${uid}/${parsedName}?orgId=1&refresh=10s&from=now-5m&to=now&panelId=1` } width="650" height="400" ></iframe> } */ }
81
- { graphType === "timeseries" ? TimeSeries ( uid , parsedName , graphType ) :
82
- graphType === "barchart" ? BarChart ( uid , parsedName , graphType ) :
83
- graphType === "stat" ? Stat ( uid , parsedName , graphType ) :
84
- graphType === "gauge" ? Gauge ( uid , parsedName , graphType ) :
85
- graphType === "table" ? Table ( uid , parsedName , graphType ) :
86
- graphType === "histogram" ? Histogram ( uid , parsedName , graphType ) :
94
+ { graphType === "timeseries" ? TimeSeries ( uid , parsedName , graphType , timeFrame ) :
95
+ graphType === "barchart" ? BarChart ( uid , parsedName , graphType , timeFrame ) :
96
+ graphType === "stat" ? Stat ( uid , parsedName , graphType , timeFrame ) :
97
+ graphType === "gauge" ? Gauge ( uid , parsedName , graphType , timeFrame ) :
98
+ graphType === "table" ? Table ( uid , parsedName , graphType , timeFrame ) :
99
+ graphType === "histogram" ? Histogram ( uid , parsedName , graphType , timeFrame ) :
87
100
null }
88
101
89
102
</ div >
90
103
) ;
91
104
} ) ;
92
105
93
- const TimeSeries = ( uid , parsedName , graphType ) => {
94
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m&to=now&panelId=1&${ graphType } ` } width = "650" height = "400" > </ iframe >
106
+ const TimeSeries = ( uid , parsedName , graphType , timeFrame ) => {
107
+ return < >
108
+ < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1&${ graphType } ` } width = "800" height = "500" > </ iframe >
109
+ < hr />
110
+ </ >
95
111
}
96
112
97
- const BarChart = ( uid , parsedName , graphType ) => {
98
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m &to=now&panelId=1${ graphType } ` } width = "650 " height = "400 " > </ iframe >
113
+ const BarChart = ( uid , parsedName , graphType , timeFrame ) => {
114
+ return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1${ graphType } ` } width = "800 " height = "500 " > </ iframe >
99
115
}
100
116
101
- const Stat = ( uid , parsedName , graphType ) => {
102
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m &to=now&panelId=1${ graphType } ` } width = "650 " height = "400 " > </ iframe >
117
+ const Stat = ( uid , parsedName , graphType , timeFrame ) => {
118
+ return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1${ graphType } ` } width = "800 " height = "500 " > </ iframe >
103
119
}
104
120
105
- const Gauge = ( uid , parsedName , graphType ) => {
106
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m &to=now&panelId=1${ graphType } ` } width = "650 " height = "400 " > </ iframe >
121
+ const Gauge = ( uid , parsedName , graphType , timeFrame ) => {
122
+ return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1${ graphType } ` } width = "800 " height = "500 " > </ iframe >
107
123
}
108
124
109
- const Table = ( uid , parsedName , graphType ) => {
110
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m &to=now&panelId=1${ graphType } ` } width = "650 " height = "400 " > </ iframe >
125
+ const Table = ( uid , parsedName , graphType , timeFrame ) => {
126
+ return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1${ graphType } ` } width = "800 " height = "500 " > </ iframe >
111
127
}
112
128
113
- const Histogram = ( uid , parsedName , graphType ) => {
114
- return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-5m &to=now&panelId=1${ graphType } ` } width = "650 " height = "400 " > </ iframe >
129
+ const Histogram = ( uid , parsedName , graphType , timeFrame ) => {
130
+ return < iframe src = { `http://localhost:32000/d-solo/${ uid } /${ parsedName } ?orgId=1&refresh=10s&from=now-${ timeFrame } &to=now&panelId=1${ graphType } ` } width = "800 " height = "500 " > </ iframe >
115
131
}
116
132
export default GrafanaEventChart ;
0 commit comments