Skip to content

Commit 94fac16

Browse files
committed
Fix history bugs
- Display the APL query (instead of JSON) in the history panel - When running a query from the history, update the editor
1 parent cbb1eea commit 94fac16

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/components/QueryEditor.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
6565
const [queryStr, setQueryStr] = React.useState('');
6666
const { apl: queryText } = query;
6767

68+
if (query.apl !== queryStr) {
69+
// query.apl could've changed from the outside (e.g. when a history query
70+
// is ran), so we need to update the state.
71+
setQueryStr(query.apl);
72+
}
73+
6874
const onQueryTextChange = (apl: string) => {
6975
onChange({ ...query, apl });
7076
setQueryStr(apl);
@@ -79,7 +85,9 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
7985
};
8086

8187
const addPlaceholder = (editor: any, monaco: any) => {
82-
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, 1, 1), text: placeholder }]);
88+
if (editor.getValue() === '') {
89+
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, 1, 1), text: placeholder }]);
90+
}
8391
editor.onDidFocusEditorText(() => {
8492
if (editor.getValue() === placeholder) {
8593
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, placeholder.length, 1), text: '' }]);

src/datasource.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
import {
2-
DataFrame,
3-
DataQueryRequest,
4-
DataQueryResponse,
5-
DataSourceInstanceSettings,
6-
} from '@grafana/data';
1+
import { DataFrame, DataQueryRequest, DataQueryResponse, DataSourceInstanceSettings } from '@grafana/data';
72
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';
83

94
import { AxiomQuery, AxiomDataSourceOptions } from './types';
@@ -55,4 +50,7 @@ export class DataSource extends DataSourceWithBackend<AxiomQuery, AxiomDataSourc
5550
return this.getResource('/schema-lookup');
5651
}
5752

53+
getQueryDisplayText(query: AxiomQuery) {
54+
return query.apl;
55+
}
5856
}

0 commit comments

Comments
 (0)