Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Canvas] Layout engine integration simplification #33702

Merged
merged 7 commits into from
Apr 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { connect } from 'react-redux';
import { compose, branch, renderComponent } from 'recompose';
import { selectElement } from '../../../state/actions/transient';
import { selectToplevelNodes } from '../../../state/actions/transient';
import { canUserWrite, getAppReady } from '../../../state/selectors/app';
import { getWorkpad, isWriteable } from '../../../state/selectors/workpad';
import { LoadWorkpad } from './load_workpad';
Expand All @@ -25,7 +25,7 @@ const mapStateToProps = state => {
const mapDispatchToProps = dispatch => ({
deselectElement(ev) {
ev && ev.stopPropagation();
dispatch(selectElement(null));
dispatch(selectToplevelNodes([]));
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,12 @@ export class DomPreview extends React.Component {
return;
}

if (!this.observer) {
this.original = this.original || document.querySelector(`#${this.props.elementId}`);
if (this.original) {
const currentOriginal = document.querySelector(`#${this.props.elementId}`);
const originalChanged = currentOriginal !== this.original;
if (originalChanged) {
this.observer && this.observer.disconnect();
this.original = currentOriginal;
if (currentOriginal) {
const slowUpdate = debounce(this.update, 100);
this.observer = new MutationObserver(slowUpdate);
// configuration of the observer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { connect } from 'react-redux';
import { setFullscreen, selectElement } from '../../state/actions/transient';
import { setFullscreen, selectToplevelNodes } from '../../state/actions/transient';
import { getFullscreen } from '../../state/selectors/app';
import { FullscreenControl as Component } from './fullscreen_control';

Expand All @@ -16,7 +16,7 @@ const mapStateToProps = state => ({
const mapDispatchToProps = dispatch => ({
setFullscreen: value => {
dispatch(setFullscreen(value));
value && dispatch(selectElement(null));
value && dispatch(selectToplevelNodes([]));
},
});

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/canvas/public/components/sidebar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { connect } from 'react-redux';
import { cloneSubgraphs } from '../../lib/clone_subgraphs';
import { insertNodes, elementLayer } from '../../state/actions/elements';
import { getSelectedPage, getSelectedElement } from '../../state/selectors/workpad';
import { selectElement } from './../../state/actions/transient';
import { selectToplevelNodes } from '../../state/actions/transient';

import { Sidebar as Component } from './sidebar';

Expand All @@ -23,7 +23,7 @@ const mapDispatchToProps = dispatch => ({
// todo: more unification w/ copy/paste; group cloning
const newElements = cloneSubgraphs([selectedElement]);
dispatch(insertNodes(newElements, pageId));
dispatch(selectElement(newElements[0].id));
dispatch(selectToplevelNodes(newElements.map(e => e.id)));
},
elementLayer: (pageId, selectedElement) => movement =>
dispatch(
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/canvas/public/components/workpad/workpad.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class Workpad extends React.PureComponent {
{pages.map((page, i) => (
<WorkpadPage
key={page.id}
page={page}
pageId={page.id}
height={height}
width={width}
isSelected={i + 1 === selectedPageNumber}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,36 @@ const setupHandler = (commit, canvasOrigin) => {
const handleMouseMove = (
commit,
{ clientX, clientY, altKey, metaKey, shiftKey, ctrlKey },
isEditable,
canvasOrigin
) => {
if (isEditable) {
const { x, y } = localMousePosition(canvasOrigin, clientX, clientY);
const { x, y } = localMousePosition(canvasOrigin, clientX, clientY);
if (commit) {
commit('cursorPosition', { x, y, altKey, metaKey, shiftKey, ctrlKey });
}
};

const handleMouseLeave = (commit, { buttons }) => {
if (buttons !== 1) {
if (buttons !== 1 && commit) {
w33ble marked this conversation as resolved.
Show resolved Hide resolved
commit('cursorPosition', {}); // reset hover only if we're not holding down left key (ie. drag in progress)
}
};

const handleMouseDown = (commit, e, isEditable, canvasOrigin) => {
const handleMouseDown = (commit, e, canvasOrigin) => {
e.stopPropagation();
const { clientX, clientY, buttons, altKey, metaKey, shiftKey, ctrlKey } = e;
if (buttons !== 1 || !isEditable) {
if (buttons !== 1 || !commit) {
resetHandler();
return; // left-click and edit mode only
return; // left-click only
}
setupHandler(commit, canvasOrigin);
const { x, y } = localMousePosition(canvasOrigin, clientX, clientY);
commit('mouseEvent', { event: 'mouseDown', x, y, altKey, metaKey, shiftKey, ctrlKey });
};

export const eventHandlers = {
onMouseDown: props => e => handleMouseDown(props.commit, e, props.isEditable, props.canvasOrigin),
onMouseMove: props => e => handleMouseMove(props.commit, e, props.isEditable, props.canvasOrigin),
onMouseDown: props => e => handleMouseDown(props.commit, e, props.canvasOrigin),
onMouseMove: props => e => handleMouseMove(props.commit, e, props.canvasOrigin),
onMouseLeave: props => e => handleMouseLeave(props.commit, e),
onWheel: props => e => handleMouseMove(props.commit, e, props.isEditable, props.canvasOrigin),
onWheel: props => e => handleMouseMove(props.commit, e, props.canvasOrigin),
resetHandler: () => () => resetHandler(),
};
Loading