Commit 8e85295b by Torkel Ödegaard

react panels query processing

parent 543c67a2
import angular from 'angular';
console.log('core module code');
const coreModule = angular.module('grafana.core', ['ngRoute']);
// legacy modules
......
......@@ -5,11 +5,11 @@ import React, { Component } from 'react';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
// Types
import { TimeRange, LoadingState } from 'app/types';
import { TimeRange, LoadingState, DataQueryResponse, TimeSeries } from 'app/types';
interface RenderProps {
loading: LoadingState;
data: any;
timeSeries: TimeSeries[];
}
export interface Props {
......@@ -26,7 +26,7 @@ export interface Props {
export interface State {
isFirstLoad: boolean;
loading: LoadingState;
data: any;
response: DataQueryResponse;
}
export class DataPanel extends Component<Props, State> {
......@@ -41,7 +41,9 @@ export class DataPanel extends Component<Props, State> {
this.state = {
loading: LoadingState.NotStarted,
data: [],
response: {
data: [],
},
isFirstLoad: true,
};
}
......@@ -70,7 +72,7 @@ export class DataPanel extends Component<Props, State> {
}
if (!queries.length) {
this.setState({ data: [], loading: LoadingState.Done });
this.setState({ loading: LoadingState.Done });
return;
}
......@@ -94,9 +96,14 @@ export class DataPanel extends Component<Props, State> {
cacheTimeout: null,
};
console.log('issueing react query', queryOptions);
console.log('Issuing DataPanel query', queryOptions);
const resp = await ds.query(queryOptions);
console.log(resp);
console.log('Issuing DataPanel query Resp', resp);
this.setState({
loading: LoadingState.Done,
response: resp,
});
} catch (err) {
console.log('Loading error', err);
this.setState({ loading: LoadingState.Error });
......@@ -104,8 +111,9 @@ export class DataPanel extends Component<Props, State> {
};
render() {
const { data, loading, isFirstLoad } = this.state;
const { response, loading, isFirstLoad } = this.state;
console.log('data panel render');
const timeSeries = response.data;
if (isFirstLoad && (loading === LoadingState.Loading || loading === LoadingState.NotStarted)) {
return (
......@@ -119,7 +127,7 @@ export class DataPanel extends Component<Props, State> {
<>
{this.loadingSpinner}
{this.props.children({
data,
timeSeries,
loading,
})}
</>
......
......@@ -73,8 +73,8 @@ export class PanelChrome extends PureComponent<Props, State> {
isVisible={this.isVisible}
refreshCounter={refreshCounter}
>
{({ loading, data }) => {
return <PanelComponent loading={loading} data={data} />;
{({ loading, timeSeries }) => {
return <PanelComponent loading={loading} timeSeries={timeSeries} />;
}}
</DataPanel>
</div>
......
// Libraries
import _ from 'lodash';
import coreModule from 'app/core/core_module';
// Utils
import config from 'app/core/config';
import { importPluginModule } from './plugin_loader';
// Types
import { DataSourceApi } from 'app/types/series';
export class DatasourceSrv {
datasources: any;
......@@ -15,7 +21,7 @@ export class DatasourceSrv {
this.datasources = {};
}
get(name?) {
get(name?): Promise<DataSourceApi> {
if (!name) {
return this.get(config.defaultDatasource);
}
......
......@@ -179,6 +179,7 @@ class GraphCtrl extends MetricsPanelCtrl {
}
onDataReceived(dataList) {
console.log(dataList);
this.dataList = dataList;
this.seriesList = this.processor.getSeriesList({
dataList: dataList,
......
// Libraries
import _ from 'lodash';
import React, { PureComponent } from 'react';
// Types
import { PanelProps } from 'app/types';
interface Options {
......@@ -15,16 +19,24 @@ export class Graph2 extends PureComponent<Props> {
}
render() {
const { data } = this.props;
let value = 0;
if (data.length) {
value = data[0].value;
}
console.log('graph2 render');
return <h2>Text Panel {value}</h2>;
const { timeSeries } = this.props;
let index = 0;
return (
<table className="filter-table">
<tbody>
{timeSeries.map(series => {
return (
<tr key={index++}>
<td>{series.target}</td>
<td>{series.datapoints[0][0]}</td>
<td>{series.datapoints[0][1]}</td>
</tr>
);
})}
</tbody>
</table>
);
}
}
......
......@@ -7,14 +7,7 @@ export class Text2 extends PureComponent<PanelProps> {
}
render() {
const { data } = this.props;
let value = 0;
if (data.length) {
value = data[0].value;
}
return <h2>Text Panel! {value}</h2>;
return <h2>Text Panel!</h2>;
}
}
......
......@@ -9,7 +9,7 @@ import { ApiKey, ApiKeysState, NewApiKey } from './apiKeys';
import { Invitee, OrgUser, User, UsersState } from './user';
import { DataSource, DataSourcesState } from './datasources';
import { PluginMeta, Plugin, PluginsState } from './plugins';
import { TimeRange, LoadingState } from './queries';
import { TimeRange, LoadingState, TimeSeries, DataQuery, DataQueryResponse, DataQueryOptions } from './series';
import { PanelProps } from './panel';
export {
......@@ -50,6 +50,10 @@ export {
TimeRange,
LoadingState,
PanelProps,
TimeSeries,
DataQuery,
DataQueryResponse,
DataQueryOptions,
};
export interface StoreState {
......
import { LoadingState } from './queries';
import { LoadingState, TimeSeries } from './series';
export interface PanelProps {
data: any;
timeSeries: TimeSeries[];
loading: LoadingState;
}
......@@ -17,3 +17,34 @@ export interface TimeRange {
to: Moment;
raw: RawTimeRange;
}
export type TimeSeriesValue = string | number | null;
export type TimeSeriesPoints = TimeSeriesValue[][];
export interface TimeSeries {
target: string;
datapoints: TimeSeriesPoints;
}
export interface DataQueryResponse {
data: TimeSeries[];
}
export interface DataQuery {
refId: string;
}
export interface DataQueryOptions {
timezone: string;
range: TimeRange;
rangeRaw: RawTimeRange;
targets: DataQuery[];
panelId: number;
dashboardId: number;
cacheTimeout?: string;
}
export interface DataSourceApi {
query(options: DataQueryOptions): Promise<DataQueryResponse>;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment