diff --git a/package-lock.json b/package-lock.json index 5f8cbf3..45487e8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "akvorado", - "version": "1.0.30", + "version": "1.0.33", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "akvorado", - "version": "1.0.30", + "version": "1.0.33", "license": "Apache-2.0", "dependencies": { "@codemirror/autocomplete": "^6.17.0", diff --git a/src/components/QueryEditor.tsx b/src/components/QueryEditor.tsx index 58b28ab..e3eb7c0 100644 --- a/src/components/QueryEditor.tsx +++ b/src/components/QueryEditor.tsx @@ -2,7 +2,7 @@ import React, { ChangeEvent, useState } from 'react'; import { InlineField, Input, Stack, Select, AsyncMultiSelect, useTheme2, CollapsableSection } from '@grafana/ui'; import { QueryEditorProps, SelectableValue, AppEvents } from '@grafana/data'; import { DataSource, queryTypes, queryUnits } from '../datasource'; -import { Configuration, DEFAULT_LIMIT, MyDataSourceOptions, MyQuery } from '../types'; +import { Configuration, DEFAULT_LIMIT, DEFAULT_QUERY, MyDataSourceOptions, MyQuery } from '../types'; import { getAppEvents } from '@grafana/runtime'; import CodeMirror, { EditorView, placeholder } from '@uiw/react-codemirror'; @@ -17,12 +17,13 @@ const appEvents = getAppEvents(); type Props = QueryEditorProps; export function QueryEditor({ query, onChange, datasource }: Props) { - const { limit, type, unit, dimensions } = query; + const { limit, type, unit, dimensions, expression } = query; const [uiDimensions, setUIDimensions] = useState>>( dimensions?.map((v) => ({ label: v, value: v })) ?? [{ label: 'SrcAS', value: 'SrcAS' }] ); - const [expression, setExpression] = useState('InIfBoundary = external'); + const [uiExpression, setUIExpression] = useState(expression || DEFAULT_QUERY.expression !!); + const getFilterTheme = (isDark: boolean) => [ syntaxHighlighting( @@ -59,10 +60,10 @@ export function QueryEditor({ query, onChange, datasource }: Props) { .sort((a, b) => a.label.localeCompare(b.label)) ?? [] ); } catch (error) { - appEvents.publish({ - type: AppEvents.alertError.name, - payload: ['Failed to fetch dimensions:'+error], - }); + appEvents.publish({ + type: AppEvents.alertError.name, + payload: ['Failed to fetch dimensions:' + error], + }); return []; } }; @@ -155,9 +156,11 @@ export function QueryEditor({ query, onChange, datasource }: Props) { width={10} /> + + { if (viewUpdate.docChanged) { - setExpression(viewUpdate.state.doc.toString()); + setUIExpression(viewUpdate.state.doc.toString()); onChange({ ...query, expression: viewUpdate.state.doc.toString() }); } if (viewUpdate.focusChanged) { @@ -194,9 +197,9 @@ export function QueryEditor({ query, onChange, datasource }: Props) { - - + diff --git a/src/datasource.ts b/src/datasource.ts index de13309..317f1de 100644 --- a/src/datasource.ts +++ b/src/datasource.ts @@ -1,4 +1,4 @@ -import { FetchResponse, getBackendSrv, isFetchError } from '@grafana/runtime'; +import { FetchResponse, getBackendSrv, getTemplateSrv, isFetchError } from '@grafana/runtime'; import { CoreApp, DataQueryRequest, @@ -46,7 +46,7 @@ export class DataSource extends DataSourceApi { bidirectional: false, dimensions: target.dimensions, end: to, - filter: target.expression, + filter: getTemplateSrv().replace(target.expression, options.scopedVars), limit: target.limit, points: 200, 'previous-period': false,