From 96ce654fc23306a3a21c4a679d51a68f6aa918c0 Mon Sep 17 00:00:00 2001 From: Matthieu Patou Date: Sat, 28 Sep 2024 10:43:07 -0700 Subject: [PATCH] Do not try to get the length of extractedVariables if it's null The URL can (although of limited utility) be without variables, let's deal with it. Signed-off-by: Matthieu Patou --- package-lock.json | 4 ++-- package.json | 2 +- src/components/DataLinksEditor.tsx | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e587cf9..998101d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cubism-grafana-panel", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cubism-grafana-panel", - "version": "0.1.0", + "version": "0.1.1", "license": "Apache-2.0", "dependencies": { "@emotion/css": "^11.10.6", diff --git a/package.json b/package.json index 74891c6..e4a84c0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cubism-grafana-panel", - "version": "0.1.0", + "version": "0.1.1", "description": "A panel to display cubism like graph in grafana", "scripts": { "build": "webpack -c ./webpack.config.ts --env production", diff --git a/src/components/DataLinksEditor.tsx b/src/components/DataLinksEditor.tsx index 59c8549..dd027f3 100644 --- a/src/components/DataLinksEditor.tsx +++ b/src/components/DataLinksEditor.tsx @@ -6,6 +6,7 @@ import { css } from '@emotion/css'; // filter out suggestions that we don't support type getSuggestionsFunc = () => VariableSuggestion[] + const DataLinkEditorWarning: React.FC<{ links: Array> }> = ({ links}) => { @@ -19,9 +20,11 @@ const DataLinkEditorWarning: React.FC<{ const pattern = /\${[^}]*}/g; const extractedVariables: string[] = url.match(pattern)!; let unsupported: string[] = []; - for (let j = 0; j < extractedVariables.length; j++) { - if (!extractedVariables[j].slice(2, -1).startsWith('__field.labels')) { - unsupported.push(extractedVariables[j]) + if (extractedVariables) { + for (let j = 0; j < extractedVariables.length; j++) { + if (!extractedVariables[j].slice(2, -1).startsWith('__field.labels')) { + unsupported.push(extractedVariables[j]) + } } } if (unsupported.length > 0) {