diff --git a/public/app/core/components/TagFilter/TagFilter.tsx b/public/app/core/components/TagFilter/TagFilter.tsx index d41d867041e..f57342ff48d 100644 --- a/public/app/core/components/TagFilter/TagFilter.tsx +++ b/public/app/core/components/TagFilter/TagFilter.tsx @@ -17,6 +17,7 @@ export interface Props { allowCustomValue?: boolean; /** Do not show selected values inside Select. Useful when the values need to be shown in some other components */ hideValues?: boolean; + inputId?: string; isClearable?: boolean; onChange: (tags: string[]) => void; placeholder?: string; @@ -33,6 +34,7 @@ const filterOption = (option: any, searchQuery: string) => { export const TagFilter: FC = ({ allowCustomValue = false, hideValues, + inputId, isClearable, onChange, placeholder = 'Filter by tag', @@ -67,6 +69,7 @@ export const TagFilter: FC = ({ filterOption, getOptionLabel: (i: any) => i.label, getOptionValue: (i: any) => i.value, + inputId, isMulti: true, loadOptions: onLoadOptions, loadingMessage: 'Loading...', diff --git a/public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.test.tsx b/public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.test.tsx new file mode 100644 index 00000000000..60d84d14c63 --- /dev/null +++ b/public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.test.tsx @@ -0,0 +1,61 @@ +import { render, screen } from '@testing-library/react'; +import React from 'react'; +import { GrafanaAnnotationType, GrafanaAnnotationQuery } from '../types'; +import AnnotationQueryEditor from './AnnotationQueryEditor'; + +describe('AnnotationQuery', () => { + const mockOnChange = jest.fn(); + let mockQuery: GrafanaAnnotationQuery; + + beforeEach(() => { + mockQuery = { + refId: 'Anno', + type: GrafanaAnnotationType.Tags, + limit: 100, + }; + }); + + it('has a "Filter by" input', () => { + render(); + const filterBy = screen.getByLabelText('Filter by'); + expect(filterBy).toBeInTheDocument(); + }); + + it('has a "Max limit" input', () => { + render(); + const maxLimit = screen.getByLabelText('Max limit'); + expect(maxLimit).toBeInTheDocument(); + }); + + describe('when the query type is "Dashboard"', () => { + beforeEach(() => { + mockQuery.type = GrafanaAnnotationType.Dashboard; + }); + + it('does not have a "Match any" toggle', () => { + render(); + const matchAny = screen.queryByLabelText('Match any'); + expect(matchAny).toBeNull(); + }); + + it('does not have a "Tags" input', () => { + render(); + const tags = screen.queryByLabelText('Tags'); + expect(tags).toBeNull(); + }); + }); + + describe('when the query type is "Tags"', () => { + it('has a "Match any" toggle', () => { + render(); + const matchAny = screen.getByLabelText('Match any'); + expect(matchAny).toBeInTheDocument(); + }); + + it('has a "Tags" input', () => { + render(); + const tags = screen.getByLabelText('Tags'); + expect(tags).toBeInTheDocument(); + }); + }); +}); diff --git a/public/app/plugins/datasource/grafana/components/AnnotationQuery.tsx b/public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.tsx similarity index 76% rename from public/app/plugins/datasource/grafana/components/AnnotationQuery.tsx rename to public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.tsx index 4e6a23a2665..3e9549db392 100644 --- a/public/app/plugins/datasource/grafana/components/AnnotationQuery.tsx +++ b/public/app/plugins/datasource/grafana/components/AnnotationQueryEditor.tsx @@ -47,7 +47,7 @@ interface Props { onChange: (newValue: GrafanaAnnotationQuery) => void; } -export default function AnnotationQuery({ query, onChange }: Props) { +export default function AnnotationQueryEditor({ query, onChange }: Props) { const { limit = 100, matchAny = false, tags = [], type = GrafanaAnnotationType.Tags } = query; const onFilterByChange = (newValue: SelectableValue) => @@ -78,19 +78,37 @@ export default function AnnotationQuery({ query, onChange }: Props) {
- - {type === GrafanaAnnotationType.Tags && ( - + - + )} diff --git a/public/app/plugins/datasource/grafana/datasource.ts b/public/app/plugins/datasource/grafana/datasource.ts index 4a2763275e5..755462aaccf 100644 --- a/public/app/plugins/datasource/grafana/datasource.ts +++ b/public/app/plugins/datasource/grafana/datasource.ts @@ -14,7 +14,7 @@ import { GrafanaQuery, GrafanaAnnotationQuery, GrafanaAnnotationType, GrafanaQue import { getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, toDataQueryResponse } from '@grafana/runtime'; import { Observable, of, merge } from 'rxjs'; import { map, catchError } from 'rxjs/operators'; -import AnnotationQuery from './components/AnnotationQuery'; +import AnnotationQueryEditor from './components/AnnotationQueryEditor'; let counter = 100; @@ -22,7 +22,7 @@ export class GrafanaDatasource extends DataSourceApi { constructor(instanceSettings: DataSourceInstanceSettings) { super(instanceSettings); this.annotations = { - QueryEditor: AnnotationQuery, + QueryEditor: AnnotationQueryEditor, }; }