From 9a72b01318d9c1a26cb6cdea3e4e6bbf5e63c636 Mon Sep 17 00:00:00 2001 From: bpostlethwaite Date: Wed, 22 Nov 2017 19:57:42 -0500 Subject: [PATCH 1/2] MenuPanel does not trigger section visibility --- src/components/containers/Section.js | 3 +- .../containers/__tests__/Section-test.js | 29 +++++++++++++++++-- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/components/containers/Section.js b/src/components/containers/Section.js index 7c4b0116c..b26eaea7a 100644 --- a/src/components/containers/Section.js +++ b/src/components/containers/Section.js @@ -76,8 +76,7 @@ export default class Section extends Component { render() { const hasVisibleChildren = - (this.children && this.children.some(childIsVisible)) || - Boolean(this.menuPanel); + this.children && this.children.some(childIsVisible); return hasVisibleChildren ? (
diff --git a/src/components/containers/__tests__/Section-test.js b/src/components/containers/__tests__/Section-test.js index e21d48421..ca5726c20 100644 --- a/src/components/containers/__tests__/Section-test.js +++ b/src/components/containers/__tests__/Section-test.js @@ -81,21 +81,44 @@ describe('Section', () => { expect(wrapper.find(Numeric).exists()).toBe(false); }); - it('will render first menuPanel even with no visible attrs', () => { + it('will render first menuPanel', () => { + const TraceSection = connectTraceToPlot(Section); const wrapper = mount( -
+ + INFO MISINFORMATION -
+
).find('[name="test-section"]'); + expect(wrapper.find(MenuPanel).length).toBe(1); expect(wrapper.find(Info).length).toBe(1); expect(wrapper.find(Info).text()).toBe('INFO'); }); + + it('will hides even with MenuPanel when attrs not defined', () => { + const TraceSection = connectTraceToPlot(Section); + const wrapper = mount( + + + + + INFO + + + MISINFORMATION + + + + ).find('[name="test-section"]'); + + expect(wrapper.find(MenuPanel).length).toBe(0); + expect(wrapper.find(Info).length).toBe(0); + }); }); From f64f4f005b048fa431659602d0a3d3ee0c1fa24c Mon Sep 17 00:00:00 2001 From: bpostlethwaite Date: Wed, 22 Nov 2017 20:23:42 -0500 Subject: [PATCH 2/2] Info no longer triggers visibility. --- src/components/containers/Section.js | 22 +++++++++++------ .../containers/__tests__/Section-test.js | 24 +++++++++++++------ 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/components/containers/Section.js b/src/components/containers/Section.js index b26eaea7a..e0f653904 100644 --- a/src/components/containers/Section.js +++ b/src/components/containers/Section.js @@ -1,3 +1,4 @@ +import Info from '../fields/Info'; import MenuPanel from './MenuPanel'; import React, {Component, cloneElement} from 'react'; import PropTypes from 'prop-types'; @@ -5,7 +6,9 @@ import unpackPlotProps from '../../lib/unpackPlotProps'; import {containerConnectedContextTypes} from '../../lib/connectToContainer'; function childIsVisible(child) { - return Boolean((child.props.plotProps || {}).isVisible); + const attrVisible = Boolean((child.props.plotProps || {}).isVisible); + const sectionVisible = Boolean(child.props['data-section-child-visible']); + return attrVisible || sectionVisible; } export default class Section extends Component { @@ -47,6 +50,7 @@ export default class Section extends Component { const isAttr = Boolean(child.props.attr); let plotProps; + let newProps = {}; if (child.plotProps) { plotProps = child.plotProps; } else if (isAttr) { @@ -58,15 +62,19 @@ export default class Section extends Component { } else { plotProps = unpackPlotProps(child.props, context); } + + // assign plotProps as a prop of children. If they are connectedToContainer + // it will see plotProps and skip recomputing them. + newProps = {plotProps, key: i}; + } else if (child.type === Info) { + // Info panels do not change section visibility. + newProps = {key: i, 'data-section-child-visible': false}; } else { - plotProps = {isVisible: true}; + // custom UI currently forces section visibility. + newProps = {key: i, 'data-section-child-visible': true}; } - // assign plotProps as a prop of children. If they are connectedToContainer - // it will see plotProps and skip recomputing them. - const childProps = Object.assign({plotProps}, child.props); - - childProps.key = i; + const childProps = Object.assign(newProps, child.props); attrChildren.push(cloneElement(child, childProps)); } diff --git a/src/components/containers/__tests__/Section-test.js b/src/components/containers/__tests__/Section-test.js index ca5726c20..3bed85084 100644 --- a/src/components/containers/__tests__/Section-test.js +++ b/src/components/containers/__tests__/Section-test.js @@ -50,14 +50,13 @@ describe('Section', () => { const wrapper = mount(
- INFO +
special extra
).find('[name="test-section"]'); expect(wrapper.children().length).toBe(1); - expect(wrapper.find(Info).exists()).toBe(true); - expect(wrapper.find(Info).text()).toBe('INFO'); + expect(wrapper.find('.extra').text()).toBe('special extra'); }); it('is not visible if it contains no visible children', () => { @@ -102,7 +101,7 @@ describe('Section', () => { expect(wrapper.find(Info).text()).toBe('INFO'); }); - it('will hides even with MenuPanel when attrs not defined', () => { + it('will hide with MenuPanel children when attrs not defined', () => { const TraceSection = connectTraceToPlot(Section); const wrapper = mount( @@ -111,9 +110,6 @@ describe('Section', () => { INFO - - MISINFORMATION - ).find('[name="test-section"]'); @@ -121,4 +117,18 @@ describe('Section', () => { expect(wrapper.find(MenuPanel).length).toBe(0); expect(wrapper.find(Info).length).toBe(0); }); + + it('will hide with Info children when attrs not defined', () => { + const TraceSection = connectTraceToPlot(Section); + const wrapper = mount( + + + + INFO + + + ).find('[name="test-section"]'); + + expect(wrapper.find(Info).length).toBe(0); + }); });