mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
AzureMonitor: Fix template variables in ARG subscription field (#63731)
Add support for template variables in sub field
This commit is contained in:
parent
7e6ed3bfcc
commit
823aaaeb7c
@ -92,4 +92,30 @@ describe('ArgQueryEditor', () => {
|
|||||||
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ subscriptions: ['foo', 'bar'] }));
|
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ subscriptions: ['foo', 'bar'] }));
|
||||||
expect(onChange).not.toHaveBeenCalledWith(expect.objectContaining({ subscriptions: ['foo', 'bar', 'foobar'] }));
|
expect(onChange).not.toHaveBeenCalledWith(expect.objectContaining({ subscriptions: ['foo', 'bar', 'foobar'] }));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should keep a template variable if used in the subscription field', async () => {
|
||||||
|
const onChange = jest.fn();
|
||||||
|
const datasource = createMockDatasource({
|
||||||
|
getSubscriptions: jest.fn().mockResolvedValue([{ value: 'foo' }]),
|
||||||
|
});
|
||||||
|
const query = createMockQuery({
|
||||||
|
subscriptions: ['$test'],
|
||||||
|
});
|
||||||
|
render(
|
||||||
|
<ArgQueryEditor
|
||||||
|
{...defaultProps}
|
||||||
|
datasource={datasource}
|
||||||
|
onChange={onChange}
|
||||||
|
query={query}
|
||||||
|
variableOptionGroup={{ label: 'Template Variables', options: [{ label: '$test', value: '$test' }] }}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
await screen.findByTestId(selectors.components.queryEditor.argsQueryEditor.container.input)
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
await screen.findByTestId(selectors.components.queryEditor.argsQueryEditor.subscriptions.input)
|
||||||
|
).toHaveTextContent('$test');
|
||||||
|
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ subscriptions: ['$test'] }));
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -33,7 +33,9 @@ function selectSubscriptions(
|
|||||||
if (querySubscriptions.length === 0 && fetchedSubscriptions.length) {
|
if (querySubscriptions.length === 0 && fetchedSubscriptions.length) {
|
||||||
querySubscriptions = [fetchedSubscriptions[0]];
|
querySubscriptions = [fetchedSubscriptions[0]];
|
||||||
}
|
}
|
||||||
const commonSubscriptions = intersection(querySubscriptions, fetchedSubscriptions);
|
|
||||||
|
const templateVars = querySubscriptions.filter((sub) => sub.includes('$'));
|
||||||
|
const commonSubscriptions = intersection(querySubscriptions, fetchedSubscriptions).concat(templateVars);
|
||||||
if (fetchedSubscriptions.length && querySubscriptions.length > commonSubscriptions.length) {
|
if (fetchedSubscriptions.length && querySubscriptions.length > commonSubscriptions.length) {
|
||||||
// If not all of the query subscriptions are in the list of fetched subscriptions, then
|
// If not all of the query subscriptions are in the list of fetched subscriptions, then
|
||||||
// select only the ones present (or the first one if none is present)
|
// select only the ones present (or the first one if none is present)
|
||||||
|
Loading…
Reference in New Issue
Block a user