mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
QueryEditorRows: Remove double callback from onDataSourceChange (#62172)
* QueryEditorRows: Remove double callbacked from onDataSourceChange * A few more updates * Updated
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { createSelector } from '@reduxjs/toolkit';
|
import { createSelector } from '@reduxjs/toolkit';
|
||||||
import React, { useCallback, useMemo } from 'react';
|
import React, { useCallback, useMemo } from 'react';
|
||||||
|
|
||||||
import { CoreApp, DataSourceInstanceSettings } from '@grafana/data';
|
import { CoreApp } from '@grafana/data';
|
||||||
import { getDataSourceSrv, reportInteraction } from '@grafana/runtime';
|
import { getDataSourceSrv, reportInteraction } from '@grafana/runtime';
|
||||||
import { DataQuery } from '@grafana/schema';
|
import { DataQuery } from '@grafana/schema';
|
||||||
import { getNextRefIdChar } from 'app/core/utils/query';
|
import { getNextRefIdChar } from 'app/core/utils/query';
|
||||||
@@ -50,9 +50,19 @@ export const QueryRows = ({ exploreId }: Props) => {
|
|||||||
}, [dispatch, exploreId]);
|
}, [dispatch, exploreId]);
|
||||||
|
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(newQueries: DataQuery[]) => {
|
async (newQueries: DataQuery[]) => {
|
||||||
dispatch(changeQueriesAction({ queries: newQueries, exploreId }));
|
dispatch(changeQueriesAction({ queries: newQueries, exploreId }));
|
||||||
|
|
||||||
|
for (const newQuery of newQueries) {
|
||||||
|
for (const oldQuery of queries) {
|
||||||
|
if (newQuery.refId === oldQuery.refId && newQuery.datasource?.type !== oldQuery.datasource?.type) {
|
||||||
|
const queryDatasource = await getDataSourceSrv().get(newQuery.datasource);
|
||||||
|
const targetDS = await getDataSourceSrv().get({ uid: newQuery.datasource?.uid });
|
||||||
|
dispatch(importQueries(exploreId, queries, queryDatasource, targetDS, newQuery.refId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if we are removing a query we want to run the remaining ones
|
// if we are removing a query we want to run the remaining ones
|
||||||
if (newQueries.length < queries.length) {
|
if (newQueries.length < queries.length) {
|
||||||
onRunQueries();
|
onRunQueries();
|
||||||
@@ -68,12 +78,6 @@ export const QueryRows = ({ exploreId }: Props) => {
|
|||||||
[onChange, queries]
|
[onChange, queries]
|
||||||
);
|
);
|
||||||
|
|
||||||
const onMixedDataSourceChange = async (ds: DataSourceInstanceSettings, query: DataQuery) => {
|
|
||||||
const queryDatasource = await getDataSourceSrv().get(query.datasource);
|
|
||||||
const targetDS = await getDataSourceSrv().get({ uid: ds.uid });
|
|
||||||
dispatch(importQueries(exploreId, queries, queryDatasource, targetDS, query.refId));
|
|
||||||
};
|
|
||||||
|
|
||||||
const onQueryCopied = () => {
|
const onQueryCopied = () => {
|
||||||
reportInteraction('grafana_explore_query_row_copy');
|
reportInteraction('grafana_explore_query_row_copy');
|
||||||
};
|
};
|
||||||
@@ -89,7 +93,6 @@ export const QueryRows = ({ exploreId }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<QueryEditorRows
|
<QueryEditorRows
|
||||||
dsSettings={dsSettings}
|
dsSettings={dsSettings}
|
||||||
onDatasourceChange={(ds: DataSourceInstanceSettings, query: DataQuery) => onMixedDataSourceChange(ds, query)}
|
|
||||||
queries={queries}
|
queries={queries}
|
||||||
onQueriesChange={onChange}
|
onQueriesChange={onChange}
|
||||||
onAddQuery={onAddQuery}
|
onAddQuery={onAddQuery}
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ interface Props {
|
|||||||
onQueryCopied?: () => void;
|
onQueryCopied?: () => void;
|
||||||
onQueryRemoved?: () => void;
|
onQueryRemoved?: () => void;
|
||||||
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
|
onQueryToggled?: (queryStatus?: boolean | undefined) => void;
|
||||||
onDatasourceChange?: (dataSource: DataSourceInstanceSettings, query: DataQuery) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class QueryEditorRows extends PureComponent<Props> {
|
export class QueryEditorRows extends PureComponent<Props> {
|
||||||
@@ -59,10 +58,6 @@ export class QueryEditorRows extends PureComponent<Props> {
|
|||||||
onDataSourceChange(dataSource: DataSourceInstanceSettings, index: number) {
|
onDataSourceChange(dataSource: DataSourceInstanceSettings, index: number) {
|
||||||
const { queries, onQueriesChange } = this.props;
|
const { queries, onQueriesChange } = this.props;
|
||||||
|
|
||||||
if (this.props.onDatasourceChange) {
|
|
||||||
this.props.onDatasourceChange(dataSource, queries[index]);
|
|
||||||
}
|
|
||||||
|
|
||||||
onQueriesChange(
|
onQueriesChange(
|
||||||
queries.map((item, itemIndex) => {
|
queries.map((item, itemIndex) => {
|
||||||
if (itemIndex !== index) {
|
if (itemIndex !== index) {
|
||||||
|
|||||||
Reference in New Issue
Block a user