Skip to content

Commit 56388ce

Browse files
Merge pull request #182 from plotly/required-changes-for-batch-application
Required changes for batch application
2 parents db45b70 + cfd7acb commit 56388ce

File tree

4 files changed

+23
-33
lines changed

4 files changed

+23
-33
lines changed

src/components/containers/Section.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,26 @@ import PropTypes from 'prop-types';
55
import unpackPlotProps from '../../lib/unpackPlotProps';
66
import {containerConnectedContextTypes} from '../../lib/connectToContainer';
77

8-
function childIsVisible(child) {
9-
const attrVisible = Boolean((child.props.plotProps || {}).isVisible);
10-
const sectionVisible = Boolean(child.props['data-section-child-visible']);
11-
return attrVisible || sectionVisible;
12-
}
13-
148
export default class Section extends Component {
159
constructor(props, context) {
1610
super(props, context);
1711

1812
this.children = null;
1913
this.menuPanel = null;
14+
this.sectionVisible = false;
2015

21-
this.processAndSetChildren(context);
16+
this.processAndSetChildren(props, context);
2217
}
2318

2419
componentWillReceiveProps(nextProps, nextContext) {
25-
this.processAndSetChildren(nextContext);
20+
this.processAndSetChildren(nextProps, nextContext);
2621
}
2722

28-
processAndSetChildren(context) {
29-
let children = this.props.children;
30-
if (!Array.isArray(children)) {
31-
children = [children];
32-
}
23+
processAndSetChildren(nextProps, nextContext) {
24+
this.sectionVisible = false;
3325

34-
const attrChildren = [];
26+
const children = React.Children.toArray(nextProps.children);
27+
this.children = [];
3528
let menuPanel = null;
3629

3730
for (let i = 0; i < children.length; i++) {
@@ -40,7 +33,8 @@ export default class Section extends Component {
4033
continue;
4134
}
4235
if (child.type === MenuPanel) {
43-
// Process the first menuPanel. Ignore the rest.
36+
// Process the first menuPanel. Ignore the rest. MenuPanel does
37+
// not affect visibility.
4438
if (menuPanel) {
4539
continue;
4640
}
@@ -55,38 +49,34 @@ export default class Section extends Component {
5549
plotProps = child.plotProps;
5650
} else if (isAttr) {
5751
if (child.type.supplyPlotProps) {
58-
plotProps = child.type.supplyPlotProps(child.props, context);
52+
plotProps = child.type.supplyPlotProps(child.props, nextContext);
5953
if (child.type.modifyPlotProps) {
60-
child.type.modifyPlotProps(child.props, context, plotProps);
54+
child.type.modifyPlotProps(child.props, nextContext, plotProps);
6155
}
6256
} else {
63-
plotProps = unpackPlotProps(child.props, context);
57+
plotProps = unpackPlotProps(child.props, nextContext);
6458
}
6559

6660
// assign plotProps as a prop of children. If they are connectedToContainer
6761
// it will see plotProps and skip recomputing them.
68-
newProps = {plotProps, key: i};
62+
newProps = {plotProps};
63+
this.sectionVisible = this.sectionVisible || plotProps.isVisible;
64+
this.children.push(cloneElement(child, newProps));
6965
} else if (child.type === Info) {
7066
// Info panels do not change section visibility.
71-
newProps = {key: i, 'data-section-child-visible': false};
67+
this.children.push(child);
7268
} else {
7369
// custom UI currently forces section visibility.
74-
newProps = {key: i, 'data-section-child-visible': true};
70+
this.sectionVisible = true;
71+
this.children.push(child);
7572
}
76-
77-
const childProps = Object.assign(newProps, child.props);
78-
attrChildren.push(cloneElement(child, childProps));
7973
}
8074

81-
this.children = attrChildren.length ? attrChildren : null;
8275
this.menuPanel = menuPanel;
8376
}
8477

8578
render() {
86-
const hasVisibleChildren =
87-
this.children && this.children.some(childIsVisible);
88-
89-
return hasVisibleChildren ? (
79+
return this.sectionVisible ? (
9080
<div className="section">
9181
<div className="section__heading">
9282
{this.props.name}

src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
connectTraceToPlot,
88
dereference,
99
localize,
10+
walkObject,
1011
} from './lib';
1112
import {EDITOR_ACTIONS} from './lib/constants';
1213

@@ -82,6 +83,7 @@ export {
8283
connectTraceToPlot,
8384
dereference,
8485
localize,
86+
walkObject,
8587
};
8688

8789
export default PlotlyEditor;

src/lib/dereference.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ export default function dereference(container, dataSources) {
1212
const data = dataSources[srcRef];
1313

1414
if (!Array.isArray(data)) {
15-
throw new Error(
16-
`Attempted to dereference ${key} but no array data found for ${srcRef}.`
17-
);
15+
return;
1816
}
1917

2018
const dataKey = key.replace(SRC_ATTR_PATTERN, '');

src/styles/components/fields/_field.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
.field__widget {
3737
width: 64%;
3838
padding-left: 12px;
39-
display: inline-block;
39+
display: flex;
4040
padding-right: 12px;
4141
}
4242

0 commit comments

Comments
 (0)