InfluxDB: Fix adhoc filter call (#74961)

* Handle nullable parameters properly

* run prettier
This commit is contained in:
ismail simsek 2023-09-18 15:44:55 +03:00 committed by GitHub
parent fb0357947f
commit 7f0570401e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -335,7 +335,7 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
rawQuery: true,
},
this.templateSrv,
options.scopedVars
options?.scopedVars
).render(true);
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
// Used in public/app/features/variables/adhoc/picker/AdHocFilterKey.tsx::fetchFilterKeys
getTagKeys(options: InfluxQuery) {
getTagKeys(options?: InfluxQuery) {
const query = buildMetadataQuery({
type: 'TAG_KEYS',
templateService: this.templateSrv,
database: this.database,
measurement: options.measurement ?? '',
measurement: options?.measurement ?? '',
tags: [],
});
return this.metricFindQuery(query, options);
@ -361,8 +361,8 @@ export default class InfluxDatasource extends DataSourceWithBackend<InfluxQuery,
type: 'TAG_VALUES',
templateService: this.templateSrv,
database: this.database,
withKey: options.key,
measurement: options.measurement ?? '',
withKey: options.key ?? '',
measurement: options?.measurement ?? '',
tags: [],
});
return this.metricFindQuery(query, options);

View File

@ -212,12 +212,32 @@ describe('InfluxDataSource', () => {
// 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
describe('Datasource contract', () => {
const metricFindQueryMock = jest.fn();
beforeEach(() => {
ctx.ds.metricFindQuery = metricFindQueryMock;
});
afterEach(() => {
jest.clearAllMocks();
});
it('has function called getTagKeys', () => {
expect(Object.getOwnPropertyNames(Object.getPrototypeOf(ctx.ds))).toContain('getTagKeys');
});
it('has function called 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', () => {