mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Correlations: Show correct number of variables (#66191)
* Show correct number of variables * Remove duplicated test
This commit is contained in:
parent
759a05083a
commit
b302cc2297
@ -671,6 +671,23 @@ describe('explore links utils', () => {
|
|||||||
const dataLinkRtnVal = getVariableUsageInfo(dataLink, scopedVars).allVariablesDefined;
|
const dataLinkRtnVal = getVariableUsageInfo(dataLink, scopedVars).allVariablesDefined;
|
||||||
expect(dataLinkRtnVal).toBe(true);
|
expect(dataLinkRtnVal).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns deduplicated list of variables', () => {
|
||||||
|
const dataLink = {
|
||||||
|
url: '',
|
||||||
|
title: '',
|
||||||
|
internal: {
|
||||||
|
datasourceUid: 'uid',
|
||||||
|
datasourceName: 'dsName',
|
||||||
|
query: { query: 'test ${test} ${foo} ${test:raw} $test' },
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const scopedVars = {
|
||||||
|
testVal: { text: '', value: 'val1' },
|
||||||
|
};
|
||||||
|
const variables = getVariableUsageInfo(dataLink, scopedVars).variables;
|
||||||
|
expect(variables).toHaveLength(2);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { uniqBy } from 'lodash';
|
||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -260,9 +261,10 @@ export function getVariableUsageInfo<T extends DataLink>(
|
|||||||
query: T,
|
query: T,
|
||||||
scopedVars: ScopedVars
|
scopedVars: ScopedVars
|
||||||
): { variables: VariableInterpolation[]; allVariablesDefined: boolean } {
|
): { variables: VariableInterpolation[]; allVariablesDefined: boolean } {
|
||||||
const variables: VariableInterpolation[] = [];
|
let variables: VariableInterpolation[] = [];
|
||||||
const replaceFn = getTemplateSrv().replace.bind(getTemplateSrv());
|
const replaceFn = getTemplateSrv().replace.bind(getTemplateSrv());
|
||||||
replaceFn(getStringsFromObject(query), scopedVars, undefined, variables);
|
replaceFn(getStringsFromObject(query), scopedVars, undefined, variables);
|
||||||
|
variables = uniqBy(variables, 'variableName');
|
||||||
return {
|
return {
|
||||||
variables: variables,
|
variables: variables,
|
||||||
allVariablesDefined: variables.every((variable) => variable.found),
|
allVariablesDefined: variables.every((variable) => variable.found),
|
||||||
|
Loading…
Reference in New Issue
Block a user