diff --git a/public/components/workpad_page/index.js b/public/components/workpad_page/index.js index a784bf50d07d5..300ab8a3695a1 100644 --- a/public/components/workpad_page/index.js +++ b/public/components/workpad_page/index.js @@ -2,38 +2,22 @@ import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { compose, withState, withProps } from 'recompose'; import { aeroelastic } from '../../lib/aeroelastic_kibana'; -import { removeElement, setPosition } from '../../state/actions/elements'; -import { selectElement } from '../../state/actions/transient'; +import { removeElement } from '../../state/actions/elements'; import { getFullscreen, getEditing } from '../../state/selectors/app'; +import { getElements } from '../../state/selectors/workpad'; import { withEventHandlers } from './event_handlers'; import { WorkpadPage as Component } from './workpad_page'; -const mapStateToProps = state => { +const mapStateToProps = (state, ownProps) => { return { - isFullscreen: getFullscreen(state), - isEditing: getEditing(state), + isEditable: !getFullscreen(state) && getEditing(state), + elements: getElements(state, ownProps.page.id), }; }; const mapDispatchToProps = dispatch => { return { removeElement: pageId => elementId => dispatch(removeElement(elementId, pageId)), - selectElement: isInteractable => elementId => - isInteractable && dispatch(selectElement(elementId)), - setPosition: pageId => (elementId, position) => - dispatch(setPosition(elementId, pageId, position)), - }; -}; - -const mergeProps = (stateProps, { removeElement }, ownProps) => { - const { isEditing, isFullscreen } = stateProps; - const { page } = ownProps; - - return { - ...ownProps, - isEditable: !isFullscreen && isEditing, - key: page.id, - removeElement, }; }; @@ -46,11 +30,11 @@ const getRootElementId = (lookup, id) => { }; export const WorkpadPage = compose( - connect(mapStateToProps, mapDispatchToProps, mergeProps), + connect(mapStateToProps, mapDispatchToProps), withState('updateCount', 'setUpdateCount', 0), // TODO: remove this, see setUpdateCount below - withProps(({ updateCount, setUpdateCount, page, removeElement }) => { + withProps(({ updateCount, setUpdateCount, page, elements: pageElements, removeElement }) => { const { shapes, selectedShapes = [], cursor } = aeroelastic.getStore(page.id).currentScene; - const elementLookup = new Map(page.elements.map(element => [element.id, element])); + const elementLookup = new Map(pageElements.map(element => [element.id, element])); const shapeLookup = new Map(shapes.map(shape => [shape.id, shape])); const elements = shapes.map( shape => diff --git a/public/components/workpad_page/workpad_page.js b/public/components/workpad_page/workpad_page.js index 6f87025fa5410..d605e9a083b90 100644 --- a/public/components/workpad_page/workpad_page.js +++ b/public/components/workpad_page/workpad_page.js @@ -84,6 +84,7 @@ export const WorkpadPage = ({ WorkpadPage.propTypes = { page: PropTypes.shape({ id: PropTypes.string.isRequired, + style: PropTypes.object, }).isRequired, elements: PropTypes.arrayOf( PropTypes.shape({ @@ -98,7 +99,6 @@ WorkpadPage.propTypes = { isSelected: PropTypes.bool.isRequired, height: PropTypes.number.isRequired, width: PropTypes.number.isRequired, - style: PropTypes.object, isEditable: PropTypes.bool.isRequired, onDoubleClick: PropTypes.func, onKeyDown: PropTypes.func, @@ -106,5 +106,4 @@ WorkpadPage.propTypes = { onMouseDown: PropTypes.func, onMouseMove: PropTypes.func, onMouseUp: PropTypes.func, - shapes: PropTypes.arrayOf(PropTypes.object), }; diff --git a/public/state/selectors/workpad.js b/public/state/selectors/workpad.js index b4eb7c04aa5a1..2f45e118c07be 100644 --- a/public/state/selectors/workpad.js +++ b/public/state/selectors/workpad.js @@ -37,15 +37,7 @@ export function getSelectedPage(state) { } export function getPages(state) { - const pages = get(state, append(workpadRoot, 'pages'), []); - - // explicitely strip the ast, basically a fix for corrupted workpads - // due to https://github.com/elastic/kibana-canvas/issues/260 - // TODO: remove this once it's been in the wild a bit - return pages.map(page => ({ - ...page, - elements: page.elements.map(el => omit(el, ['ast'])), - })); + return get(state, append(workpadRoot, 'pages'), []); } export function getPageById(state, id) {