Skip to content

Commit ccd373a

Browse files
Info no longer triggers visibility.
1 parent 5a412cf commit ccd373a

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

src/components/containers/Section.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
import Info from '../fields/Info';
12
import MenuPanel from './MenuPanel';
23
import React, {Component, cloneElement} from 'react';
34
import PropTypes from 'prop-types';
45
import unpackPlotProps from '../../lib/unpackPlotProps';
56
import {containerConnectedContextTypes} from '../../lib/connectToContainer';
67

78
function childIsVisible(child) {
8-
return Boolean((child.props.plotProps || {}).isVisible);
9+
const attrVisible = Boolean((child.props.plotProps || {}).isVisible);
10+
const sectionVisible = Boolean(child.props['data-section-child-visible']);
11+
return attrVisible || sectionVisible;
912
}
1013

1114
export default class Section extends Component {
@@ -47,6 +50,7 @@ export default class Section extends Component {
4750

4851
const isAttr = Boolean(child.props.attr);
4952
let plotProps;
53+
let newProps = {};
5054
if (child.plotProps) {
5155
plotProps = child.plotProps;
5256
} else if (isAttr) {
@@ -58,15 +62,19 @@ export default class Section extends Component {
5862
} else {
5963
plotProps = unpackPlotProps(child.props, context);
6064
}
65+
66+
// assign plotProps as a prop of children. If they are connectedToContainer
67+
// it will see plotProps and skip recomputing them.
68+
newProps = {plotProps, key: i};
69+
} else if (child.type === Info) {
70+
// Info panels do not change section visibility.
71+
newProps = {key: i, 'data-section-child-visible': false};
6172
} else {
62-
plotProps = {isVisible: true};
73+
// custom UI currently forces section visibility.
74+
newProps = {key: i, 'data-section-child-visible': true};
6375
}
6476

65-
// assign plotProps as a prop of children. If they are connectedToContainer
66-
// it will see plotProps and skip recomputing them.
67-
const childProps = Object.assign({plotProps}, child.props);
68-
69-
childProps.key = i;
77+
const childProps = Object.assign(newProps, child.props);
7078
attrChildren.push(cloneElement(child, childProps));
7179
}
7280

src/components/containers/__tests__/Section-test.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,13 @@ describe('Section', () => {
5050
const wrapper = mount(
5151
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter()}>
5252
<Section name="test-section">
53-
<Info>INFO</Info>
53+
<div className="extra">special extra</div>
5454
</Section>
5555
</TestEditor>
5656
).find('[name="test-section"]');
5757

5858
expect(wrapper.children().length).toBe(1);
59-
expect(wrapper.find(Info).exists()).toBe(true);
60-
expect(wrapper.find(Info).text()).toBe('INFO');
59+
expect(wrapper.find('.extra').text()).toBe('special extra');
6160
});
6261

6362
it('is not visible if it contains no visible children', () => {
@@ -102,7 +101,7 @@ describe('Section', () => {
102101
expect(wrapper.find(Info).text()).toBe('INFO');
103102
});
104103

105-
it('will hides even with MenuPanel when attrs not defined', () => {
104+
it('will hide with MenuPanel children when attrs not defined', () => {
106105
const TraceSection = connectTraceToPlot(Section);
107106
const wrapper = mount(
108107
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter()}>
@@ -111,14 +110,25 @@ describe('Section', () => {
111110
<MenuPanel show>
112111
<Info>INFO</Info>
113112
</MenuPanel>
114-
<MenuPanel show>
115-
<Info>MISINFORMATION</Info>
116-
</MenuPanel>
117113
</TraceSection>
118114
</TestEditor>
119115
).find('[name="test-section"]');
120116

121117
expect(wrapper.find(MenuPanel).length).toBe(0);
122118
expect(wrapper.find(Info).length).toBe(0);
123119
});
120+
121+
it('will hide with Info children when attrs not defined', () => {
122+
const TraceSection = connectTraceToPlot(Section);
123+
const wrapper = mount(
124+
<TestEditor onUpdate={jest.fn()} {...fixtures.scatter()}>
125+
<TraceSection name="test-section" traceIndex={0}>
126+
<Numeric attr="badattr" traceIndex={0} />
127+
<Info>INFO</Info>
128+
</TraceSection>
129+
</TestEditor>
130+
).find('[name="test-section"]');
131+
132+
expect(wrapper.find(Info).length).toBe(0);
133+
});
124134
});

0 commit comments

Comments
 (0)