Loki: Update copy for missing label filter error message (#53449)

* Loki: Update copy for missing label filter

* Update
This commit is contained in:
Ivana Huckova 2022-08-11 17:57:10 +02:00 committed by GitHub
parent 6592b03f12
commit 8813cbfb62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 10 deletions

View File

@ -1,5 +1,6 @@
import { e2e } from '@grafana/e2e';
const MISSING_LABEL_FILTER_ERROR_MESSAGE = 'Select at least 1 label filter (label and value)';
const dataSourceName = 'LokiBuilder';
const addDataSource = () => {
e2e.flows.addDataSource({
@ -56,7 +57,7 @@ describe('Loki query builder', () => {
e2e().contains('rate({} | logfmt | __error__=`` [$__interval]').should('be.visible');
// Check for expected error
e2e().contains('You need to specify at least 1 label filter (stream selector)').should('be.visible');
e2e().contains(MISSING_LABEL_FILTER_ERROR_MESSAGE).should('be.visible');
// Add labels to remove error
e2e.components.QueryBuilder.labelSelect().should('be.visible').click().type('instance{enter}');
@ -66,7 +67,7 @@ describe('Loki query builder', () => {
.click()
.type('instance1{enter}')
.type('instance2{enter}');
e2e().contains('You need to specify at least 1 label filter (stream selector)').should('not.exist');
e2e().contains(MISSING_LABEL_FILTER_ERROR_MESSAGE).should('not.exist');
e2e().contains(finalQuery).should('be.visible');
// Switch to code editor and check if query was parsed

View File

@ -7,7 +7,7 @@ import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data'
import { LokiDatasource } from '../../datasource';
import { LokiOperationId, LokiVisualQuery } from '../types';
import { LokiQueryBuilder } from './LokiQueryBuilder';
import { MISSING_LABEL_FILTER_ERROR_MESSAGE, LokiQueryBuilder } from './LokiQueryBuilder';
import { EXPLAIN_LABEL_FILTER_CONTENT } from './LokiQueryBuilderExplained';
const defaultQuery: LokiVisualQuery = {
@ -54,9 +54,7 @@ describe('LokiQueryBuilder', () => {
const query = { labels: [], operations: [{ id: LokiOperationId.Logfmt, params: [] }] };
render(<LokiQueryBuilder {...createDefaultProps()} query={query} />);
expect(
await screen.findByText('You need to specify at least 1 label filter (stream selector)')
).toBeInTheDocument();
expect(await screen.findByText(MISSING_LABEL_FILTER_ERROR_MESSAGE)).toBeInTheDocument();
});
it('shows no error for query with empty __line_contains operation and no stream selector', async () => {
@ -64,9 +62,7 @@ describe('LokiQueryBuilder', () => {
render(<LokiQueryBuilder {...createDefaultProps()} query={query} />);
await waitFor(() => {
expect(
screen.queryByText('You need to specify at least 1 label filter (stream selector)')
).not.toBeInTheDocument();
expect(screen.queryByText(MISSING_LABEL_FILTER_ERROR_MESSAGE)).not.toBeInTheDocument();
});
});
it('shows explain section when showExplain is true', async () => {

View File

@ -31,6 +31,7 @@ export interface Props {
onChange: (update: LokiVisualQuery) => void;
onRunQuery: () => void;
}
export const MISSING_LABEL_FILTER_ERROR_MESSAGE = 'Select at least 1 label filter (label and value)';
export const LokiQueryBuilder = React.memo<Props>(({ datasource, query, onChange, onRunQuery, showExplain }) => {
const [sampleData, setSampleData] = useState<PanelData>();
@ -83,7 +84,7 @@ export const LokiQueryBuilder = React.memo<Props>(({ datasource, query, onChange
if (op.length === 1 && op[0].id === LokiOperationId.LineContains && op[0].params[0] === '') {
return undefined;
}
return 'You need to specify at least 1 label filter (stream selector)';
return MISSING_LABEL_FILTER_ERROR_MESSAGE;
}
return undefined;
}, [query]);