1import { DataSourceInstanceSettings, DataSourcePluginMeta, PluginType } from '@grafana/data'; 2import { ExpressionQuery, ExpressionQueryType } from './types'; 3import { ExpressionQueryEditor } from './ExpressionQueryEditor'; 4import { DataSourceWithBackend } from '@grafana/runtime'; 5import { ExpressionDatasourceRef } from '@grafana/runtime/src/utils/DataSourceWithBackend'; 6 7/** 8 * This is a singleton instance that just pretends to be a DataSource 9 */ 10export class ExpressionDatasourceApi extends DataSourceWithBackend<ExpressionQuery> { 11 constructor(public instanceSettings: DataSourceInstanceSettings) { 12 super(instanceSettings); 13 } 14 15 getCollapsedText(query: ExpressionQuery) { 16 return `Expression: ${query.type}`; 17 } 18 19 newQuery(query?: Partial<ExpressionQuery>): ExpressionQuery { 20 return { 21 refId: '--', // Replaced with query 22 type: query?.type ?? ExpressionQueryType.math, 23 datasource: ExpressionDatasourceRef, 24 conditions: query?.conditions ?? undefined, 25 }; 26 } 27} 28 29/** 30 * MATCHES a constant in DataSourceWithBackend, this should be '__expr__' 31 * @deprecated 32 */ 33export const ExpressionDatasourceUID = '-100'; 34 35export const instanceSettings: DataSourceInstanceSettings = { 36 id: -100, 37 uid: ExpressionDatasourceUID, 38 name: ExpressionDatasourceRef.type, 39 type: ExpressionDatasourceRef.type, 40 access: 'proxy', 41 meta: { 42 baseUrl: '', 43 module: '', 44 type: PluginType.datasource, 45 name: ExpressionDatasourceRef.type, 46 id: ExpressionDatasourceRef.type, 47 info: { 48 author: { 49 name: 'Grafana Labs', 50 }, 51 logos: { 52 small: 'public/img/icn-datasource.svg', 53 large: 'public/img/icn-datasource.svg', 54 }, 55 description: 'Adds expression support to Grafana', 56 screenshots: [], 57 links: [], 58 updated: '', 59 version: '', 60 }, 61 }, 62 jsonData: {}, 63}; 64 65export const dataSource = new ExpressionDatasourceApi(instanceSettings); 66dataSource.meta = { 67 id: ExpressionDatasourceRef.type, 68 info: { 69 logos: { 70 small: 'public/img/icn-datasource.svg', 71 large: 'public/img/icn-datasource.svg', 72 }, 73 }, 74} as DataSourcePluginMeta; 75dataSource.components = { 76 QueryEditor: ExpressionQueryEditor, 77}; 78