Skip to content

Commit 440f88b

Browse files
Section handles non Attr children as default Visible
1 parent 2225452 commit 440f88b

File tree

3 files changed

+34
-27
lines changed

3 files changed

+34
-27
lines changed

src/components/containers/Section.js

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,9 @@
1-
import CogMenu from './CogMenu';
1+
import SubPanel from './SubPanel';
22
import React, {Component, cloneElement} from 'react';
33
import PropTypes from 'prop-types';
4-
import {bem, icon} from '../../lib';
4+
import {icon} from '../../lib';
55
import unpackPlotProps from '../../lib/unpackPlotProps';
66

7-
const classNames = {
8-
section: bem('section'),
9-
sectionHeading: bem('section', 'heading'),
10-
sectionCogMenu: `${bem('section', 'cog-menu')} ${icon('cog')}`,
11-
};
12-
137
function childIsVisible(child) {
148
return Boolean((child.props.plotProps || {}).isVisible);
159
}
@@ -19,7 +13,7 @@ class Section extends Component {
1913
super(props, context);
2014

2115
this.children = null;
22-
this.cogMenu = null;
16+
this.subPanel = null;
2317

2418
this.processAndSetChildren(context);
2519
}
@@ -35,48 +29,43 @@ class Section extends Component {
3529
}
3630

3731
const attrChildren = [];
38-
let cogMenu = null;
32+
let subPanel = null;
3933

4034
for (let i = 0; i < children.length; i++) {
4135
let child = children[i];
4236
if (!child) {
4337
continue;
4438
}
45-
if (child.type === CogMenu) {
46-
// Process the first cogMenu. Ignore the rest.
47-
if (cogMenu) {
39+
if (child.type === SubPanel) {
40+
// Process the first subPanel. Ignore the rest.
41+
if (subPanel) {
4842
continue;
4943
}
50-
cogMenu = child;
44+
subPanel = child;
5145
continue;
5246
}
5347

5448
let isAttr = !!child.props.attr;
5549
let plotProps = isAttr
5650
? unpackPlotProps(child.props, context, child.constructor)
57-
: {};
51+
: {isVisible: true};
5852
let childProps = Object.assign({plotProps}, child.props);
5953
childProps.key = i;
60-
61-
attrChildren.push(cloneElement(child, childProps, child.children));
54+
attrChildren.push(cloneElement(child, childProps));
6255
}
6356

6457
this.children = attrChildren.length ? attrChildren : null;
65-
this.cogMenu = cogMenu;
58+
this.subPanel = subPanel;
6659
}
6760

6861
render() {
6962
const hasVisibleChildren = this.children.some(childIsVisible);
7063

7164
return hasVisibleChildren ? (
72-
<div className={classNames.section}>
73-
<div className={classNames.sectionHeading}>
65+
<div className="section">
66+
<div className="section__heading">
7467
{this.props.name}
75-
{this.cogMenu ? (
76-
<span>
77-
<i className={classNames.sectionCogMenu} />
78-
</span>
79-
) : null}
68+
{this.subPanel}
8069
</div>
8170
{this.children}
8271
</div>

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

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import Section from '../Section';
3-
import {Flaglist, Numeric} from '../../fields';
3+
import {Flaglist, Info, Numeric} from '../../fields';
44
import {TestEditor, fixtures, plotly} from '../../../lib/test-utils';
55
import {connectTraceToPlot} from '../../../lib';
66
import {mount} from 'enzyme';
@@ -47,6 +47,24 @@ describe('Section', () => {
4747
).toBe(false);
4848
});
4949

50+
fit('is visible if it contains any non attr children', () => {
51+
const wrapper = mount(
52+
<TestEditor
53+
plotly={plotly}
54+
onUpdate={jest.fn()}
55+
{...fixtures.scatter({deref: true})}
56+
>
57+
<Section name="test-section">
58+
<Info>INFO</Info>
59+
</Section>
60+
</TestEditor>
61+
).find('[name="test-section"]');
62+
63+
expect(wrapper.children().length).toBe(1);
64+
expect(wrapper.find(Info).exists()).toBe(true);
65+
expect(wrapper.find(Info).text()).toBe('INFO');
66+
});
67+
5068
it('is not visible if it contains no visible children', () => {
5169
// pull and hole are not scatter attrs. Section should not show.
5270
const wrapper = mount(

src/components/fields/Info.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Field from './Field';
2+
import PropTypes from 'prop-types';
23
import React, {Component} from 'react';
3-
import {bem} from '../../lib';
44

55
export default class Info extends Component {
66
render() {

0 commit comments

Comments
 (0)