From 8f1fdeb47720e53d359158ef17bf7831288887c7 Mon Sep 17 00:00:00 2001 From: Filip Barl Date: Tue, 25 Jul 2017 17:46:17 +0200 Subject: [PATCH] Make Resource view nodes clickable (#2679) * Made Resource view nodes clickable. * Remove selection when clicking on the background. * Use opacity instead of the blue overlay for selected nodes. --- client/app/scripts/actions/app-actions.js | 5 ++- .../app/scripts/components/nodes-resources.js | 18 ++++++++- .../nodes-resources/node-resources-layer.js | 2 + .../node-resources-metric-box.js | 38 +++++++++++++++++-- .../app/scripts/components/zoomable-canvas.js | 4 +- client/app/scripts/reducers/root.js | 2 +- client/app/styles/_base.scss | 4 +- 7 files changed, 62 insertions(+), 11 deletions(-) diff --git a/client/app/scripts/actions/app-actions.js b/client/app/scripts/actions/app-actions.js index 422c2a6b94..047a7f485b 100644 --- a/client/app/scripts/actions/app-actions.js +++ b/client/app/scripts/actions/app-actions.js @@ -323,13 +323,14 @@ export function setResourceView() { }; } -export function clickNode(nodeId, label, origin) { +export function clickNode(nodeId, label, origin, topologyId = null) { return (dispatch, getState) => { dispatch({ type: ActionTypes.CLICK_NODE, origin, label, - nodeId + nodeId, + topologyId, }); updateRoute(getState); getNodeDetails(getState, dispatch); diff --git a/client/app/scripts/components/nodes-resources.js b/client/app/scripts/components/nodes-resources.js index 27f86c8377..50f257ab36 100644 --- a/client/app/scripts/components/nodes-resources.js +++ b/client/app/scripts/components/nodes-resources.js @@ -8,9 +8,22 @@ import { resourcesZoomLimitsSelector, resourcesZoomStateSelector, } from '../selectors/resource-view/zoom'; +import { clickBackground } from '../actions/app-actions'; class NodesResources extends React.Component { + constructor(props, context) { + super(props, context); + + this.handleMouseClick = this.handleMouseClick.bind(this); + } + + handleMouseClick() { + if (this.props.selectedNodeId) { + this.props.clickBackground(); + } + } + renderLayers(transform) { return this.props.layersTopologyIds.map((topologyId, index) => ( @@ -38,10 +52,12 @@ class NodesResources extends React.Component { function mapStateToProps(state) { return { + selectedNodeId: state.get('selectedNodeId'), layersTopologyIds: layersTopologyIdsSelector(state), }; } export default connect( - mapStateToProps + mapStateToProps, + { clickBackground } )(NodesResources); diff --git a/client/app/scripts/components/nodes-resources/node-resources-layer.js b/client/app/scripts/components/nodes-resources/node-resources-layer.js index af613cac57..2a369483ee 100644 --- a/client/app/scripts/components/nodes-resources/node-resources-layer.js +++ b/client/app/scripts/components/nodes-resources/node-resources-layer.js @@ -19,9 +19,11 @@ class NodesResourcesLayer extends React.Component { {layoutNodes.toIndexedSeq().map(node => ( = RESOURCES_LABEL_MIN_SIZE; const showNode = width >= 1; // hide the thin nodes @@ -85,7 +110,9 @@ class NodeResourcesMetricBox extends React.Component { metricSummary.get('humanizedAbsoluteConsumption'); return ( - + {label} - {type} usage at {resourceUsageTooltipInfo} {showCapacity && } @@ -104,8 +131,11 @@ class NodeResourcesMetricBox extends React.Component { function mapStateToProps(state) { return { contrastMode: state.get('contrastMode'), + selectedNodeId: state.get('selectedNodeId'), viewportWidth: state.getIn(['viewport', 'width']), }; } - -export default connect(mapStateToProps)(NodeResourcesMetricBox); +export default connect( + mapStateToProps, + { clickNode } +)(NodeResourcesMetricBox); diff --git a/client/app/scripts/components/zoomable-canvas.js b/client/app/scripts/components/zoomable-canvas.js index 7eff294afc..205b4f2c16 100644 --- a/client/app/scripts/components/zoomable-canvas.js +++ b/client/app/scripts/components/zoomable-canvas.js @@ -102,7 +102,7 @@ class ZoomableCanvas extends React.Component { const transform = forwardTransform ? '' : transformToString(this.state); return ( - +
@@ -115,7 +115,7 @@ class ZoomableCanvas extends React.Component { maxScale={this.state.maxScale} scale={this.state.scaleX} />} - +
); } diff --git a/client/app/scripts/reducers/root.js b/client/app/scripts/reducers/root.js index 751352837b..2e8d76fe35 100644 --- a/client/app/scripts/reducers/root.js +++ b/client/app/scripts/reducers/root.js @@ -300,8 +300,8 @@ export function rootReducer(state = initialState, action) { { id: action.nodeId, label: action.label, + topologyId: action.topologyId || state.get('currentTopologyId'), origin, - topologyId: state.get('currentTopologyId') } ); state = state.set('selectedNodeId', action.nodeId); diff --git a/client/app/styles/_base.scss b/client/app/styles/_base.scss index bcc62fcf98..1f0f12539c 100644 --- a/client/app/styles/_base.scss +++ b/client/app/styles/_base.scss @@ -1125,12 +1125,14 @@ .node-resources { &-metric-box { + @extend .palable; + cursor: pointer; fill: rgba(150, 150, 150, 0.4); &-info { background-color: rgba(white, 0.6); border-radius: 2px; - cursor: default; + cursor: inherit; padding: 5px; .wrapper {