2018-10-14 08:39:34 -05:00
|
|
|
// Libraries
|
2018-11-20 10:01:58 -06:00
|
|
|
import React, { PureComponent } from 'react';
|
2018-11-13 11:50:12 -06:00
|
|
|
import { AutoSizer } from 'react-virtualized';
|
2018-10-14 08:39:34 -05:00
|
|
|
|
|
|
|
// Services
|
2018-11-08 07:44:12 -06:00
|
|
|
import { getTimeSrv, TimeSrv } from '../time_srv';
|
2018-10-14 08:39:34 -05:00
|
|
|
|
|
|
|
// Components
|
2018-10-25 05:47:09 -05:00
|
|
|
import { PanelHeader } from './PanelHeader/PanelHeader';
|
2018-10-14 08:39:34 -05:00
|
|
|
import { DataPanel } from './DataPanel';
|
|
|
|
|
2018-11-08 07:44:12 -06:00
|
|
|
// Utils
|
2018-11-13 08:05:07 -06:00
|
|
|
import { applyPanelTimeOverrides } from 'app/features/dashboard/utils/panel';
|
2018-11-14 06:20:19 -06:00
|
|
|
import { PANEL_HEADER_HEIGHT } from 'app/core/constants';
|
2018-11-08 07:44:12 -06:00
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
// Types
|
2018-06-19 07:51:57 -05:00
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
|
import { DashboardModel } from '../dashboard_model';
|
2018-12-23 02:15:32 -06:00
|
|
|
import { PanelPlugin } from 'app/types';
|
|
|
|
import { TimeRange } from '@grafana/ui';
|
2018-06-19 07:51:57 -05:00
|
|
|
|
2019-01-14 07:47:41 -06:00
|
|
|
import variables from 'sass/_variables.scss';
|
2019-01-15 10:15:46 -06:00
|
|
|
import templateSrv from 'app/features/templating/template_srv';
|
2019-01-14 07:47:41 -06:00
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export interface Props {
|
2018-06-19 07:51:57 -05:00
|
|
|
panel: PanelModel;
|
|
|
|
dashboard: DashboardModel;
|
2018-11-20 10:01:58 -06:00
|
|
|
plugin: PanelPlugin;
|
2018-06-19 07:51:57 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export interface State {
|
2018-10-14 08:39:34 -05:00
|
|
|
refreshCounter: number;
|
2018-11-05 10:46:09 -06:00
|
|
|
renderCounter: number;
|
2018-11-13 08:05:07 -06:00
|
|
|
timeInfo?: string;
|
2018-10-14 08:39:34 -05:00
|
|
|
timeRange?: TimeRange;
|
|
|
|
}
|
2018-07-05 15:10:39 -05:00
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
export class PanelChrome extends PureComponent<Props, State> {
|
2018-11-08 07:44:12 -06:00
|
|
|
timeSrv: TimeSrv = getTimeSrv();
|
|
|
|
|
2018-06-19 07:51:57 -05:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2018-11-06 09:37:51 -06:00
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
this.state = {
|
|
|
|
refreshCounter: 0,
|
2018-11-05 10:46:09 -06:00
|
|
|
renderCounter: 0,
|
2018-10-14 08:39:34 -05:00
|
|
|
};
|
2018-07-05 15:10:39 -05:00
|
|
|
}
|
|
|
|
|
2018-11-06 09:37:51 -06:00
|
|
|
componentDidMount() {
|
2018-10-14 08:39:34 -05:00
|
|
|
this.props.panel.events.on('refresh', this.onRefresh);
|
2018-11-05 10:46:09 -06:00
|
|
|
this.props.panel.events.on('render', this.onRender);
|
2018-10-14 09:31:20 -05:00
|
|
|
this.props.dashboard.panelInitialized(this.props.panel);
|
2018-10-14 08:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
|
|
|
this.props.panel.events.off('refresh', this.onRefresh);
|
|
|
|
}
|
|
|
|
|
|
|
|
onRefresh = () => {
|
2018-11-08 07:44:12 -06:00
|
|
|
console.log('onRefresh');
|
|
|
|
if (!this.isVisible) {
|
|
|
|
return;
|
|
|
|
}
|
2018-11-12 04:23:41 -06:00
|
|
|
|
2018-11-08 07:44:12 -06:00
|
|
|
const { panel } = this.props;
|
2018-11-13 08:05:07 -06:00
|
|
|
const timeData = applyPanelTimeOverrides(panel, this.timeSrv.timeRange());
|
2018-07-09 15:24:15 -05:00
|
|
|
|
2018-11-13 08:05:07 -06:00
|
|
|
this.setState({
|
2018-10-14 08:39:34 -05:00
|
|
|
refreshCounter: this.state.refreshCounter + 1,
|
2018-11-13 08:05:07 -06:00
|
|
|
timeRange: timeData.timeRange,
|
|
|
|
timeInfo: timeData.timeInfo,
|
|
|
|
});
|
2018-10-14 08:39:34 -05:00
|
|
|
};
|
2018-07-09 15:24:15 -05:00
|
|
|
|
2018-11-05 10:46:09 -06:00
|
|
|
onRender = () => {
|
2018-11-13 08:05:07 -06:00
|
|
|
this.setState({
|
2018-11-06 09:37:51 -06:00
|
|
|
renderCounter: this.state.renderCounter + 1,
|
2018-11-13 08:05:07 -06:00
|
|
|
});
|
2018-11-03 17:36:40 -05:00
|
|
|
};
|
|
|
|
|
2019-01-15 10:15:46 -06:00
|
|
|
onInterpolate = (value: string, format?: string) => {
|
|
|
|
return templateSrv.replace(value, this.props.panel.scopedVars, format);
|
|
|
|
};
|
|
|
|
|
2018-10-14 08:39:34 -05:00
|
|
|
get isVisible() {
|
2018-10-14 09:31:20 -05:00
|
|
|
return !this.props.dashboard.otherPanelInFullscreen(this.props.panel);
|
2018-10-14 08:39:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-11-20 10:01:58 -06:00
|
|
|
const { panel, dashboard, plugin } = this.props;
|
2018-11-12 04:23:41 -06:00
|
|
|
const { refreshCounter, timeRange, timeInfo, renderCounter } = this.state;
|
2018-11-06 08:03:56 -06:00
|
|
|
|
2018-12-06 03:34:27 -06:00
|
|
|
const { datasource, targets, transparent } = panel;
|
2018-11-20 10:01:58 -06:00
|
|
|
const PanelComponent = plugin.exports.Panel;
|
2018-12-06 03:34:27 -06:00
|
|
|
const containerClassNames = `panel-container panel-container--absolute ${transparent ? 'panel-transparent' : ''}`;
|
2018-06-19 07:51:57 -05:00
|
|
|
return (
|
2018-11-14 05:03:25 -06:00
|
|
|
<AutoSizer>
|
|
|
|
{({ width, height }) => {
|
|
|
|
if (width === 0) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2018-12-06 03:34:27 -06:00
|
|
|
<div className={containerClassNames}>
|
2018-12-05 07:57:57 -06:00
|
|
|
<PanelHeader
|
|
|
|
panel={panel}
|
|
|
|
dashboard={dashboard}
|
|
|
|
timeInfo={timeInfo}
|
|
|
|
title={panel.title}
|
|
|
|
description={panel.description}
|
|
|
|
scopedVars={panel.scopedVars}
|
|
|
|
links={panel.links}
|
|
|
|
/>
|
|
|
|
|
2018-11-13 11:50:12 -06:00
|
|
|
<DataPanel
|
|
|
|
datasource={datasource}
|
|
|
|
queries={targets}
|
|
|
|
timeRange={timeRange}
|
|
|
|
isVisible={this.isVisible}
|
|
|
|
widthPixels={width}
|
|
|
|
refreshCounter={refreshCounter}
|
|
|
|
>
|
2019-01-08 06:32:08 -06:00
|
|
|
{({ loading, timeSeries }) => {
|
2018-11-13 11:50:12 -06:00
|
|
|
return (
|
2018-11-14 06:20:19 -06:00
|
|
|
<div className="panel-content">
|
|
|
|
<PanelComponent
|
|
|
|
loading={loading}
|
|
|
|
timeSeries={timeSeries}
|
|
|
|
timeRange={timeRange}
|
2018-11-20 10:01:58 -06:00
|
|
|
options={panel.getOptions(plugin.exports.PanelDefaults)}
|
2019-01-15 10:15:46 -06:00
|
|
|
width={width - 2 * variables.panelHorizontalPadding}
|
2019-01-14 07:47:41 -06:00
|
|
|
height={height - PANEL_HEADER_HEIGHT - variables.panelVerticalPadding}
|
2018-11-14 06:20:19 -06:00
|
|
|
renderCounter={renderCounter}
|
2019-01-15 10:15:46 -06:00
|
|
|
onInterpolate={this.onInterpolate}
|
2018-11-14 06:20:19 -06:00
|
|
|
/>
|
|
|
|
</div>
|
2018-11-13 11:50:12 -06:00
|
|
|
);
|
|
|
|
}}
|
|
|
|
</DataPanel>
|
2018-11-14 05:03:25 -06:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
</AutoSizer>
|
2018-06-19 07:51:57 -05:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|