grafana/public/app/features/query/components/QueryActionComponent.ts
Travis Patterson 3fb8b87972
Add on datasource change to optional components -- alt -- (#40239)
* Add onDataSourceChange to optional components

- Fixes a bug where the user can select  twice and overwrite all queries
- Adds handler to control main datasoruce selection to the optional components.

* only pass onDatasource change when necessary
2021-10-13 09:49:40 -06:00

35 lines
937 B
TypeScript

import { DataQuery, DataSourceInstanceSettings, TimeRange } from '@grafana/data';
interface ActionComponentProps {
query?: DataQuery;
queries?: Array<Partial<DataQuery>>;
onAddQuery?: (q: DataQuery) => void;
onChangeDataSource?: (ds: DataSourceInstanceSettings) => void;
timeRange?: TimeRange;
dataSource?: DataSourceInstanceSettings;
}
type QueryActionComponent = React.ComponentType<ActionComponentProps>;
class QueryActionComponents {
extraRenderActions: QueryActionComponent[] = [];
addExtraRenderAction(extra: QueryActionComponent) {
this.extraRenderActions = this.extraRenderActions.concat(extra);
}
getAllExtraRenderAction(): QueryActionComponent[] {
return this.extraRenderActions;
}
}
/**
* @internal and experimental
*/
export const GroupActionComponents = new QueryActionComponents();
/**
* @internal and experimental
*/
export const RowActionComponents = new QueryActionComponents();