Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Datasources: Propagate TestDataDB default selection to PanelModel #57703

Closed
wants to merge 10 commits into from
14 changes: 12 additions & 2 deletions public/app/plugins/datasource/testdata/QueryEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { ChangeEvent, FormEvent, useMemo } from 'react';
import React, { ChangeEvent, FormEvent, useMemo, useEffect } from 'react';
import { useAsync } from 'react-use';

import { QueryEditorProps, SelectableValue } from '@grafana/data';
Expand Down Expand Up @@ -172,6 +172,16 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
);
const showLabels = useMemo(() => showLabelsFor.includes(query.scenarioId ?? ''), [query]);

const selectedValue = options.find((item) => item.value === query.scenarioId);
useEffect(() => {
if (selectedValue) {
// This updates the panel model with the default scenario
onScenarioChange(selectedValue);
}
// Adding a dependency on onScenarioChange causes an infinite loop
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [selectedValue]);

if (loading) {
return null;
}
Expand All @@ -183,7 +193,7 @@ export const QueryEditor = ({ query, datasource, onChange, onRunQuery }: Props)
<Select
inputId={`test-data-scenario-select-${query.refId}`}
options={options}
value={options.find((item) => item.value === query.scenarioId)}
value={selectedValue}
onChange={onScenarioChange}
width={32}
/>
Expand Down