Dashboards: Skip inherited object variable names (#79567)

This commit is contained in:
Jára Benc 2023-12-19 15:08:28 +01:00 committed by GitHub
parent ecfc8048e1
commit 315dd75767
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 1 deletions

View File

@ -6,7 +6,13 @@ import { createDataSourceVariableAdapter } from '../datasource/adapter';
import { createQueryVariableAdapter } from '../query/adapter';
import { createGraph } from '../state/actions';
import { flattenPanels, getAllAffectedPanelIdsForVariableChange, getPanelVars, getPropsWithVariable } from './utils';
import {
flattenPanels,
getAllAffectedPanelIdsForVariableChange,
getPanelVars,
getPropsWithVariable,
getVariableName,
} from './utils';
describe('getPropsWithVariable', () => {
it('when called it should return the correct graph', () => {
@ -303,6 +309,20 @@ describe('flattenPanels', () => {
});
});
describe('getVariableName', () => {
it('should return undefined if no match is found', () => {
expect(getVariableName('no variable here')).toBeUndefined();
});
it('should return undefined if variable matches inherited object prop names', () => {
expect(getVariableName('${toString}')).toBeUndefined();
});
it('should return the variable name if it exists and does not match inherited object prop names', () => {
expect(getVariableName('${myVariable}')).toBe('myVariable');
});
});
const dashWithRepeatsAndRows = {
annotations: {
list: [

View File

@ -60,6 +60,12 @@ export function getVariableName(expression: string) {
return undefined;
}
const variableName = match.slice(1).find((match) => match !== undefined);
// ignore variables that match inherited object prop names
if (variableName! in {}) {
return undefined;
}
return variableName;
}