mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Show invalid fields in label filter (#55751)
* Loki: Show invalid fields in Label filter * Update * Update comment * Update comment
This commit is contained in:
@@ -4,10 +4,11 @@ import React from 'react';
|
||||
|
||||
import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data';
|
||||
|
||||
import { MISSING_LABEL_FILTER_ERROR_MESSAGE } from '../../../prometheus/querybuilder/shared/LabelFilters';
|
||||
import { LokiDatasource } from '../../datasource';
|
||||
import { LokiOperationId, LokiVisualQuery } from '../types';
|
||||
|
||||
import { MISSING_LABEL_FILTER_ERROR_MESSAGE, LokiQueryBuilder } from './LokiQueryBuilder';
|
||||
import { LokiQueryBuilder } from './LokiQueryBuilder';
|
||||
import { EXPLAIN_LABEL_FILTER_CONTENT } from './LokiQueryBuilderExplained';
|
||||
|
||||
const defaultQuery: LokiVisualQuery = {
|
||||
|
||||
@@ -31,8 +31,6 @@ 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>();
|
||||
const [highlightedOp, setHighlightedOp] = useState<QueryBuilderOperation | undefined>(undefined);
|
||||
@@ -77,16 +75,16 @@ export const LokiQueryBuilder = React.memo<Props>(({ datasource, query, onChange
|
||||
return values ? values.map((v) => escapeLabelValueInSelector(v, forLabel.op)) : []; // Escape values in return
|
||||
};
|
||||
|
||||
const labelFilterError: string | undefined = useMemo(() => {
|
||||
const labelFilterRequired: boolean = useMemo(() => {
|
||||
const { labels, operations: op } = query;
|
||||
if (!labels.length && op.length) {
|
||||
// We don't want to show error for initial state with empty line contains operation
|
||||
// Filter is required when operations are present (empty line contains operation is exception)
|
||||
if (op.length === 1 && op[0].id === LokiOperationId.LineContains && op[0].params[0] === '') {
|
||||
return undefined;
|
||||
return false;
|
||||
}
|
||||
return MISSING_LABEL_FILTER_ERROR_MESSAGE;
|
||||
return true;
|
||||
}
|
||||
return undefined;
|
||||
return false;
|
||||
}, [query]);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -113,7 +111,7 @@ export const LokiQueryBuilder = React.memo<Props>(({ datasource, query, onChange
|
||||
}
|
||||
labelsFilters={query.labels}
|
||||
onChange={onChangeLabels}
|
||||
error={labelFilterError}
|
||||
labelFilterRequired={labelFilterRequired}
|
||||
/>
|
||||
</EditorRow>
|
||||
{showExplain && (
|
||||
|
||||
Reference in New Issue
Block a user