grafana/public/app/features/dashboard/dashgrid/PanelChrome.tsx

65 lines
1.8 KiB
TypeScript
Raw Normal View History

2018-06-19 07:51:57 -05:00
import React from 'react';
import $ from 'jquery';
import { PanelModel } from '../panel_model';
import { DashboardModel } from '../dashboard_model';
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN } from 'app/core/constants';
import { PanelHeader } from './PanelHeader';
import { PanelEditor } from './PanelEditor';
const TITLE_HEIGHT = 27;
const PANEL_BORDER = 2;
2018-07-01 10:34:42 -05:00
export interface Props {
2018-06-19 07:51:57 -05:00
panel: PanelModel;
dashboard: DashboardModel;
component: any;
}
2018-07-01 10:34:42 -05:00
export class PanelChrome extends React.Component<Props, any> {
2018-06-19 07:51:57 -05:00
constructor(props) {
super(props);
this.props.panel.events.on('panel-size-changed', this.triggerForceUpdate.bind(this));
}
triggerForceUpdate() {
2018-06-19 10:30:10 -05:00
this.forceUpdate();
2018-06-19 07:51:57 -05:00
}
render() {
let panelContentStyle = {
height: this.getPanelHeight(),
};
let PanelComponent = this.props.component;
return (
<div className="panel-height-helper">
<div className="panel-container">
<PanelHeader panel={this.props.panel} dashboard={this.props.dashboard} />
<div className="panel-content" style={panelContentStyle}>
{<PanelComponent />}
</div>
</div>
2018-06-19 14:25:57 -05:00
{this.props.panel.isEditing && <PanelEditor panel={this.props.panel} dashboard={this.props.dashboard} />}
2018-06-19 07:51:57 -05:00
</div>
);
}
getPanelHeight() {
const panel = this.props.panel;
let height = 0;
if (panel.fullscreen) {
var docHeight = $(window).height();
2018-06-19 14:25:57 -05:00
var editHeight = Math.floor(docHeight * 0.3);
2018-06-19 07:51:57 -05:00
var fullscreenHeight = Math.floor(docHeight * 0.8);
height = panel.isEditing ? editHeight : fullscreenHeight;
} else {
height = panel.gridPos.h * GRID_CELL_HEIGHT + (panel.gridPos.h - 1) * GRID_CELL_VMARGIN;
}
return height - PANEL_BORDER + TITLE_HEIGHT;
}
}