64
64
button : hover {
65
65
background : # 0056b3 ;
66
66
}
67
+
68
+ # endpointLink {
69
+ text-decoration : none;
70
+ font-weight : bold;
71
+ color : # 007bff ;
72
+ background-color : # f8f9fa ;
73
+ padding : 8px 12px ;
74
+ border-radius : 4px ;
75
+ border : 1px solid # 007bff ;
76
+ transition : background-color 0.3s , color 0.3s , border-color 0.3s ;
77
+ }
78
+
79
+ # endpointLink : hover {
80
+ background-color : # 007bff ;
81
+ color : white;
82
+ border-color : # 0056b3 ;
83
+ }
84
+
85
+ # endpointLink : active {
86
+ background-color : # 0056b3 ;
87
+ border-color : # 004085 ;
88
+ }
67
89
</ style >
68
90
</ head >
69
91
70
92
< body >
71
93
< div id ="sidebar ">
72
94
< h3 > Edit GraphQL Query</ h3 >
73
95
< textarea id ="graphqlQuery "> </ textarea >
74
- < button id ="updateMap "> Update Map</ button >
75
- < button id ="loadSimpleExample "> Load Simple Example</ button >
76
- < button id ="loadComplexExample "> Load Complex Example</ button >
96
+ < div style ="display: flex; align-items: center; gap: 10px; ">
97
+ < button id ="updateMap "> Update Map</ button >
98
+ < button id ="loadSimpleExample "> Load Simple Example</ button >
99
+ < button id ="loadComplexExample "> Load Complex Example</ button >
100
+ < a id ="endpointLink " href ="" target ="_blank "> View JSON on Endpoint</ a >
101
+ </ div >
77
102
</ div >
78
103
< div id ="map "> </ div >
79
104
@@ -236,7 +261,12 @@ <h3>Edit GraphQL Query</h3>
236
261
} ) ;
237
262
}
238
263
239
- document . getElementById ( 'graphqlQuery' ) . value = initialQuery ;
264
+ function setQuery ( newContent ) {
265
+ const textarea = document . getElementById ( 'graphqlQuery' ) ;
266
+ textarea . value = newContent ;
267
+
268
+ textarea . dispatchEvent ( new Event ( 'input' ) ) ;
269
+ }
240
270
241
271
// Event listener for the "Update Map" button
242
272
document . getElementById ( 'updateMap' ) . addEventListener ( 'click' , ( ) => {
@@ -245,16 +275,25 @@ <h3>Edit GraphQL Query</h3>
245
275
246
276
247
277
document . getElementById ( 'loadSimpleExample' ) . addEventListener ( 'click' , ( ) => {
248
- document . getElementById ( 'graphqlQuery' ) . value = simpleQuery ;
278
+ setQuery ( simpleQuery ) ;
249
279
addDataToMap ( ) ;
250
280
} ) ;
251
281
252
282
document . getElementById ( 'loadComplexExample' ) . addEventListener ( 'click' , ( ) => {
253
- document . getElementById ( 'graphqlQuery' ) . value = complexQuery ;
283
+ setQuery ( complexQuery ) ;
254
284
addDataToMap ( ) ;
255
285
} ) ;
256
286
287
+ document . getElementById ( 'graphqlQuery' ) . addEventListener ( 'input' , function ( ) {
288
+ const editorContent = document . getElementById ( 'graphqlQuery' ) . value ;
289
+ const params = new URLSearchParams ( { qtxt : editorContent } ) ;
290
+ const fullUrl = `${ GRAPHQL_URL } ?${ params . toString ( ) } ` ;
291
+ document . getElementById ( 'endpointLink' ) . href = fullUrl ;
292
+ } ) ;
293
+
294
+ document . getElementById ( 'endpointLink' ) . href = GRAPHQL_URL ;
257
295
296
+ setQuery ( initialQuery ) ;
258
297
259
298
// Load the map data
260
299
addDataToMap ( initialQuery ) ;
0 commit comments