grafana/public/app/features/expressions/ExpressionDatasource.ts
Peter Holmberg 569fb3f112
Alerting: adding query editor when creating threshold rule. (#33123)
* fix viz

* add datasource picker on query rows in mixed mode

* add timerange, handle add/remove queryrunners

* multiqueryrunner test

* trying things out.

* adding another test to verify running a induvidual query runner will update multirunner.

* cleaned up tests a bit.

* draft version working ok.

* fixing so we base the refId from request targets.

* reenable adding expression

* layout fixes for alerting page

* some cleanup

* cleaning up code that we won't use

* changed so we don't display the time range if params not passed.

* remove unused things in querygroup

* changed button to type button.

* removed timerange from dataQuery and removed multiquery runner.

* minor refactoring.

* renamed callback function to make it more clear what it does.

* renamed droppable area.

* changed so we only display the query editor when selecting threshold.

* removed the refresh picker.

* revert

* wip

* extending with data query.

* timerange fixes

* it is now possible to add grafana queries.

* removed unused type.

* removed expect import.

* added docs.

* moved range converting methods to rangeUtil.

* clean up some typings, remove file

* making sure we don't blow up on component being unmounted.

Co-authored-by: Marcus Andersson <marcus.andersson@grafana.com>
2021-04-21 13:57:17 +02:00

48 lines
1.4 KiB
TypeScript

import { DataSourceInstanceSettings, DataSourcePluginMeta } from '@grafana/data';
import { ExpressionQuery, ExpressionQueryType } from './types';
import { ExpressionQueryEditor } from './ExpressionQueryEditor';
import { DataSourceWithBackend } from '@grafana/runtime';
/**
* This is a singleton instance that just pretends to be a DataSource
*/
export class ExpressionDatasourceApi extends DataSourceWithBackend<ExpressionQuery> {
constructor(instanceSettings: DataSourceInstanceSettings) {
super(instanceSettings);
}
getCollapsedText(query: ExpressionQuery) {
return `Expression: ${query.type}`;
}
newQuery(query?: Partial<ExpressionQuery>): ExpressionQuery {
return {
refId: '--', // Replaced with query
type: query?.type ?? ExpressionQueryType.math,
datasource: ExpressionDatasourceID,
conditions: query?.conditions ?? undefined,
};
}
}
// MATCHES the constant in DataSourceWithBackend
export const ExpressionDatasourceID = '__expr__';
export const ExpressionDatasourceUID = '-100';
export const expressionDatasource = new ExpressionDatasourceApi({
id: -100,
name: ExpressionDatasourceID,
} as DataSourceInstanceSettings);
expressionDatasource.meta = {
id: ExpressionDatasourceID,
info: {
logos: {
small: 'public/img/icn-datasource.svg',
large: 'public/img/icn-datasource.svg',
},
},
} as DataSourcePluginMeta;
expressionDatasource.components = {
QueryEditor: ExpressionQueryEditor,
};