@@ -8,20 +8,33 @@ import useMapData from './GetMaps';
8
8
9
9
interface Props extends PanelProps < SimpleOptions > { }
10
10
11
+ const isValidUrl = ( url : string ) => / ^ ( h t t p | h t t p s ) : \/ \/ [ ^ " ] + $ / . test ( url ) ;
12
+
11
13
export const ImageDisplayPanel : React . FC < Props > = ( {
12
14
options, data, width, height,
13
15
} ) => {
14
16
const styles = getStyles ( ) ;
15
17
16
18
// TODO: we'll need get all values from the first data series into URLS to be displayed
17
- // First query from the S3 Data Source plugin to get the image to be displayed
19
+ // First series will get the image to be displayed
18
20
const displayUrl = data . series [ 0 ] . fields [ 0 ] . values . get ( 0 ) ;
19
- // Second query from the S3 Data Source plugin to get a distinct download URL (if it exists)
21
+
22
+ // Second series will get a distinct download URL (if it exists)
20
23
const downloadUrl = data . series . length > 1 ? data . series [ 1 ] . fields [ 0 ] . values . get ( 0 ) : displayUrl ;
21
24
22
25
const { states } = useMapData ( displayUrl , width , height , options ) ;
23
26
const [ displayDownload , setDisplayDownload ] = useState ( false ) ;
24
27
28
+ if ( ! isValidUrl ( displayUrl ) || ! isValidUrl ( downloadUrl ) ) {
29
+ return (
30
+ < div className = { styles . panel } >
31
+ < div className = { styles . wrapper } >
32
+ ERROR: Data source must return a valid image URL, like `https://grafana.com/media/images/logos/grafana-logo-footer.svg`
33
+ </ div >
34
+ </ div >
35
+ ) ;
36
+ }
37
+
25
38
const { imgWidth, imgHeight } = states ;
26
39
const displayWidth = imgWidth ;
27
40
const displayHeight = imgHeight ;
0 commit comments