From 32438c4716fbb3a2156426513f9d641ed41e2292 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Mon, 31 Dec 2018 12:38:13 +0000 Subject: [PATCH] Loki: change query row to be single field again - tried split selector and search for a week, and it did not feel natural - keeping some of the original modifications in QueryField from splitting PR - adapted CheatSheet and placeholder text - added new label selector state: No labels found --- .../loki/components/LokiCheatSheet.tsx | 10 ++-- .../loki/components/LokiQueryField.tsx | 59 +++++-------------- 2 files changed, 19 insertions(+), 50 deletions(-) diff --git a/public/app/plugins/datasource/loki/components/LokiCheatSheet.tsx b/public/app/plugins/datasource/loki/components/LokiCheatSheet.tsx index c3a85495a59..49f6b74e8b6 100644 --- a/public/app/plugins/datasource/loki/components/LokiCheatSheet.tsx +++ b/public/app/plugins/datasource/loki/components/LokiCheatSheet.tsx @@ -3,22 +3,22 @@ import React from 'react'; const CHEAT_SHEET_ITEMS = [ { title: 'See your logs', - label: 'Start by selecting a log stream from the Log Labels selector.', + label: 'Start by selecting a log stream from the Log labels selector.', }, { - title: 'Logs From a Job', + title: 'Logs from a "job"', expression: '{job="default/prometheus"}', label: 'Returns all log lines emitted by instances of this job.', }, { - title: 'Combine Stream Selectors', + title: 'Combine stream selectors', expression: '{app="cassandra",namespace="prod"}', label: 'Returns all log lines from streams that have both labels.', }, { - title: 'Search For Text', + title: 'Search for text', expression: '{app="cassandra"} (duration|latency)\\s*(=|is|of)\\s*[\\d\\.]+', - label: 'The right search field takes a regular expression to search for.', + label: 'Add a regular expression after the selector to filter for.', }, ]; diff --git a/public/app/plugins/datasource/loki/components/LokiQueryField.tsx b/public/app/plugins/datasource/loki/components/LokiQueryField.tsx index f5d42a2e8cf..820c964f7b1 100644 --- a/public/app/plugins/datasource/loki/components/LokiQueryField.tsx +++ b/public/app/plugins/datasource/loki/components/LokiQueryField.tsx @@ -12,14 +12,18 @@ import BracesPlugin from 'app/features/explore/slate-plugins/braces'; import RunnerPlugin from 'app/features/explore/slate-plugins/runner'; import QueryField, { TypeaheadInput, QueryFieldState } from 'app/features/explore/QueryField'; import { DataQuery } from 'app/types'; -import { parseQuery, formatQuery } from '../query_utils'; const PRISM_SYNTAX = 'promql'; -const SEARCH_FIELD_STYLES = { - width: '66%', - marginLeft: 3, -}; +function getChooserText(hasSytax, hasLogLabels) { + if (!hasSytax) { + return 'Loading labels...'; + } + if (!hasLogLabels) { + return '(No labels found)'; + } + return 'Log labels'; +} export function willApplySuggestion(suggestion: string, { typeaheadContext, typeaheadText }: QueryFieldState): string { // Modify suggestion based on context @@ -145,35 +149,12 @@ class LokiQueryField extends React.PureComponent { - const enableSearchField = !this.modifiedQuery && value; - this.modifiedQuery = value; // Send text change to parent const { initialQuery, onQueryChange } = this.props; if (onQueryChange) { - const search = this.modifiedSearch || parseQuery(initialQuery.expr).regexp; - const expr = formatQuery(value, search); const query = { ...initialQuery, - expr, - }; - onQueryChange(query, override); - } - // Enable the search field if we have a selector query - if (enableSearchField) { - this.forceUpdate(); - } - }; - - onChangeSearch = (value: string, override?: boolean) => { - this.modifiedSearch = value; - // Send text change to parent - const { initialQuery, onQueryChange } = this.props; - if (onQueryChange) { - const selector = this.modifiedQuery || parseQuery(initialQuery.expr).query; - const expr = formatQuery(selector, value); - const query = { - ...initialQuery, - expr, + expr: value, }; onQueryChange(query, override); } @@ -223,10 +204,8 @@ class LokiQueryField extends React.PureComponent 0; + const chooserText = getChooserText(syntaxLoaded, hasLogLabels); return (
@@ -241,11 +220,11 @@ class LokiQueryField extends React.PureComponent @@ -261,16 +240,6 @@ class LokiQueryField extends React.PureComponent ) : null}
-
- -
); }