import React, { PropTypes } from 'react'; import { Responsive, WidthProvider } from 'react-grid-layout'; const ResponsiveReactGridLayout = WidthProvider(Responsive); require('../../../node_modules/react-grid-layout/css/styles.css'); require('../../../node_modules/react-resizable/css/styles.css'); const sliceCellPropTypes = { slice: PropTypes.object.isRequired, removeSlice: PropTypes.func.isRequired, expandedSlices: PropTypes.object }; const gridLayoutPropTypes = { dashboard: PropTypes.object.isRequired, slices: PropTypes.arrayOf(PropTypes.object).isRequired, posDict: PropTypes.object.isRequired }; class SliceCell extends React.Component { render() { const slice = this.props.slice, createMarkup = function () { return { __html: slice.description_markeddown }; }; return (
{slice.slice_name}
{slice.description ? : ""}
loading
); } } class GridLayout extends React.Component { removeSlice(sliceId) { $('[data-toggle="tooltip"]').tooltip("hide"); this.setState({ layout: this.state.layout.filter(function (reactPos) { return reactPos.i !== String(sliceId); }), slices: this.state.slices.filter(function (slice) { return slice.slice_id !== sliceId; }) }); } onResizeStop(layout, oldItem, newItem) { if (oldItem.w !== newItem.w || oldItem.h !== newItem.h) { this.setState({ layout: layout }, function () { this.props.dashboard.getSlice(newItem.i).resize(); }); } } onDragStop(layout) { this.setState({ layout: layout }); } serialize() { return this.state.layout.map(function (reactPos) { return { slice_id: reactPos.i, col: reactPos.x + 1, row: reactPos.y, size_x: reactPos.w, size_y: reactPos.h }; }); } componentWillMount() { var layout = []; this.props.slices.forEach(function (slice, index) { var pos = this.props.posDict[slice.slice_id]; if (!pos) { pos = { col: (index * 4 + 1) % 12, row: Math.floor((index) / 3) * 4, size_x: 4, size_y: 4 }; } layout.push({ i: String(slice.slice_id), x: pos.col - 1, y: pos.row, w: pos.size_x, minW: 2, h: pos.size_y }); }, this); this.setState({ layout: layout, slices: this.props.slices }); } render() { return ( {this.state.slices.map((slice) => { return (
); })}
); } } SliceCell.propTypes = sliceCellPropTypes; GridLayout.propTypes = gridLayoutPropTypes; export default GridLayout;