From 4a8d80a94077767713af7cc4e6668abb93a7c637 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Thu, 20 Sep 2018 16:57:58 +0200 Subject: [PATCH 1/4] Explore: Fix metric suggestions when first letters have been typed --- public/app/containers/Explore/PromQueryField.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/app/containers/Explore/PromQueryField.tsx b/public/app/containers/Explore/PromQueryField.tsx index 491e7005bd0..8188e516161 100644 --- a/public/app/containers/Explore/PromQueryField.tsx +++ b/public/app/containers/Explore/PromQueryField.tsx @@ -255,6 +255,8 @@ class PromQueryField extends React.Component 3; // Determine candidates by CSS context if (_.includes(wrapperClasses, 'context-range')) { // Suggestions for metric[|] @@ -266,7 +268,7 @@ class PromQueryField extends React.Component Date: Thu, 20 Sep 2018 16:59:06 +0200 Subject: [PATCH 2/4] Explore: dont rate-hint on rate queries --- public/app/plugins/datasource/prometheus/datasource.ts | 2 +- .../plugins/datasource/prometheus/specs/datasource.test.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/prometheus/datasource.ts b/public/app/plugins/datasource/prometheus/datasource.ts index ca80b3760a7..b53b9eb34c1 100644 --- a/public/app/plugins/datasource/prometheus/datasource.ts +++ b/public/app/plugins/datasource/prometheus/datasource.ts @@ -46,7 +46,7 @@ export function determineQueryHints(series: any[], datasource?: any): any[] { // Check for monotony const datapoints: number[][] = s.datapoints; - if (datapoints.length > 1) { + if (query.indexOf('rate(') === -1 && datapoints.length > 1) { let increasing = false; const monotonic = datapoints.filter(dp => dp[0] !== null).every((dp, index) => { if (index === 0) { diff --git a/public/app/plugins/datasource/prometheus/specs/datasource.test.ts b/public/app/plugins/datasource/prometheus/specs/datasource.test.ts index eef2bbd56b6..692a1827247 100644 --- a/public/app/plugins/datasource/prometheus/specs/datasource.test.ts +++ b/public/app/plugins/datasource/prometheus/specs/datasource.test.ts @@ -247,6 +247,12 @@ describe('PrometheusDatasource', () => { }); }); + it('returns no rate hint for a monotonously increasing series that already has a rate', () => { + const series = [{ datapoints: [[23, 1000], [24, 1001]], query: 'rate(metric[1m])', responseIndex: 0 }]; + const hints = determineQueryHints(series); + expect(hints).toEqual([null]); + }); + it('returns a rate hint w/o action for a complex monotonously increasing series', () => { const series = [{ datapoints: [[23, 1000], [24, 1001]], query: 'sum(metric)', responseIndex: 0 }]; const hints = determineQueryHints(series); From 0e173918aa575c943ce42ea990f9594c64f86f91 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Thu, 20 Sep 2018 17:02:26 +0200 Subject: [PATCH 3/4] Explore: show series title in tooltip of legend item --- public/app/containers/Explore/Legend.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/public/app/containers/Explore/Legend.tsx b/public/app/containers/Explore/Legend.tsx index e00932fe566..439b6c3e54f 100644 --- a/public/app/containers/Explore/Legend.tsx +++ b/public/app/containers/Explore/Legend.tsx @@ -5,7 +5,9 @@ const LegendItem = ({ series }) => (
- {series.alias} + + {series.alias} + ); From 9e86809ace5e06c7669bb4dc92c718b0421f1909 Mon Sep 17 00:00:00 2001 From: David Kaltschmidt Date: Thu, 20 Sep 2018 17:22:38 +0200 Subject: [PATCH 4/4] Explore: remove closing brace with opening brace --- .../Explore/slate-plugins/braces.test.ts | 18 ++++++++++++++++++ .../containers/Explore/slate-plugins/braces.ts | 16 ++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/public/app/containers/Explore/slate-plugins/braces.test.ts b/public/app/containers/Explore/slate-plugins/braces.test.ts index dda805c07f7..410334d020f 100644 --- a/public/app/containers/Explore/slate-plugins/braces.test.ts +++ b/public/app/containers/Explore/slate-plugins/braces.test.ts @@ -53,4 +53,22 @@ describe('braces', () => { handler(event, change); expect(Plain.serialize(change.value)).toEqual('sum(rate(metric{namespace="dev", cluster="c1"}[2m]))'); }); + + it('removes closing brace when opening brace is removed', () => { + const change = Plain.deserialize('time()').change(); + let event; + change.move(5); + event = new window.KeyboardEvent('keydown', { key: 'Backspace' }); + handler(event, change); + expect(Plain.serialize(change.value)).toEqual('time'); + }); + + it('keeps closing brace when opening brace is removed and inner values exist', () => { + const change = Plain.deserialize('time(value)').change(); + let event; + change.move(5); + event = new window.KeyboardEvent('keydown', { key: 'Backspace' }); + const handled = handler(event, change); + expect(handled).toBeFalsy(); + }); }); diff --git a/public/app/containers/Explore/slate-plugins/braces.ts b/public/app/containers/Explore/slate-plugins/braces.ts index 2ea58569ef0..f3a76263ad6 100644 --- a/public/app/containers/Explore/slate-plugins/braces.ts +++ b/public/app/containers/Explore/slate-plugins/braces.ts @@ -43,6 +43,22 @@ export default function BracesPlugin() { return true; } + case 'Backspace': { + const text = value.anchorText.text; + const offset = value.anchorOffset; + const previousChar = text[offset - 1]; + const nextChar = text[offset]; + if (BRACES[previousChar] && BRACES[previousChar] === nextChar) { + event.preventDefault(); + // Remove closing brace if directly following + change + .deleteBackward() + .deleteForward() + .focus(); + return true; + } + } + default: { break; }