Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dashboards: Skip inherited object variable names #79567

Merged
merged 3 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion public/app/features/variables/inspect/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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: [
Expand Down
6 changes: 6 additions & 0 deletions public/app/features/variables/inspect/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading