DashboardScene: Reset query variable query and definition on datasource change (#84347)

reset query variable query and definition on datasource change
This commit is contained in:
Sergej-Vlasov 2024-03-13 15:41:03 +02:00 committed by GitHub
parent c0933fa6bb
commit c0d0f13a8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 0 deletions

View File

@ -152,6 +152,8 @@ describe('QueryVariableEditor', () => {
});
expect(variable.state.datasource).toEqual({ uid: 'mock-ds-3', type: 'prometheus' });
expect(variable.state.query).toBe('');
expect(variable.state.definition).toBe('');
});
it('should update the variable state when changing the query', async () => {

View File

@ -36,6 +36,12 @@ export function QueryVariableEditor({ variable, onRunQuery }: QueryVariableEdito
};
const onDataSourceChange = (dsInstanceSettings: DataSourceInstanceSettings) => {
const datasource: DataSourceRef = { uid: dsInstanceSettings.uid, type: dsInstanceSettings.type };
if (variable.state.datasource && variable.state.datasource.type !== datasource.type) {
variable.setState({ datasource, query: '', definition: '' });
return;
}
variable.setState({ datasource });
};
const onQueryChange = (query: VariableQueryType) => {