mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
InfluxDB: Fix custom variable support (#88642)
* fix variable support * prettier
This commit is contained in:
parent
043e19afb5
commit
f458e57523
@ -13,7 +13,7 @@ type Props = QueryEditorProps<InfluxDatasource, InfluxQuery, InfluxOptions, Infl
|
|||||||
const refId = 'InfluxVariableQueryEditor-VariableQuery';
|
const refId = 'InfluxVariableQueryEditor-VariableQuery';
|
||||||
|
|
||||||
export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) => {
|
export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) => {
|
||||||
const getFluxVariableQuery = (q: InfluxVariableQuery | string) => {
|
const getVariableQuery = (q: InfluxVariableQuery | string) => {
|
||||||
// in legacy variable support query can be only a string
|
// in legacy variable support query can be only a string
|
||||||
// in new variable support query can be an object and hold more information
|
// in new variable support query can be an object and hold more information
|
||||||
// to be able to support old version we check the query here
|
// to be able to support old version we check the query here
|
||||||
@ -24,7 +24,7 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
|
|||||||
return {
|
return {
|
||||||
refId,
|
refId,
|
||||||
query: q,
|
query: q,
|
||||||
maxDataPoints: 1000,
|
...(datasource.version === InfluxVersion.Flux ? { maxDataPoints: 1000 } : {}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
|
|||||||
<>
|
<>
|
||||||
<FluxQueryEditor
|
<FluxQueryEditor
|
||||||
datasource={datasource}
|
datasource={datasource}
|
||||||
query={getFluxVariableQuery(query)}
|
query={getVariableQuery(query)}
|
||||||
onChange={(q) => {
|
onChange={(q) => {
|
||||||
onChange({ ...query, query: q.query ?? '' });
|
onChange({ ...query, query: q.query ?? '' });
|
||||||
}}
|
}}
|
||||||
@ -72,11 +72,11 @@ export const InfluxVariableEditor = ({ onChange, datasource, query }: Props) =>
|
|||||||
<InlineField label="Query" labelWidth={20} required grow aria-labelledby="influx-variable-query">
|
<InlineField label="Query" labelWidth={20} required grow aria-labelledby="influx-variable-query">
|
||||||
<TextArea
|
<TextArea
|
||||||
aria-label="influx-variable-query"
|
aria-label="influx-variable-query"
|
||||||
defaultValue={query.query}
|
defaultValue={getVariableQuery(query).query}
|
||||||
placeholder="metric name or tags query"
|
placeholder="metric name or tags query"
|
||||||
rows={1}
|
rows={1}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
onChange({ refId, query: query.query ?? '' });
|
onChange({ refId, query: e.currentTarget.value ?? '' });
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</InlineField>
|
</InlineField>
|
||||||
|
@ -30,7 +30,9 @@ export class InfluxVariableSupport extends CustomVariableSupport<InfluxDatasourc
|
|||||||
return of({ data: [] });
|
return of({ data: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
const interpolated = this.templateSrv.replace(query, request.scopedVars, this.datasource.interpolateQueryExpr);
|
const q = this.templateSrv.replace(query, request.scopedVars, this.datasource.interpolateQueryExpr);
|
||||||
|
const timeFilter = this.datasource.getTimeFilter({ rangeRaw: request.range.raw, timezone: request.timezone });
|
||||||
|
const interpolated = q.replace('$timeFilter', timeFilter);
|
||||||
const metricFindStream = from(
|
const metricFindStream = from(
|
||||||
this.datasource.metricFindQuery(
|
this.datasource.metricFindQuery(
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user