Skip to content

Commit 915ec5a

Browse files
karl-powerbossinc
andauthored
Add filterQuery method to datasource (#1732)
Co-authored-by: Andrew Hackmann <5140848+bossinc@users.noreply.github.com>
1 parent d456312 commit 915ec5a

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/data/CHDatasource.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,15 +715,28 @@ describe('ClickHouseDatasource', () => {
715715
});
716716
});
717717

718+
describe('filterQuery', () => {
719+
it('returns true when hide is not set', () => {
720+
expect(mockDatasource.filterQuery({ refId: '1' } as CHQuery)).toBe(true);
721+
});
722+
723+
it('returns true when hide is false', () => {
724+
expect(mockDatasource.filterQuery({ refId: '1', hide: false } as CHQuery)).toBe(true);
725+
});
726+
727+
it('returns false when hide is true', () => {
728+
expect(mockDatasource.filterQuery({ refId: '1', hide: true } as CHQuery)).toBe(false);
729+
});
730+
});
731+
718732
describe('query', () => {
719-
it('filters out hidden queries', async () => {
733+
it('attaches timezone metadata to targets', async () => {
720734
const instance = cloneDeep(mockDatasource);
721-
// Datasource inherits from DataSourceWithBackend
722735
const spy = jest
723736
.spyOn(DataSourceWithBackend.prototype, 'query')
724737
.mockImplementation((_request) => of({ data: [toDataFrame([])] }));
725738
instance.query({
726-
targets: [{ refId: '1' }, { refId: '2', hide: false }, { refId: '3', hide: true }] as DataQuery[],
739+
targets: [{ refId: '1' }, { refId: '2', hide: false }] as DataQuery[],
727740
timezone: 'UTC',
728741
} as any);
729742

src/data/CHDatasource.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,10 +809,12 @@ export class Datasource
809809
return localTimezoneInfo?.ianaName;
810810
}
811811

812+
filterQuery(query: CHQuery): boolean {
813+
return !query.hide;
814+
}
815+
812816
query(request: DataQueryRequest<CHQuery>): Observable<DataQueryResponse> {
813817
const targets = request.targets
814-
// filters out queries disabled in UI
815-
.filter((t) => t.hide !== true)
816818
// attach timezone information
817819
.map((t) => {
818820
return {

0 commit comments

Comments
 (0)