|
@@ -4,6 +4,9 @@ import React, { Component } from 'react';
|
|
|
// Services
|
|
// Services
|
|
|
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
|
|
|
|
|
|
|
|
|
+// Utils
|
|
|
|
|
+import kbn from 'app/core/utils/kbn';
|
|
|
|
|
+
|
|
|
// Types
|
|
// Types
|
|
|
import { TimeRange, LoadingState, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types';
|
|
import { TimeRange, LoadingState, DataQueryOptions, DataQueryResponse, TimeSeries } from 'app/types';
|
|
|
|
|
|
|
@@ -19,7 +22,10 @@ export interface Props {
|
|
|
dashboardId?: number;
|
|
dashboardId?: number;
|
|
|
isVisible?: boolean;
|
|
isVisible?: boolean;
|
|
|
timeRange?: TimeRange;
|
|
timeRange?: TimeRange;
|
|
|
|
|
+ widthPixels: number;
|
|
|
refreshCounter: number;
|
|
refreshCounter: number;
|
|
|
|
|
+ minInterval?: string;
|
|
|
|
|
+ maxDataPoints?: number;
|
|
|
children: (r: RenderProps) => JSX.Element;
|
|
children: (r: RenderProps) => JSX.Element;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -30,6 +36,8 @@ export interface State {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export class DataPanel extends Component<Props, State> {
|
|
export class DataPanel extends Component<Props, State> {
|
|
|
|
|
+ dataSourceSrv = getDatasourceSrv();
|
|
|
|
|
+
|
|
|
static defaultProps = {
|
|
static defaultProps = {
|
|
|
isVisible: true,
|
|
isVisible: true,
|
|
|
panelId: 1,
|
|
panelId: 1,
|
|
@@ -49,7 +57,7 @@ export class DataPanel extends Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
componentDidMount() {
|
|
|
- console.log('DataPanel mount');
|
|
|
|
|
|
|
+ this.issueQueries();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
async componentDidUpdate(prevProps: Props) {
|
|
async componentDidUpdate(prevProps: Props) {
|
|
@@ -61,11 +69,11 @@ export class DataPanel extends Component<Props, State> {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
hasPropsChanged(prevProps: Props) {
|
|
hasPropsChanged(prevProps: Props) {
|
|
|
- return this.props.refreshCounter !== prevProps.refreshCounter || this.props.isVisible !== prevProps.isVisible;
|
|
|
|
|
|
|
+ return this.props.refreshCounter !== prevProps.refreshCounter;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
issueQueries = async () => {
|
|
issueQueries = async () => {
|
|
|
- const { isVisible, queries, datasource, panelId, dashboardId, timeRange } = this.props;
|
|
|
|
|
|
|
+ const { isVisible, queries, datasource, panelId, dashboardId, timeRange, widthPixels, maxDataPoints } = this.props;
|
|
|
|
|
|
|
|
if (!isVisible) {
|
|
if (!isVisible) {
|
|
|
return;
|
|
return;
|
|
@@ -79,18 +87,22 @@ export class DataPanel extends Component<Props, State> {
|
|
|
this.setState({ loading: LoadingState.Loading });
|
|
this.setState({ loading: LoadingState.Loading });
|
|
|
|
|
|
|
|
try {
|
|
try {
|
|
|
- const dataSourceSrv = getDatasourceSrv();
|
|
|
|
|
- const ds = await dataSourceSrv.get(datasource);
|
|
|
|
|
|
|
+ const ds = await this.dataSourceSrv.get(datasource);
|
|
|
|
|
+
|
|
|
|
|
+ // TODO interpolate variables
|
|
|
|
|
+ const minInterval = this.props.minInterval || ds.interval;
|
|
|
|
|
+ const intervalRes = kbn.calculateInterval(timeRange, widthPixels, minInterval);
|
|
|
|
|
+
|
|
|
const queryOptions: DataQueryOptions = {
|
|
const queryOptions: DataQueryOptions = {
|
|
|
timezone: 'browser',
|
|
timezone: 'browser',
|
|
|
panelId: panelId,
|
|
panelId: panelId,
|
|
|
dashboardId: dashboardId,
|
|
dashboardId: dashboardId,
|
|
|
range: timeRange,
|
|
range: timeRange,
|
|
|
rangeRaw: timeRange.raw,
|
|
rangeRaw: timeRange.raw,
|
|
|
- interval: '1s',
|
|
|
|
|
- intervalMs: 60000,
|
|
|
|
|
|
|
+ interval: intervalRes.interval,
|
|
|
|
|
+ intervalMs: intervalRes.intervalMs,
|
|
|
targets: queries,
|
|
targets: queries,
|
|
|
- maxDataPoints: 500,
|
|
|
|
|
|
|
+ maxDataPoints: maxDataPoints || widthPixels,
|
|
|
scopedVars: {},
|
|
scopedVars: {},
|
|
|
cacheTimeout: null,
|
|
cacheTimeout: null,
|
|
|
};
|
|
};
|
|
@@ -111,17 +123,10 @@ export class DataPanel extends Component<Props, State> {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { response, loading, isFirstLoad } = this.state;
|
|
|
|
|
- console.log('data panel render');
|
|
|
|
|
|
|
+ const { response, loading } = this.state;
|
|
|
const timeSeries = response.data;
|
|
const timeSeries = response.data;
|
|
|
|
|
|
|
|
- if (isFirstLoad && (loading === LoadingState.Loading || loading === LoadingState.NotStarted)) {
|
|
|
|
|
- return (
|
|
|
|
|
- <div className="loading">
|
|
|
|
|
- <p>Loading</p>
|
|
|
|
|
- </div>
|
|
|
|
|
- );
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ console.log('data panel render');
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<>
|
|
<>
|
|
@@ -139,7 +144,7 @@ export class DataPanel extends Component<Props, State> {
|
|
|
|
|
|
|
|
if (loading === LoadingState.Loading) {
|
|
if (loading === LoadingState.Loading) {
|
|
|
return (
|
|
return (
|
|
|
- <div className="panel__loading">
|
|
|
|
|
|
|
+ <div className="panel-loading">
|
|
|
<i className="fa fa-spinner fa-spin" />
|
|
<i className="fa fa-spinner fa-spin" />
|
|
|
</div>
|
|
</div>
|
|
|
);
|
|
);
|