@@ -20,8 +20,11 @@ interface EventChartProps {
20
20
*/
21
21
const GrafanaEventChart : React . FC < EventChartProps > = React . memo ( props => {
22
22
const { metricName, token } = props ;
23
- const [ graphType , setGraphType ] = useState < string > ( "timeseries" ) ;
23
+ const [ graphType , setGraphType ] = useState ( "timeseries" ) ;
24
+ const [ type , setType ] = useState ( [ 'timeserie' ] ) ;
24
25
// const [solo, setSolo] = useState<SoloStyles | null>(null);
26
+ console . log ( "graphType: " , graphType )
27
+ console . log ( "type: " , type )
25
28
console . log ( "inside GrafanaEventChart" )
26
29
27
30
// setInterval(() => {
@@ -39,33 +42,75 @@ const GrafanaEventChart: React.FC<EventChartProps> = React.memo(props => {
39
42
console . log ( "uid: " , uid )
40
43
console . log ( "parsedName: " , parsedName )
41
44
45
+ let currentType ;
46
+
47
+
48
+
42
49
const handleSelectionChange = async ( event ) => {
43
- setGraphType ( event . target . value ) ;
50
+ //setGraphType(event.target.value);
51
+ setType ( [ ...type , graphType ] ) ;
44
52
await fetch ( 'http://localhost:1111/api/updateDashboard' , {
45
53
method : 'POST' ,
46
54
headers : {
47
55
'Content-Type' : 'application/json' ,
48
56
} ,
49
57
body : JSON . stringify ( { graphType : event . target . value , metric : metricName , token : token } ) ,
50
58
} )
51
-
59
+ console . log ( "event.target.value: " , event . target . value )
60
+ setGraphType ( event . target . value ) ;
52
61
}
53
62
63
+
54
64
return (
55
65
< div className = "chart" data-testid = "Grafana Event Chart" >
56
- < h2 > { parsedName } </ h2 >
66
+ < h2 > { `${ parsedName } - ${ graphType } ` } </ h2 >
67
+ < div >
68
+ < select name = "graphType" id = "graphType" onChange = { handleSelectionChange } >
69
+ < option value = "timeseries" > Time Series</ option >
70
+ < option value = "barchart" > Bar Chart</ option >
71
+ < option value = "stat" > Stat</ option >
72
+ < option value = "gauge" > Gauge</ option >
73
+ < option value = "table" > Table</ option >
74
+ < option value = "histogram" > Histogram</ option >
75
+ </ select >
76
+ </ div >
57
77
{ /* create chart using grafana iframe tag*/ }
58
- < 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 >
59
- < select name = "graphType" id = "graphType" value = { graphType } onChange = { handleSelectionChange } >
60
- < option value = "timeseries" > Time Series</ option >
61
- < option value = "barchart" > Bar Chart</ option >
62
- < option value = "stat" > Stat</ option >
63
- < option value = "gauge" > Gauge</ option >
64
- < option value = "table" > Table</ option >
65
- < option value = "histogram" > Histogram</ option >
66
- </ select >
78
+ { /* {type[type.length - 1] !== graphType ?
79
+ <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
+ : <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 ) :
87
+ null }
88
+
67
89
</ div >
68
90
) ;
69
91
} ) ;
70
92
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 >
95
+ }
96
+
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 >
99
+ }
100
+
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 >
103
+ }
104
+
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 >
107
+ }
108
+
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 >
111
+ }
112
+
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 >
115
+ }
71
116
export default GrafanaEventChart ;
0 commit comments