Commit d3def115 by Torkel Ödegaard Committed by GitHub

TestData: Remove useEffect that triggeres query on component load (#28321)

* TestData: Remove useEffect that triggeres query on component load

* Updated

* Update e2e spec
parent 84992adf
......@@ -11,9 +11,20 @@ e2e.scenario({
e2e.pages.Explore.General.container().should('have.length', 1);
e2e.pages.Explore.General.runButton().should('have.length', 1);
e2e.components.DataSource.TestData.QueryTab.scenarioSelectContainer()
.should('be.visible')
.within(() => {
e2e.components.Select.input()
.should('be.visible')
.click();
cy.contains('CSV Metric Values')
.scrollIntoView()
.should('be.visible')
.click();
});
const canvases = e2e().get('canvas');
canvases.should('have.length', 2);
e2e.components.DataSource.TestData.QueryTab.noise().should('have.length', 1);
},
});
// Libraries
import React, { ChangeEvent, FormEvent, useMemo, useEffect } from 'react';
import React, { ChangeEvent, FormEvent, useMemo } from 'react';
import { useAsync } from 'react-use';
// Components
......@@ -46,10 +46,6 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
onRunQuery();
};
useEffect(() => {
onUpdate(query);
}, []);
const currentScenario = useMemo(() => scenarioList?.find(scenario => scenario.id === query.scenarioId), [
scenarioList,
query,
......
......@@ -29,6 +29,8 @@ import { getSearchFilterScopedVar } from 'app/features/variables/utils';
type TestData = TimeSeries | TableData;
export class TestDataDataSource extends DataSourceApi<TestDataQuery> {
scenariosCache?: Promise<Scenario[]>;
constructor(
instanceSettings: DataSourceInstanceSettings,
private readonly templateSrv: TemplateSrv = getTemplateSrv()
......@@ -169,7 +171,11 @@ export class TestDataDataSource extends DataSourceApi<TestDataQuery> {
}
getScenarios(): Promise<Scenario[]> {
return getBackendSrv().get('/api/tsdb/testdata/scenarios');
if (!this.scenariosCache) {
this.scenariosCache = getBackendSrv().get('/api/tsdb/testdata/scenarios');
}
return this.scenariosCache;
}
metricFindQuery(query: string, options: any) {
......
......@@ -19,6 +19,7 @@ import {
getFieldDisplayName,
} from '@grafana/data';
import { config } from 'app/core/config';
import { SeriesOptions, GraphOptions, GraphLegendEditorLegendOptions } from './types';
export const getGraphSeriesModel = (
......@@ -38,6 +39,7 @@ export const getGraphSeriesModel = (
decimals: legendOptions.decimals,
},
},
theme: config.theme,
timeZone,
});
......@@ -104,7 +106,7 @@ export const getGraphSeriesModel = (
}
: { ...field.config, color };
field.display = getDisplayProcessor({ field, timeZone });
field.display = getDisplayProcessor({ field, timeZone, theme: config.theme });
// Time step is used to determine bars width when graph is rendered as bar chart
const timeStep = getSeriesTimeStep(timeField);
......@@ -119,6 +121,7 @@ export const getGraphSeriesModel = (
unit: systemDateFormats.getTimeFieldUnit(useMsDateFormat),
},
},
theme: config.theme,
});
graphs.push({
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment