|
|
@@ -3,7 +3,6 @@ import ReactGridLayout from 'react-grid-layout';
|
|
|
import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
|
|
|
import { DashboardPanel } from './DashboardPanel';
|
|
|
import { DashboardModel } from '../dashboard_model';
|
|
|
-import { PanelContainer } from './PanelContainer';
|
|
|
import { PanelModel } from '../panel_model';
|
|
|
import classNames from 'classnames';
|
|
|
import sizeMe from 'react-sizeme';
|
|
|
@@ -60,18 +59,15 @@ function GridWrapper({
|
|
|
const SizedReactLayoutGrid = sizeMe({ monitorWidth: true })(GridWrapper);
|
|
|
|
|
|
export interface DashboardGridProps {
|
|
|
- getPanelContainer: () => PanelContainer;
|
|
|
+ dashboard: DashboardModel;
|
|
|
}
|
|
|
|
|
|
export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
gridToPanelMap: any;
|
|
|
- panelContainer: PanelContainer;
|
|
|
- dashboard: DashboardModel;
|
|
|
panelMap: { [id: string]: PanelModel };
|
|
|
|
|
|
constructor(props) {
|
|
|
super(props);
|
|
|
- this.panelContainer = this.props.getPanelContainer();
|
|
|
this.onLayoutChange = this.onLayoutChange.bind(this);
|
|
|
this.onResize = this.onResize.bind(this);
|
|
|
this.onResizeStop = this.onResizeStop.bind(this);
|
|
|
@@ -81,20 +77,20 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
this.state = { animated: false };
|
|
|
|
|
|
// subscribe to dashboard events
|
|
|
- this.dashboard = this.panelContainer.getDashboard();
|
|
|
- this.dashboard.on('panel-added', this.triggerForceUpdate.bind(this));
|
|
|
- this.dashboard.on('panel-removed', this.triggerForceUpdate.bind(this));
|
|
|
- this.dashboard.on('repeats-processed', this.triggerForceUpdate.bind(this));
|
|
|
- this.dashboard.on('view-mode-changed', this.onViewModeChanged.bind(this));
|
|
|
- this.dashboard.on('row-collapsed', this.triggerForceUpdate.bind(this));
|
|
|
- this.dashboard.on('row-expanded', this.triggerForceUpdate.bind(this));
|
|
|
+ let dashboard = this.props.dashboard;
|
|
|
+ dashboard.on('panel-added', this.triggerForceUpdate.bind(this));
|
|
|
+ dashboard.on('panel-removed', this.triggerForceUpdate.bind(this));
|
|
|
+ dashboard.on('repeats-processed', this.triggerForceUpdate.bind(this));
|
|
|
+ dashboard.on('view-mode-changed', this.onViewModeChanged.bind(this));
|
|
|
+ dashboard.on('row-collapsed', this.triggerForceUpdate.bind(this));
|
|
|
+ dashboard.on('row-expanded', this.triggerForceUpdate.bind(this));
|
|
|
}
|
|
|
|
|
|
buildLayout() {
|
|
|
const layout = [];
|
|
|
this.panelMap = {};
|
|
|
|
|
|
- for (let panel of this.dashboard.panels) {
|
|
|
+ for (let panel of this.props.dashboard.panels) {
|
|
|
let stringId = panel.id.toString();
|
|
|
this.panelMap[stringId] = panel;
|
|
|
|
|
|
@@ -129,7 +125,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
this.panelMap[newPos.i].updateGridPos(newPos);
|
|
|
}
|
|
|
|
|
|
- this.dashboard.sortPanelsByGridPos();
|
|
|
+ this.props.dashboard.sortPanelsByGridPos();
|
|
|
}
|
|
|
|
|
|
triggerForceUpdate() {
|
|
|
@@ -137,7 +133,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
}
|
|
|
|
|
|
onWidthChange() {
|
|
|
- for (const panel of this.dashboard.panels) {
|
|
|
+ for (const panel of this.props.dashboard.panels) {
|
|
|
panel.resizeDone();
|
|
|
}
|
|
|
}
|
|
|
@@ -176,11 +172,11 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
renderPanels() {
|
|
|
const panelElements = [];
|
|
|
|
|
|
- for (let panel of this.dashboard.panels) {
|
|
|
+ for (let panel of this.props.dashboard.panels) {
|
|
|
const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
|
|
|
panelElements.push(
|
|
|
<div key={panel.id.toString()} className={panelClasses}>
|
|
|
- <DashboardPanel panel={panel} dashboard={this.dashboard} panelContainer={this.panelContainer} />
|
|
|
+ <DashboardPanel panel={panel} dashboard={this.props.dashboard} />
|
|
|
</div>
|
|
|
);
|
|
|
}
|
|
|
@@ -193,8 +189,8 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
|
|
|
<SizedReactLayoutGrid
|
|
|
className={classNames({ layout: true, animated: this.state.animated })}
|
|
|
layout={this.buildLayout()}
|
|
|
- isResizable={this.dashboard.meta.canEdit}
|
|
|
- isDraggable={this.dashboard.meta.canEdit}
|
|
|
+ isResizable={this.props.dashboard.meta.canEdit}
|
|
|
+ isDraggable={this.props.dashboard.meta.canEdit}
|
|
|
onLayoutChange={this.onLayoutChange}
|
|
|
onWidthChange={this.onWidthChange}
|
|
|
onDragStop={this.onDragStop}
|