mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: Fix adhoc filter call (#74961)
* Handle nullable parameters properly * run prettier
This commit is contained in:
parent
fb0357947f
commit
7f0570401e
@ -335,7 +335,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
rawQuery: true,
|
rawQuery: true,
|
||||||
},
|
},
|
||||||
this.templateSrv,
|
this.templateSrv,
|
||||||
options.scopedVars
|
options?.scopedVars
|
||||||
).render(true);
|
).render(true);
|
||||||
|
|
||||||
return lastValueFrom(this._seriesQuery(interpolated, options)).then((resp) => {
|
return lastValueFrom(this._seriesQuery(interpolated, options)).then((resp) => {
|
||||||
@ -345,12 +345,12 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
|
|
||||||
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
|
// By implementing getTagKeys and getTagValues we add ad-hoc filters functionality
|
||||||
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
|
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
|
||||||
getTagKeys(options: InfluxQuery) {
|
getTagKeys(options?: InfluxQuery) {
|
||||||
const query = buildMetadataQuery({
|
const query = buildMetadataQuery({
|
||||||
type: 'TAG_KEYS',
|
type: 'TAG_KEYS',
|
||||||
templateService: this.templateSrv,
|
templateService: this.templateSrv,
|
||||||
database: this.database,
|
database: this.database,
|
||||||
measurement: options.measurement ?? '',
|
measurement: options?.measurement ?? '',
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
return this.metricFindQuery(query, options);
|
return this.metricFindQuery(query, options);
|
||||||
@ -361,8 +361,8 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
|
|||||||
type: 'TAG_VALUES',
|
type: 'TAG_VALUES',
|
||||||
templateService: this.templateSrv,
|
templateService: this.templateSrv,
|
||||||
database: this.database,
|
database: this.database,
|
||||||
withKey: options.key,
|
withKey: options.key ?? '',
|
||||||
measurement: options.measurement ?? '',
|
measurement: options?.measurement ?? '',
|
||||||
tags: [],
|
tags: [],
|
||||||
});
|
});
|
||||||
return this.metricFindQuery(query, options);
|
return this.metricFindQuery(query, options);
|
||||||
|
@ -212,12 +212,32 @@ describe('InfluxDataSource', () => {
|
|||||||
// Some functions are required by the parent datasource class to provide functionality
|
// Some functions are required by the parent datasource class to provide functionality
|
||||||
// such as ad-hoc filters, which requires the definition of the getTagKeys, and getTagValues
|
// such as ad-hoc filters, which requires the definition of the getTagKeys, and getTagValues
|
||||||
describe('Datasource contract', () => {
|
describe('Datasource contract', () => {
|
||||||
|
const metricFindQueryMock = jest.fn();
|
||||||
|
beforeEach(() => {
|
||||||
|
ctx.ds.metricFindQuery = metricFindQueryMock;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('has function called getTagKeys', () => {
|
it('has function called getTagKeys', () => {
|
||||||
expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagKeys');
|
expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagKeys');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('has function called getTagValues', () => {
|
it('has function called getTagValues', () => {
|
||||||
expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagValues');
|
expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagValues');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should be able to call getTagKeys without specifying any parameter', () => {
|
||||||
|
ctx.ds.getTagKeys();
|
||||||
|
expect(metricFindQueryMock).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should be able to call getTagValues without specifying anything but key', () => {
|
||||||
|
ctx.ds.getTagValues({ key: 'test' });
|
||||||
|
expect(metricFindQueryMock).toHaveBeenCalled();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Variables should be interpolated correctly', () => {
|
describe('Variables should be interpolated correctly', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user