1
- import React , { useEffect , useState } from "react" ;
1
+ import React , { useEffect , useContext , useState } from "react" ;
2
+ import { AwsContext } from '../context/AwsContext' ;
2
3
3
- interface Dashboard {
4
- uid : string ;
5
- url : string ;
6
- title : string ;
7
- }
8
4
9
5
interface Props {
10
6
awsUrl : string ;
11
7
}
12
-
8
+ interface Dashboard {
9
+ uid : string ,
10
+ url : string ,
11
+ title : string ,
12
+
13
+ }
13
14
//http://a9921cff905094aa0a45e6e330684283-98913978.us-east-2.elb.amazonaws.com/api/search?folderIds=0
14
15
//`${grafanaUrl}/api/search?query=&type=dash-db`
15
16
//api/search?type=dash-folder
16
17
17
- const GrafanaIFrames : React . FC < Props > = ( { awsUrl } ) => {
18
+ const GrafanaIFrame : React . FC < Props > = ( { awsUrl } ) => {
18
19
const [ dashboards , setDashboards ] = useState < Dashboard [ ] > ( [ ] ) ;
19
20
const [ iframes , setIframes ] = useState < JSX . Element [ ] > ( [ ] ) ;
21
+ const { awsEksData, setAwsEksData, setLoadingState } = useContext ( AwsContext ) ;
22
+
23
+ useEffect ( ( ) => {
24
+ return ( ) => {
25
+ setAwsEksData ( { } ) ;
26
+ setLoadingState ( true ) ;
27
+ } ;
28
+ } , [ ] ) ;
20
29
21
30
useEffect ( ( ) => {
31
+
32
+ // const url = `${awsUrl}/api/search?folderIds=0`
33
+
34
+ // ipcRenderer.send('eksMetricRequest', url);
35
+
36
+ // ipcRenderer.on('eksMetricResponse', async (event, data) => {
37
+ // const eksData = await data.json();
38
+ // console.log(eksData)
39
+ // const tempDashboards = eksData.map((dashboard: any) => ({
40
+ // uid: dashboard.uid,
41
+ // url: dashboard.url,
42
+ // title: dashboard.title,
43
+ // }));
44
+ // setDashboards(tempDashboards);
45
+ // })
22
46
const url = `${ awsUrl } /api/search?folderIds=0`
23
47
console . log ( awsUrl )
24
48
const fetchDashboards = async ( ) => {
25
49
const response = await fetch ( url , {
26
50
method : 'GET' ,
51
+ mode :"no-cors" ,
27
52
headers : {
53
+
28
54
"Access-Control-Allow-Origin" : "*" ,
29
55
Accept : "application/json" ,
30
56
"Content-Type" : "application/json" ,
31
57
Authorization : 'Bearer eyJrIjoiamN4UGRKVHg3cUQyZ201N042NW41bHg5bGhJaVFlaFciLCJuIjoidGVzdEtleSIsImlkIjoxfQ=='
32
58
} ,
33
59
} ) ;
34
- console . log ( url )
35
- console . log ( response )
36
60
const data = await response . json ( ) ;
37
- console . log ( data )
38
- console . log ( awsUrl )
61
+ console . log ( data ) ;
39
62
const tempDashboards = data . map ( ( dashboard : any ) => ( {
40
63
uid : dashboard . uid ,
41
64
url : dashboard . url ,
@@ -44,6 +67,7 @@ const GrafanaIFrames: React.FC<Props> = ({ awsUrl }) => {
44
67
setDashboards ( tempDashboards ) ;
45
68
} ;
46
69
fetchDashboards ( ) ;
70
+ console . log ( dashboards )
47
71
} , [ awsUrl ] ) ;
48
72
49
73
useEffect ( ( ) => {
@@ -63,11 +87,141 @@ const GrafanaIFrames: React.FC<Props> = ({ awsUrl }) => {
63
87
}
64
88
setIframes ( iframesArr ) ;
65
89
} , [ dashboards , awsUrl ] ) ;
66
- return < div >
67
- { iframes }
90
+
91
+
92
+
93
+
94
+ console . log ( awsEksData ) ;
95
+ return (
96
+ < div >
97
+ { iframes }
68
98
< div > ${ awsUrl } </ div >
69
99
70
- </ div > ;
100
+ </ div >
101
+ )
71
102
} ;
72
103
73
- export default GrafanaIFrames ;
104
+
105
+ export default GrafanaIFrame ;
106
+
107
+ // interface Props {
108
+ // awsUrl: string;
109
+ // }
110
+
111
+ // //http://a9921cff905094aa0a45e6e330684283-98913978.us-east-2.elb.amazonaws.com/api/search?folderIds=0
112
+ // //`${grafanaUrl}/api/search?query=&type=dash-db`
113
+ // //api/search?type=dash-folder
114
+
115
+ // const GrafanaIFrames: React.FC<Props> = ({ awsUrl }) => {
116
+ // const [dashboards, setDashboards] = useState<Dashboard[]>([]);
117
+ // const [iframes, setIframes] = useState<JSX.Element[]>([]);
118
+ // const { awsEksData, setAwsEksData, setLoadingState } = useContext(AwsContext);
119
+
120
+ // useEffect(() => {
121
+ // return () => {
122
+ // setAwsEksData({});
123
+ // setLoadingState(true);
124
+ // };
125
+ // }, []);
126
+
127
+ // useEffect(() => {
128
+
129
+ // // const url = `${awsUrl}/api/search?folderIds=0`
130
+
131
+ // // ipcRenderer.send('eksMetricRequest', url);
132
+
133
+ // // ipcRenderer.on('eksMetricResponse', async (event, data) => {
134
+ // // const eksData = await data.json();
135
+ // // console.log(eksData)
136
+ // // const tempDashboards = eksData.map((dashboard: any) => ({
137
+ // // uid: dashboard.uid,
138
+ // // url: dashboard.url,
139
+ // // title: dashboard.title,
140
+ // // }));
141
+ // // setDashboards(tempDashboards);
142
+ // // })
143
+ // // const url = `${awsUrl}/api/search?folderIds=0`
144
+ // // console.log(awsUrl)
145
+ // // const fetchDashboards = async () => {
146
+ // // const response = await fetch(url, {
147
+ // // method: 'GET',
148
+ // // headers: {
149
+ // // "Access-Control-Allow-Origin": "*",
150
+ // // Accept: "application/json",
151
+ // // "Content-Type": "application/json",
152
+ // // Authorization: 'Bearer eyJrIjoiamN4UGRKVHg3cUQyZ201N042NW41bHg5bGhJaVFlaFciLCJuIjoidGVzdEtleSIsImlkIjoxfQ=='
153
+ // // },
154
+ // // });
155
+ // // const data = await response.json();
156
+ // // const tempDashboards = data.map((dashboard: any) => ({
157
+ // // uid: dashboard.uid,
158
+ // // url: dashboard.url,
159
+ // // title: dashboard.title,
160
+ // // }));
161
+ // // setDashboards(tempDashboards);
162
+ // // };
163
+ // // fetchDashboards();
164
+ // // console.log(dashboards)
165
+ // }, [awsUrl]);
166
+
167
+ // useEffect(() => {
168
+ // // const iframesArr: JSX.Element[] = [];
169
+ // // for (const dashboard of dashboards) {
170
+ // // const iframe = (
171
+ // // <iframe
172
+ // // key={dashboard.uid}
173
+ // // src={`${awsUrl}${dashboard.url}`}
174
+ // // title={dashboard.title}
175
+ // // width="100%"
176
+ // // height="600"
177
+ // // style={{ border: "none" }}
178
+ // // />
179
+ // // );
180
+ // // iframesArr.push(iframe);
181
+ // // }
182
+ // // setIframes(iframesArr);
183
+ // }, [dashboards, awsUrl]);
184
+
185
+
186
+
187
+
188
+ // console.log(awsEksData);
189
+ // return (
190
+ // <div>
191
+ // {iframes}
192
+ // <div>${awsUrl}</div>
193
+
194
+ // </div>
195
+ // )
196
+ // };
197
+
198
+ // export default GrafanaIFrames;
199
+
200
+ //interface Dashboard {
201
+ // uid: string;
202
+ // url: string;
203
+ // title: string;
204
+ // }
205
+
206
+
207
+ // const GrafanaIFrame: React.FC = React.memo(props => {
208
+ // const {awsEksData, setAwsEksData , setLoadingState } = useContext(AwsContext);
209
+
210
+ // useEffect(() => {
211
+ // return () => {
212
+ // setAwsEksData({});
213
+ // setLoadingState(true);
214
+ // };
215
+ // }, []);
216
+
217
+
218
+ // console.log(awsEksData)
219
+
220
+
221
+ // console.log('dashboard data: ', awsEksData)
222
+ // return (
223
+ // <div>
224
+ // hi
225
+ // </div>
226
+ // );
227
+ // });
0 commit comments