Skip to content

Commit

Permalink
Merge pull request #32 from axiomhq/arne/inp-184-fix-query-history-in…
Browse files Browse the repository at this point in the history
…-grafana-data-source-plugin

Fix history bugs
  • Loading branch information
bahlo authored Jun 29, 2023
2 parents cbb1eea + 94fac16 commit 7b5d3c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
10 changes: 9 additions & 1 deletion src/components/QueryEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
const [queryStr, setQueryStr] = React.useState('');
const { apl: queryText } = query;

if (query.apl !== queryStr) {
// query.apl could've changed from the outside (e.g. when a history query
// is ran), so we need to update the state.
setQueryStr(query.apl);
}

const onQueryTextChange = (apl: string) => {
onChange({ ...query, apl });
setQueryStr(apl);
Expand All @@ -79,7 +85,9 @@ export function QueryEditor({ query, onChange, onRunQuery, datasource }: Props)
};

const addPlaceholder = (editor: any, monaco: any) => {
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, 1, 1), text: placeholder }]);
if (editor.getValue() === '') {
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, 1, 1), text: placeholder }]);
}
editor.onDidFocusEditorText(() => {
if (editor.getValue() === placeholder) {
editor.executeEdits(null, [{ range: new monaco.Range(1, 1, placeholder.length, 1), text: '' }]);
Expand Down
10 changes: 4 additions & 6 deletions src/datasource.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import {
DataFrame,
DataQueryRequest,
DataQueryResponse,
DataSourceInstanceSettings,
} from '@grafana/data';
import { DataFrame, DataQueryRequest, DataQueryResponse, DataSourceInstanceSettings } from '@grafana/data';
import { DataSourceWithBackend, getTemplateSrv } from '@grafana/runtime';

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

getQueryDisplayText(query: AxiomQuery) {
return query.apl;
}
}

0 comments on commit 7b5d3c8

Please sign in to comment.