Skip to content

Commit d965a95

Browse files
authored
Display an error message if not providing a URL (#2)
1 parent d48f86b commit d965a95

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tailosinc/grafanaplugin-map-panel",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "Visualize maps provided by an s3 datasource",
55
"scripts": {
66
"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",

src/components/ImageDisplayPanel.tsx

+15-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,33 @@ import useMapData from './GetMaps';
88

99
interface Props extends PanelProps<SimpleOptions> { }
1010

11+
const isValidUrl = (url: string) => /^(http|https):\/\/[^ "]+$/.test(url);
12+
1113
export const ImageDisplayPanel: React.FC<Props> = ({
1214
options, data, width, height,
1315
}) => {
1416
const styles = getStyles();
1517

1618
// 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
1820
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)
2023
const downloadUrl = data.series.length > 1 ? data.series[1].fields[0].values.get(0) : displayUrl;
2124

2225
const { states } = useMapData(displayUrl, width, height, options);
2326
const [displayDownload, setDisplayDownload] = useState(false);
2427

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+
2538
const { imgWidth, imgHeight } = states;
2639
const displayWidth = imgWidth;
2740
const displayHeight = imgHeight;

src/plugin.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"links": [],
1919
"screenshots": [],
20-
"version": "1.0.1",
20+
"version": "1.0.4",
2121
"updated": "2023-07-25"
2222
},
2323
"dependencies": {

0 commit comments

Comments
 (0)