Hi All,
Firstly, I do (obviously) apologise if this is asked and answered, I’ve not found a single solution (or even question) that covers this- this is very possibly down to my search terms and lack of Grafana Plugin Development vocabulary or terminology, so if this is a solved problem, I’m happy to be told the right combo of words.
(That reads as sarcasm, it’s genuinely not).
I’ve written a dirt simple little data source plugin. The backend talks to my API perfectly well, and I can draw all the charts I want from it.
The problem I have is that my plugin returns a lot of fields by default, and I want to just return a specific one for some alerts I want to setup.
To do this I’ve added an optional value in both the backend:
type Query struct {
Dimension *string `json:"dimension"`
}
and the frontend
export interface MyQuery extends DataQuery {
dimension?: string;
}
and updated my QueryEditor
thusly
import React, { ChangeEvent } from 'react';
import { InlineField, Input, Stack } from '@grafana/ui';
import { QueryEditorProps } from '@grafana/data';
import { DataSource } from '../datasource';
import { MyDataSourceOptions, MyQuery } from '../types';
type Props = QueryEditorProps<DataSource, MyQuery, MyDataSourceOptions>;
export function QueryEditor({ query, onChange, onRunQuery }: Props) {
const { dimension } = query;
const onQueryTextChange = (event: ChangeEvent<HTMLInputElement>) => {
onChange({ ...query, dimension: event.target.value });
};
return (
<Stack gap={0}>
<InlineField label="Dimension" labelWidth={16} tooltip="Dimension">
<Input
id="query-editor-query-text"
onChange={onQueryTextChange}
value={dimension || ''}
placeholder="Specific dimension to return, empty for all"
type="text"
/>
</InlineField>
</Stack>
);
}
Problem is that if I go to test these changes via the explore
tab, the run query
button doesn’t seem to fire. The API that returns data certainly doesn’t fire like if I set dimension
to something.
Now, the obvious work around here is to use some kind of placeholder that the backend can ignore, like maybe dimension: all
but that feels both fragile, and like I just don’t really know what I’m doing. So I’d like to avoid it.
Can anybody point me in the right direction?