From bac56c6c03be460b17e00c9cf37a1c6938c1c770 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:13:33 +0100 Subject: [PATCH 1/6] Fixes terminal being closed when its node's card is closed. --- client/app/scripts/stores/app-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index f5428168a..f25008a42 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -110,7 +110,7 @@ function closeNodeDetails(nodeId) { const popNodeId = nodeId || nodeDetails.keySeq().last(); // remove pipe if it belongs to the node being closed controlPipes = controlPipes.filter(pipe => { - return pipe.nodeId !== popNodeId; + return pipe.get('nodeId') !== popNodeId; }); nodeDetails = nodeDetails.delete(popNodeId); } From 5500c2f280013542a687203d515f1b65b83dd264 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:14:08 +0100 Subject: [PATCH 2/6] Fixes harmless exception: hitting esc with no cards open. --- client/app/scripts/stores/app-store.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index f25008a42..5f79042b9 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -240,7 +240,7 @@ export class AppStore extends Store { } getTopCardNodeId() { - return nodeDetails.last().id; + return nodeDetails.last() && nodeDetails.last().id; } getNodes() { From dcb621d7e6674f4e155918563dd3c43dc39d7c65 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:14:47 +0100 Subject: [PATCH 3/6] Close terminal when we click "show node in its topology" --- client/app/scripts/stores/app-store.js | 1 + 1 file changed, 1 insertion(+) diff --git a/client/app/scripts/stores/app-store.js b/client/app/scripts/stores/app-store.js index 5f79042b9..58c261b66 100644 --- a/client/app/scripts/stores/app-store.js +++ b/client/app/scripts/stores/app-store.js @@ -362,6 +362,7 @@ export class AppStore extends Store { case ActionTypes.CLICK_SHOW_TOPOLOGY_FOR_NODE: nodeDetails = nodeDetails.filter((v, k) => k === payload.nodeId); + controlPipes = controlPipes.clear(); selectedNodeId = payload.nodeId; if (payload.topologyId !== currentTopologyId) { setTopology(payload.topologyId); From ab75bb5e4123de4b3dbce63be896cd0a1bb1af0f Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:16:33 +0100 Subject: [PATCH 4/6] Move details panel styling dimensions into common constants file. They are used in a couple of places around the code base. --- client/app/scripts/charts/nodes-chart.js | 4 ++-- client/app/scripts/components/details-card.js | 23 ++++++++----------- client/app/scripts/constants/styles.js | 10 ++++++++ 3 files changed, 21 insertions(+), 16 deletions(-) create mode 100644 client/app/scripts/constants/styles.js diff --git a/client/app/scripts/charts/nodes-chart.js b/client/app/scripts/charts/nodes-chart.js index 914bffa33..adb804830 100644 --- a/client/app/scripts/charts/nodes-chart.js +++ b/client/app/scripts/charts/nodes-chart.js @@ -5,6 +5,7 @@ import React from 'react'; import { Map as makeMap } from 'immutable'; import timely from 'timely'; +import { DETAILS_PANEL_WIDTH } from '../constants/styles'; import { clickBackground } from '../actions/app-actions'; import AppStore from '../stores/app-store'; import Edge from './edge'; @@ -302,9 +303,8 @@ export default class NodesChart extends React.Component { // move origin node to center of viewport const zoomScale = state.scale; - const detailsWidth = 420; const translate = state.panTranslate; - const centerX = (-translate[0] + (props.width + MARGINS.left - detailsWidth) / 2) / zoomScale; + const centerX = (-translate[0] + (props.width + MARGINS.left - DETAILS_PANEL_WIDTH) / 2) / zoomScale; const centerY = (-translate[1] + (props.height + MARGINS.top) / 2) / zoomScale; stateNodes = stateNodes.mergeIn([props.selectedNodeId], { x: centerX, diff --git a/client/app/scripts/components/details-card.js b/client/app/scripts/components/details-card.js index 256311213..b1f8694a0 100644 --- a/client/app/scripts/components/details-card.js +++ b/client/app/scripts/components/details-card.js @@ -1,13 +1,8 @@ import React from 'react'; import NodeDetails from './node-details'; - -// card dimensions in px -const marginTop = 24; -const marginBottom = 48; -const marginRight = 36; -const panelWidth = 420; -const offset = 8; +import { DETAILS_PANEL_WIDTH as WIDTH, DETAILS_PANEL_OFFSET as OFFSET, + DETAILS_PANEL_MARGINS as MARGINS } from '../constants/styles'; export default class DetailsCard extends React.Component { @@ -27,21 +22,21 @@ export default class DetailsCard extends React.Component { render() { let transform; const origin = this.props.origin; - const panelHeight = window.innerHeight - marginBottom - marginTop; + const panelHeight = window.innerHeight - MARGINS.bottom - MARGINS.top; if (origin && !this.state.mounted) { // render small panel near origin, will transition into normal panel after being mounted - const scaleY = origin.height / (window.innerHeight - marginBottom - marginTop) / 2; - const scaleX = origin.width / panelWidth / 2; - const centerX = window.innerWidth - marginRight - (panelWidth / 2); - const centerY = (panelHeight) / 2 + marginTop; + const scaleY = origin.height / (window.innerHeight - MARGINS.bottom - MARGINS.top) / 2; + const scaleX = origin.width / WIDTH / 2; + const centerX = window.innerWidth - MARGINS.right - (WIDTH / 2); + const centerY = (panelHeight) / 2 + MARGINS.top; const dx = (origin.left + origin.width / 2) - centerX; const dy = (origin.top + origin.height / 2) - centerY; transform = `translate(${dx}px, ${dy}px) scale(${scaleX},${scaleY})`; } else { // stack effect: shift top cards to the left, shrink lower cards vertically - const shiftX = -1 * this.props.index * offset; + const shiftX = -1 * this.props.index * OFFSET; const position = this.props.cardCount - this.props.index - 1; // reverse index - const scaleY = position === 0 ? 1 : (panelHeight - 2 * offset * position) / panelHeight; + const scaleY = position === 0 ? 1 : (panelHeight - 2 * OFFSET * position) / panelHeight; if (scaleY !== 1) { transform = `translateX(${shiftX}px) scaleY(${scaleY})`; } else { diff --git a/client/app/scripts/constants/styles.js b/client/app/scripts/constants/styles.js new file mode 100644 index 000000000..44d3afc85 --- /dev/null +++ b/client/app/scripts/constants/styles.js @@ -0,0 +1,10 @@ + +export const DETAILS_PANEL_WIDTH = 420; + +export const DETAILS_PANEL_MARGINS = { + top: 24, + bottom: 48, + right: 36 +}; + +export const DETAILS_PANEL_OFFSET = 8; From 06aff39548e1a7ddb8d9d988b915676a0cfaf355 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:17:58 +0100 Subject: [PATCH 5/6] Fixes details cards opening out over the terminal --- client/app/scripts/components/embedded-terminal.js | 10 ++++++++-- client/app/scripts/components/terminal.js | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/client/app/scripts/components/embedded-terminal.js b/client/app/scripts/components/embedded-terminal.js index bd7436bf1..e56094ba0 100644 --- a/client/app/scripts/components/embedded-terminal.js +++ b/client/app/scripts/components/embedded-terminal.js @@ -2,6 +2,7 @@ import React from 'react'; import { getNodeColor, getNodeColorDark } from '../utils/color-utils'; import Terminal from './terminal'; +import { DETAILS_PANEL_WIDTH, DETAILS_PANEL_MARGINS, DETAILS_PANEL_OFFSET } from '../constants/styles'; export default function EmeddedTerminal({pipe, nodeId, details}) { const node = details.get(nodeId); @@ -10,12 +11,17 @@ export default function EmeddedTerminal({pipe, nodeId, details}) { const statusBarColor = d && getNodeColor(d.rank, d.label_major); const title = d && d.label_major; + const style = { + right: DETAILS_PANEL_MARGINS.right + DETAILS_PANEL_WIDTH + 10 + + (details.size * DETAILS_PANEL_OFFSET) + }; + // React unmount/remounts when key changes, this is important for cleaning up // the term.js and creating a new one for the new pipe. return ( -
+
+ statusBarColor={statusBarColor} containerMargin={style.right} title={title} />
); } diff --git a/client/app/scripts/components/terminal.js b/client/app/scripts/components/terminal.js index d87ff6774..cff1419e9 100644 --- a/client/app/scripts/components/terminal.js +++ b/client/app/scripts/components/terminal.js @@ -184,6 +184,14 @@ export default class Terminal extends React.Component { } } + componentWillReceiveProps(nextProps) { + const containerMarginChanged = nextProps.containerMargin !== this.props.containerMargin; + log(nextProps.containerMargin); + if (containerMarginChanged) { + this.handleResize(); + } + } + componentDidUpdate(prevProps, prevState) { const sizeChanged = ( prevState.cols !== this.state.cols || From aad6e1fbeb00fe47d47a2bdcf129df0e7168af90 Mon Sep 17 00:00:00 2001 From: Simon Howe Date: Fri, 29 Jan 2016 13:19:06 +0100 Subject: [PATCH 6/6] Fixes new browser window size when popping out terminal. Calculate the size more dynamically based on the size of the terminal dom element. --- client/app/scripts/components/terminal.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/client/app/scripts/components/terminal.js b/client/app/scripts/components/terminal.js index cff1419e9..e291ca5ec 100644 --- a/client/app/scripts/components/terminal.js +++ b/client/app/scripts/components/terminal.js @@ -52,16 +52,16 @@ function terminalCellSize(wrapperNode, rows, cols) { return {pixelPerCol, pixelPerRow}; } -function openNewWindow(url, minWidth = 200) { +function openNewWindow(url, bcr, minWidth = 200) { const screenLeft = window.screenX || window.screenLeft; const screenTop = window.screenY || window.screenTop; const popoutWindowToolbarHeight = 51; // TODO replace this stuff w/ looking up bounding box. const windowOptions = { - width: Math.max(minWidth, window.innerWidth - 420 - 36 - 36 - 10), - height: window.innerHeight - 24 - 48 - popoutWindowToolbarHeight, - left: screenLeft + 36, - top: screenTop + (window.outerHeight - window.innerHeight) + 24, + width: Math.max(minWidth, bcr.width), + height: bcr.height - popoutWindowToolbarHeight, + left: screenLeft + bcr.left, + top: screenTop + (window.outerHeight - window.innerHeight) + bcr.top, location: 'no', }; @@ -219,8 +219,9 @@ export default class Terminal extends React.Component { const paramString = JSON.stringify(this.props); clickCloseTerminal(this.getPipeId()); + const bcr = ReactDOM.findDOMNode(this).getBoundingClientRect(); const minWidth = this.state.pixelPerCol * 80 + (8 * 2); - openNewWindow(`terminal.html#!/state/${paramString}`, minWidth); + openNewWindow(`terminal.html#!/state/${paramString}`, bcr, minWidth); } handleResize() {