Skip to content

Commit

Permalink
make disable query button work (grafana#237)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshustov authored Nov 14, 2022
1 parent 81f5f71 commit 218cede
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/data/CHDatasource.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ArrayDataFrame, ScopedVar, ScopedVars, toDataFrame } from '@grafana/data';
import { ArrayDataFrame, ScopedVar, ScopedVars, toDataFrame, DataQuery } from '@grafana/data';
import { of } from 'rxjs';
import { DataSourceWithBackend } from '@grafana/runtime';
import { mockDatasource } from '__mocks__/datasource';
import { CHQuery, QueryType } from 'types';
import { cloneDeep } from 'lodash';
Expand Down Expand Up @@ -244,4 +245,22 @@ describe('ClickHouseDatasource', () => {
);
});
});

describe('query', () => {
it('filters out hidden queries', async () => {
const instance = cloneDeep(mockDatasource);
// Datasource inherits from DataSourceWithBackend
const spy = jest
.spyOn(DataSourceWithBackend.prototype, 'query')
.mockImplementation((request) => of({ data: [toDataFrame([])] }));

instance.query({
targets: [{ refId: '1' }, { refId: '2', hide: false }, { refId: '3', hide: true }] as DataQuery[],
} as any);

expect(spy).toHaveBeenCalledWith({
targets: [{ refId: '1' }, { refId: '2', hide: false }],
});
});
});
});
9 changes: 9 additions & 0 deletions src/data/CHDatasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
vectorator,
} from '@grafana/data';
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
import { Observable } from 'rxjs';
import { CHConfig, CHQuery, FullField, QueryType } from '../types';
import { AdHocFilter } from './adHocFilter';
import { isString, isEmpty } from 'lodash';
Expand Down Expand Up @@ -182,6 +183,14 @@ export class Datasource extends DataSourceWithBackend<CHQuery, CHConfig> {
return this.values(frame);
}

query(request: DataQueryRequest<CHQuery>): Observable<DataQueryResponse> {
return super.query({
...request,
// filters out queries disabled in UI
targets: request.targets.filter((t) => t.hide !== true),
});
}

private runQuery(request: Partial<CHQuery>, options?: any): Promise<DataFrame> {
return new Promise((resolve) => {
const req = {
Expand Down

0 comments on commit 218cede

Please sign in to comment.