Commit 71658d1e by Torkel Ödegaard

grid: disable resize and drag on non editable dashboards, closes #10235

parent 4112abd6
...@@ -76,7 +76,7 @@ ...@@ -76,7 +76,7 @@
"postcss-browser-reporter": "^0.5.0", "postcss-browser-reporter": "^0.5.0",
"postcss-loader": "^2.0.6", "postcss-loader": "^2.0.6",
"postcss-reporter": "^5.0.0", "postcss-reporter": "^5.0.0",
"prettier": "1.7.3", "prettier": "1.9.2",
"react-test-renderer": "^16.0.0", "react-test-renderer": "^16.0.0",
"sass-lint": "^1.10.2", "sass-lint": "^1.10.2",
"sass-loader": "^6.0.6", "sass-loader": "^6.0.6",
......
import React from 'react'; import React from 'react';
import ReactGridLayout from 'react-grid-layout'; import ReactGridLayout from 'react-grid-layout';
import {GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT} from 'app/core/constants'; import { GRID_CELL_HEIGHT, GRID_CELL_VMARGIN, GRID_COLUMN_COUNT } from 'app/core/constants';
import {DashboardPanel} from './DashboardPanel'; import { DashboardPanel } from './DashboardPanel';
import {DashboardModel} from '../dashboard_model'; import { DashboardModel } from '../dashboard_model';
import {PanelContainer} from './PanelContainer'; import { PanelContainer } from './PanelContainer';
import {PanelModel} from '../panel_model'; import { PanelModel } from '../panel_model';
import classNames from 'classnames'; import classNames from 'classnames';
import sizeMe from 'react-sizeme'; import sizeMe from 'react-sizeme';
let lastGridWidth = 1200; let lastGridWidth = 1200;
function GridWrapper({size, layout, onLayoutChange, children, onDragStop, onResize, onResizeStop, onWidthChange, className}) { function GridWrapper({
size,
layout,
onLayoutChange,
children,
onDragStop,
onResize,
onResizeStop,
onWidthChange,
className,
isResizable,
isDraggable,
}) {
if (size.width === 0) { if (size.width === 0) {
console.log('size is zero!'); console.log('size is zero!');
} }
...@@ -25,8 +37,8 @@ function GridWrapper({size, layout, onLayoutChange, children, onDragStop, onResi ...@@ -25,8 +37,8 @@ function GridWrapper({size, layout, onLayoutChange, children, onDragStop, onResi
<ReactGridLayout <ReactGridLayout
width={lastGridWidth} width={lastGridWidth}
className={className} className={className}
isDraggable={true} isDraggable={isDraggable}
isResizable={true} isResizable={isResizable}
measureBeforeMount={false} measureBeforeMount={false}
containerPadding={[0, 0]} containerPadding={[0, 0]}
useCSSTransforms={true} useCSSTransforms={true}
...@@ -44,7 +56,7 @@ function GridWrapper({size, layout, onLayoutChange, children, onDragStop, onResi ...@@ -44,7 +56,7 @@ function GridWrapper({size, layout, onLayoutChange, children, onDragStop, onResi
); );
} }
const SizedReactLayoutGrid = sizeMe({monitorWidth: true})(GridWrapper); const SizedReactLayoutGrid = sizeMe({ monitorWidth: true })(GridWrapper);
export interface DashboardGridProps { export interface DashboardGridProps {
getPanelContainer: () => PanelContainer; getPanelContainer: () => PanelContainer;
...@@ -54,7 +66,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -54,7 +66,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
gridToPanelMap: any; gridToPanelMap: any;
panelContainer: PanelContainer; panelContainer: PanelContainer;
dashboard: DashboardModel; dashboard: DashboardModel;
panelMap: {[id: string]: PanelModel}; panelMap: { [id: string]: PanelModel };
constructor(props) { constructor(props) {
super(props); super(props);
...@@ -65,7 +77,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -65,7 +77,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
this.onDragStop = this.onDragStop.bind(this); this.onDragStop = this.onDragStop.bind(this);
this.onWidthChange = this.onWidthChange.bind(this); this.onWidthChange = this.onWidthChange.bind(this);
this.state = {animated: false}; this.state = { animated: false };
// subscribe to dashboard events // subscribe to dashboard events
this.dashboard = this.panelContainer.getDashboard(); this.dashboard = this.panelContainer.getDashboard();
...@@ -153,7 +165,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -153,7 +165,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
componentDidMount() { componentDidMount() {
setTimeout(() => { setTimeout(() => {
this.setState(() => { this.setState(() => {
return {animated: true}; return { animated: true };
}); });
}); });
} }
...@@ -162,7 +174,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -162,7 +174,7 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
const panelElements = []; const panelElements = [];
for (let panel of this.dashboard.panels) { for (let panel of this.dashboard.panels) {
const panelClasses = classNames({panel: true, 'panel--fullscreen': panel.fullscreen}); const panelClasses = classNames({ panel: true, 'panel--fullscreen': panel.fullscreen });
panelElements.push( panelElements.push(
<div key={panel.id.toString()} className={panelClasses}> <div key={panel.id.toString()} className={panelClasses}>
<DashboardPanel panel={panel} getPanelContainer={this.props.getPanelContainer} /> <DashboardPanel panel={panel} getPanelContainer={this.props.getPanelContainer} />
...@@ -176,8 +188,10 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -176,8 +188,10 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
render() { render() {
return ( return (
<SizedReactLayoutGrid <SizedReactLayoutGrid
className={classNames({'layout': true, 'animated': this.state.animated})} className={classNames({ layout: true, animated: this.state.animated })}
layout={this.buildLayout()} layout={this.buildLayout()}
isResizable={this.dashboard.meta.canEdit}
isDraggable={this.dashboard.meta.canEdit}
onLayoutChange={this.onLayoutChange} onLayoutChange={this.onLayoutChange}
onWidthChange={this.onWidthChange} onWidthChange={this.onWidthChange}
onDragStop={this.onDragStop} onDragStop={this.onDragStop}
...@@ -188,4 +202,3 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> { ...@@ -188,4 +202,3 @@ export class DashboardGrid extends React.Component<DashboardGridProps, any> {
); );
} }
} }
...@@ -7668,9 +7668,9 @@ preserve@^0.2.0: ...@@ -7668,9 +7668,9 @@ preserve@^0.2.0:
version "0.2.0" version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
prettier@1.7.3: prettier@1.9.2:
version "1.7.3" version "1.9.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.3.tgz#8e6974725273914b1c47439959dd3d3ba53664b6" resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.2.tgz#96bc2132f7a32338e6078aeb29727178c6335827"
pretty-bytes@^1.0.0: pretty-bytes@^1.0.0:
version "1.0.4" version "1.0.4"
......
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