mirror of
https://github.com/grafana/grafana.git
synced 2024-12-02 13:39:19 -06:00
Further refinements of typings
This commit is contained in:
parent
5d17ad1103
commit
5ab9a7c2b8
@ -3,11 +3,6 @@ import { PanelProps, PanelOptionsProps } from './panel';
|
|||||||
import { DataQueryOptions, DataQuery, DataQueryResponse, QueryHint } from './datasource';
|
import { DataQueryOptions, DataQuery, DataQueryResponse, QueryHint } from './datasource';
|
||||||
|
|
||||||
export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
|
export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
|
||||||
// set externally by grafana
|
|
||||||
name?: string;
|
|
||||||
meta?: PluginMeta;
|
|
||||||
pluginExports?: PluginExports;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* min interval range
|
* min interval range
|
||||||
*/
|
*/
|
||||||
@ -37,19 +32,26 @@ export interface DataSourceApi<TQuery extends DataQuery = DataQuery> {
|
|||||||
* Get hints for query improvements
|
* Get hints for query improvements
|
||||||
*/
|
*/
|
||||||
getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[];
|
getQueryHints?(query: TQuery, results: any[], ...rest: any): QueryHint[];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set after constructor is called by Grafana
|
||||||
|
*/
|
||||||
|
name?: string;
|
||||||
|
meta?: PluginMeta;
|
||||||
|
pluginExports?: PluginExports;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface QueryEditorProps<DSType extends DataSourceApi = DataSourceApi, TQuery extends DataQuery = DataQuery> {
|
export interface QueryEditorProps<DSType extends DataSourceApi, TQuery extends DataQuery> {
|
||||||
datasource: DSType;
|
datasource: DSType;
|
||||||
query: TQuery;
|
query: TQuery;
|
||||||
onExecuteQuery?: () => void;
|
onExecuteQuery?: () => void;
|
||||||
onQueryChange?: (value: DataQuery) => void;
|
onQueryChange?: (value: TQuery) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PluginExports {
|
export interface PluginExports {
|
||||||
Datasource?: any;
|
Datasource?: DataSourceApi;
|
||||||
QueryCtrl?: any;
|
QueryCtrl?: any;
|
||||||
QueryEditor?: ComponentClass<QueryEditorProps>;
|
QueryEditor?: ComponentClass<QueryEditorProps<DataSourceApi,DataQuery>>;
|
||||||
ConfigCtrl?: any;
|
ConfigCtrl?: any;
|
||||||
AnnotationsQueryCtrl?: any;
|
AnnotationsQueryCtrl?: any;
|
||||||
VariableQueryEditor?: any;
|
VariableQueryEditor?: any;
|
||||||
|
@ -29,11 +29,12 @@ export class QueryEditor extends PureComponent<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
async componentDidMount() {
|
async componentDidMount() {
|
||||||
const { query } = this.props;
|
const { query, datasource } = this.props;
|
||||||
|
|
||||||
query.scenarioId = query.scenarioId || 'random_walk';
|
query.scenarioId = query.scenarioId || 'random_walk';
|
||||||
|
|
||||||
const scenarioList = await this.backendSrv.get('/api/tsdb/testdata/scenarios');
|
// const scenarioList = await this.backendSrv.get('/api/tsdb/testdata/scenarios');
|
||||||
|
const scenarioList = await datasource.getScenarios();
|
||||||
const current = _.find(scenarioList, { id: query.scenarioId });
|
const current = _.find(scenarioList, { id: query.scenarioId });
|
||||||
|
|
||||||
this.setState({ scenarioList: scenarioList, current: current });
|
this.setState({ scenarioList: scenarioList, current: current });
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import TableModel from 'app/core/table_model';
|
import TableModel from 'app/core/table_model';
|
||||||
import { DataSourceApi, DataQueryOptions } from '@grafana/ui';
|
import { DataSourceApi, DataQueryOptions } from '@grafana/ui';
|
||||||
import { TestDataQuery } from './types';
|
import { TestDataQuery, Scenario } from './types';
|
||||||
|
|
||||||
export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
|
export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
|
||||||
id: number;
|
id: number;
|
||||||
@ -93,5 +93,9 @@ export class TestDataDatasource implements DataSourceApi<TestDataQuery> {
|
|||||||
message: 'Data source is working',
|
message: 'Data source is working',
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getScenarios(): Promise<Scenario[]> {
|
||||||
|
return this.backendSrv.get('/api/tsdb/testdata/scenarios');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { TestDataDatasource } from './datasource';
|
import { TestDataDatasource } from './datasource';
|
||||||
// import { TestDataQueryCtrl } from './query_ctrl';
|
import { TestDataQueryCtrl } from './query_ctrl';
|
||||||
import { QueryEditor } from './QueryEditor';
|
// import { QueryEditor } from './QueryEditor';
|
||||||
|
|
||||||
class TestDataAnnotationsQueryCtrl {
|
class TestDataAnnotationsQueryCtrl {
|
||||||
annotation: any;
|
annotation: any;
|
||||||
@ -11,8 +11,8 @@ class TestDataAnnotationsQueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export {
|
export {
|
||||||
QueryEditor,
|
// QueryEditor,
|
||||||
TestDataDatasource as Datasource,
|
TestDataDatasource as Datasource,
|
||||||
// TestDataQueryCtrl as QueryCtrl,
|
TestDataQueryCtrl as QueryCtrl,
|
||||||
TestDataAnnotationsQueryCtrl as AnnotationsQueryCtrl,
|
TestDataAnnotationsQueryCtrl as AnnotationsQueryCtrl,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user