diff --git a/specs/metric_find_query.jest.ts b/specs/metric_find_query.jest.ts index 53df7ed..8775f13 100644 --- a/specs/metric_find_query.jest.ts +++ b/specs/metric_find_query.jest.ts @@ -10,9 +10,9 @@ describe('metric find query', () => { it('returns a measurement query for measurements()', () => { const query = ' measurements(mydb) '; - const result = expandMacros(query).replace(/\s/g, ''); + const result = expandMacros(query); expect(result).toBe( - 'from(bucket:"mydb")|>range($range)|>group(columns:["_measurement"])|>distinct(column:"_measurement")' + 'import "influxdata/influxdb/v1" v1.measurements(bucket: "mydb")' ); }); diff --git a/src/editor/FluxQueryField.tsx b/src/editor/FluxQueryField.tsx index 0220777..a94f247 100644 --- a/src/editor/FluxQueryField.tsx +++ b/src/editor/FluxQueryField.tsx @@ -29,11 +29,11 @@ const DEFAULT_DATABASE = 'telegraf'; function expandQuery(bucket, measurement, field) { if (field) { return ( - `from(bucket: "${bucket}")\n` + - ` |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> filter(fn: (r) => r["_field"] == "${field}")\n |> range($range)\n |> limit(n: 1000)` + `from(bucket: "${bucket}")\n |> range($range)\n` + + ` |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> filter(fn: (r) => r["_field"] == "${field}")\n |> aggregateWindow(every: $__interval, fn: last)` ); } - return `from(bucket: "${bucket}")\n |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> range($range)\n |> limit(n: 1000)`; + return `from(bucket: "${bucket}")\n |> range($range)\n |> filter(fn: (r) => r["_measurement"] == "${measurement}")\n |> aggregateWindow(every: $__interval, fn: last)`; } export default class FluxQueryField extends QueryField { @@ -126,7 +126,7 @@ export default class FluxQueryField extends QueryField { } } else if (db) { const measurements = this.measurements && this.measurements[db]; - if (measurements) { + if (measurements && measurements.length > 0) { prefix = prefix.replace(/\w*\.\./g, ''); typeaheadContext = 'context-measurements'; suggestionGroups.push({ label: 'Measurements', items: measurements }); diff --git a/src/editor/slate-plugins/braces.test.ts b/src/editor/slate-plugins/braces.test.ts deleted file mode 100644 index 5c9a90a..0000000 --- a/src/editor/slate-plugins/braces.test.ts +++ /dev/null @@ -1,47 +0,0 @@ -import Plain from 'slate-plain-serializer'; - -import BracesPlugin from './braces'; - -declare global { - interface Window { - KeyboardEvent: any; - } -} - -describe('braces', () => { - const handler = BracesPlugin().onKeyDown; - - it('adds closing braces around empty value', () => { - const change = Plain.deserialize('').change(); - const event = new window.KeyboardEvent('keydown', { key: '(' }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('()'); - }); - - it('adds closing braces around a value', () => { - const change = Plain.deserialize('foo').change(); - const event = new window.KeyboardEvent('keydown', { key: '(' }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('(foo)'); - }); - - it('adds closing braces around the following value only', () => { - const change = Plain.deserialize('foo bar ugh').change(); - let event; - event = new window.KeyboardEvent('keydown', { key: '(' }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('(foo) bar ugh'); - - // Wrap bar - change.move(5); - event = new window.KeyboardEvent('keydown', { key: '(' }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('(foo) (bar) ugh'); - - // Create empty parens after (bar) - change.move(4); - event = new window.KeyboardEvent('keydown', { key: '(' }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('(foo) (bar)() ugh'); - }); -}); diff --git a/src/editor/slate-plugins/clear.test.ts b/src/editor/slate-plugins/clear.test.ts deleted file mode 100644 index 28ba371..0000000 --- a/src/editor/slate-plugins/clear.test.ts +++ /dev/null @@ -1,38 +0,0 @@ -import Plain from 'slate-plain-serializer'; - -import ClearPlugin from './clear'; - -describe('clear', () => { - const handler = ClearPlugin().onKeyDown; - - it('does not change the empty value', () => { - const change = Plain.deserialize('').change(); - const event = new window.KeyboardEvent('keydown', { - key: 'k', - ctrlKey: true, - }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual(''); - }); - - it('clears to the end of the line', () => { - const change = Plain.deserialize('foo').change(); - const event = new window.KeyboardEvent('keydown', { - key: 'k', - ctrlKey: true, - }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual(''); - }); - - it('clears from the middle to the end of the line', () => { - const change = Plain.deserialize('foo bar').change(); - change.move(4); - const event = new window.KeyboardEvent('keydown', { - key: 'k', - ctrlKey: true, - }); - handler(event, change); - expect(Plain.serialize(change.value)).toEqual('foo '); - }); -}); diff --git a/src/metric_find_query.ts b/src/metric_find_query.ts index d92e2c5..0f9c6d3 100644 --- a/src/metric_find_query.ts +++ b/src/metric_find_query.ts @@ -16,10 +16,7 @@ export default function expandMacros(query) { const measurementsQuery = query.match(MEASUREMENTS_REGEXP); if (measurementsQuery) { const database = measurementsQuery[1]; - return `from(bucket:"${database}") - |> range($range) - |> group(columns:["_measurement"]) - |> distinct(column:"_measurement")`; + return `import "influxdata/influxdb/v1" v1.measurements(bucket: "${database}")`; } const tagsQuery = query.match(TAGS_REGEXP);