Skip to content

Commit e78c77a

Browse files
authored
Merge pull request #432 from plotly/plotly-containers
Rename Panel/Fold/Section -> PlotlyPanel/Fold/Section/
2 parents d278280 + 4212d4e commit e78c77a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1415
-1096
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ The [custom editor example](https://github.com/plotly/react-chart-editor/tree/ma
6666

6767
### General-purpose Containers
6868

69-
* `<Panel />`: renders as a generic rectangular container with special handling for collapsing/expanding child `<Fold />`s and optionally an 'add' button for creating them
7069
* `<PanelMenuWrapper />`: renders as a sidebar selector menu for `<Panel />`s
71-
* `<Fold />`: collapsable container within a `<Panel />`
72-
* `<Section />`: uncollapsable container within a `<Panel />` or `<Fold />`
73-
* `<SectionHeader/>`: a `SectionHeader` to use separately with custom layouts.
70+
* `<PlotlyPanel />`: renders as a generic rectangular container with special handling for collapsing/expanding child `<Fold />`s and optionally an 'add' button for creating them, has special [visibility rules](https://github.com/plotly/react-chart-editor/tree/master/src/components/containers/_tests_/ConnectedContainersVisibility-test.js) that depend on plotly figure
71+
* `<PlotlyFold />`: collapsable container within a `<Panel />`, has special [visibility rules](https://github.com/plotly/react-chart-editor/tree/master/src/components/containers/_tests_/ConnectedContainersVisibility-test.js) that depend on plotly figure
72+
* `<PlotlySection />`: uncollapsable container within a `<Panel />` or `<Fold />`, has special [visibility rules](https://github.com/plotly/react-chart-editor/tree/master/src/components/containers/_tests_/ConnectedContainersVisibility-test.js) that depend on plotly figure
73+
* `<Panel/>`, `<Fold/>`, `<Section/>`: same as `PlotlyPanel`, `PlotlyFold`, `PlotlySection`, but there are no special visibility rules, those containers [always show, and always show their children](https://github.com/plotly/react-chart-editor/tree/master/src/components/containers/_tests_/UnconnectedContainersVisibility-test.js), but Fold does not have the canDelete functionality as its context related
7474
* `<SingleSidebarItem/>`: wraps any item you would like to see appear in the sidebar menu.
7575

7676
### General-purpose Fields

examples/custom/src/CustomEditor.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ import {
33
Flaglist,
44
ColorPicker,
55
ColorscalePicker,
6-
Fold,
6+
PlotlyFold,
77
PanelMenuWrapper,
88
TextEditor,
99
Radio,
1010
Dropdown,
1111
Info,
12-
Section,
12+
PlotlySection,
1313
Numeric,
1414
LayoutPanel,
1515
Button,
@@ -22,16 +22,16 @@ export default class CustomEditor extends Component {
2222
return (
2323
<PanelMenuWrapper>
2424
<TraceAccordion group="Traces" name="Style">
25-
<Section name="Colorscale" attr="marker.colorscale">
25+
<PlotlySection name="Colorscale" attr="marker.colorscale">
2626
<ColorscalePicker label="Colorscale" attr="marker.colorscale" />
27-
</Section>
27+
</PlotlySection>
2828
</TraceAccordion>
2929

3030
<LayoutPanel group="Layout" name="Style">
31-
<Fold name="Fold">
31+
<PlotlyFold name="PlotlyFold">
3232
{
33-
// At least one of the direct children of Fold must have an attr prop
34-
// for the Fold to display itself
33+
// At least one of the direct children of PlotlyFold must have an attr prop
34+
// for the PlotlyFold to display itself
3535
}
3636
<Info attr="title">
3737
<p>
@@ -42,7 +42,7 @@ export default class CustomEditor extends Component {
4242
This is an <code>Info</code> component.
4343
</p>
4444
</Info>
45-
<Section name="Section">
45+
<PlotlySection name="PlotlySection">
4646
<Numeric label="Numeric" attr="width" show units="units" />
4747
<Dropdown
4848
label="Dropdown"
@@ -80,8 +80,8 @@ export default class CustomEditor extends Component {
8080
/>
8181
<TextEditor attr="title" label="TextEditor htmlOnly" htmlOnly />
8282
<TextEditor attr="title" label="TextEditor latexOnly" latexOnly />
83-
</Section>
84-
</Fold>
83+
</PlotlySection>
84+
</PlotlyFold>
8585
</LayoutPanel>
8686
<SingleSidebarItem>
8787
<Button

src/__tests__/PlotlyEditor.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import PlotlyEditor, {Fold} from '..';
1+
import PlotlyEditor, {PlotlyFold} from '..';
22
import {configure, mount} from 'enzyme';
33
import Adapter from 'enzyme-adapter-react-16';
44
import React, {Component} from 'react';
@@ -54,7 +54,7 @@ describe('<TestApp>', () => {
5454
});
5555

5656
it('Can create and delete traces', done => {
57-
expect(app.find(Fold).length).toEqual(0);
57+
expect(app.find(PlotlyFold).length).toEqual(0);
5858

5959
app
6060
.find('.js-add-button')

src/components/containers/AnnotationAccordion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Fold from './Fold';
1+
import PlotlyFold from './PlotlyFold';
22
import TraceRequiredPanel from './TraceRequiredPanel';
33
import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
55
import {connectAnnotationToLayout, localize} from 'lib';
66

7-
const AnnotationFold = connectAnnotationToLayout(Fold);
7+
const AnnotationFold = connectAnnotationToLayout(PlotlyFold);
88

99
class AnnotationAccordion extends Component {
1010
render() {

src/components/containers/AxesFold.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AxesSelector from '../fields/AxesSelector';
2-
import Fold from './Fold';
2+
import PlotlyFold from './PlotlyFold';
33
import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
55
import {connectAxesToLayout} from 'lib';
@@ -8,10 +8,10 @@ class AxesFold extends Component {
88
render() {
99
const {children, options} = this.props;
1010
return options.length && children ? (
11-
<Fold {...this.props}>
11+
<PlotlyFold {...this.props}>
1212
{options.length === 1 ? null : <AxesSelector axesOptions={options} />}
1313
{children}
14-
</Fold>
14+
</PlotlyFold>
1515
) : null;
1616
}
1717
}

src/components/containers/ImageAccordion.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Fold from './Fold';
1+
import PlotlyFold from './PlotlyFold';
22
import TraceRequiredPanel from './TraceRequiredPanel';
33
import PropTypes from 'prop-types';
44
import React, {Component} from 'react';
55
import {connectImageToLayout, localize} from 'lib';
66

7-
const ImageFold = connectImageToLayout(Fold);
7+
const ImageFold = connectImageToLayout(PlotlyFold);
88

99
class ImageAccordion extends Component {
1010
render() {

src/components/containers/Fold.js renamed to src/components/containers/PlotlyFold.js

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,43 +10,10 @@ import {
1010
striptags,
1111
} from 'lib';
1212

13-
class Fold extends Component {
14-
constructor(props, context) {
15-
super(props, context);
16-
17-
this.foldVisible = false;
18-
this.determineVisibility(props, context);
19-
}
20-
21-
componentWillReceiveProps(nextProps, nextContext) {
22-
this.determineVisibility(nextProps, nextContext);
23-
}
24-
25-
determineVisibility(nextProps, nextContext) {
26-
this.foldVisible = false;
27-
28-
React.Children.forEach(nextProps.children, child => {
29-
if (!child || this.foldVisible) {
30-
return;
31-
}
32-
33-
if (child.props.attr) {
34-
// attr components force fold open if they are visible
35-
const plotProps = unpackPlotProps(child.props, nextContext);
36-
if (child.type.modifyPlotProps) {
37-
child.type.modifyPlotProps(child.props, nextContext, plotProps);
38-
}
39-
40-
this.foldVisible = this.foldVisible || plotProps.isVisible;
41-
return;
42-
}
43-
44-
if (!(child.type.plotly_editor_traits || {}).no_visibility_forcing) {
45-
// non-attr components force visibility (unless they don't via traits)
46-
this.foldVisible = true;
47-
return;
48-
}
49-
});
13+
class UnlocalizedFold extends Component {
14+
constructor() {
15+
super();
16+
this.foldVisible = true;
5017
}
5118

5219
render() {
@@ -136,9 +103,9 @@ class Fold extends Component {
136103
}
137104
}
138105

139-
Fold.plotly_editor_traits = {foldable: true};
106+
UnlocalizedFold.plotly_editor_traits = {foldable: true};
140107

141-
Fold.propTypes = {
108+
UnlocalizedFold.propTypes = {
142109
canDelete: PropTypes.bool,
143110
children: PropTypes.node,
144111
className: PropTypes.string,
@@ -151,11 +118,57 @@ Fold.propTypes = {
151118
name: PropTypes.string,
152119
};
153120

154-
Fold.contextTypes = Object.assign(
121+
export const Fold = localize(UnlocalizedFold);
122+
123+
class PlotlyFold extends UnlocalizedFold {
124+
constructor(props, context) {
125+
super(props, context);
126+
127+
this.foldVisible = false;
128+
this.determineVisibility(props, context);
129+
}
130+
131+
componentWillReceiveProps(nextProps, nextContext) {
132+
this.determineVisibility(nextProps, nextContext);
133+
}
134+
135+
determineVisibility(nextProps, nextContext) {
136+
this.foldVisible = false;
137+
138+
React.Children.forEach(nextProps.children, child => {
139+
if (!child || this.foldVisible) {
140+
return;
141+
}
142+
143+
if (child.props.attr) {
144+
// attr components force fold open if they are visible
145+
const plotProps = unpackPlotProps(child.props, nextContext);
146+
if (child.type.modifyPlotProps) {
147+
child.type.modifyPlotProps(child.props, nextContext, plotProps);
148+
}
149+
150+
this.foldVisible = this.foldVisible || plotProps.isVisible;
151+
return;
152+
}
153+
154+
if (!(child.type.plotly_editor_traits || {}).no_visibility_forcing) {
155+
// non-attr components force visibility (unless they don't via traits)
156+
this.foldVisible = true;
157+
return;
158+
}
159+
});
160+
}
161+
}
162+
163+
PlotlyFold.plotly_editor_traits = {
164+
foldable: true,
165+
};
166+
167+
PlotlyFold.contextTypes = Object.assign(
155168
{
156169
deleteContainer: PropTypes.func,
157170
},
158171
containerConnectedContextTypes
159172
);
160173

161-
export default localize(Fold);
174+
export default localize(PlotlyFold);

src/components/containers/Panel.js renamed to src/components/containers/PlotlyPanel.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ PanelErrorImpl.propTypes = {
2626

2727
const PanelError = localize(PanelErrorImpl);
2828

29-
class Panel extends Component {
29+
class UnlocalizedPanel extends Component {
3030
constructor(props) {
3131
super(props);
3232
this.state = {
@@ -123,23 +123,23 @@ class Panel extends Component {
123123
}
124124
}
125125

126-
Panel.plotly_editor_traits = {no_visibility_forcing: true};
127-
128-
Panel.propTypes = {
126+
UnlocalizedPanel.propTypes = {
129127
children: PropTypes.node,
130128
addAction: PropTypes.object,
131129
showExpandCollapse: PropTypes.bool,
132130
noPadding: PropTypes.bool,
133131
};
134132

135-
Panel.defaultProps = {
133+
UnlocalizedPanel.defaultProps = {
136134
showExpandCollapse: true,
137135
};
138136

139-
Panel.contextTypes = {
140-
layout: PropTypes.object,
141-
onUpdate: PropTypes.func,
142-
updateContainer: PropTypes.func,
137+
export const Panel = localize(UnlocalizedPanel);
138+
139+
class PlotlyPanel extends UnlocalizedPanel {}
140+
141+
PlotlyPanel.plotly_editor_traits = {
142+
no_visibility_forcing: true,
143143
};
144144

145-
export default Panel;
145+
export default localize(PlotlyPanel);

src/components/containers/Section.js renamed to src/components/containers/PlotlySection.js

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,43 @@ import {
55
localize,
66
unpackPlotProps,
77
} from '../../lib';
8-
import SectionHeader from './SectionHeader';
98

10-
class Section extends Component {
11-
constructor(props, context) {
12-
super(props, context);
9+
class UnlocalizedSection extends Component {
10+
constructor() {
11+
super();
12+
this.sectionVisible = true;
13+
}
14+
15+
render() {
16+
if (!this.sectionVisible) {
17+
return null;
18+
}
19+
20+
return (
21+
<div className="section">
22+
{this.props.name ? (
23+
<div className="section__heading">
24+
<div className="section__heading__text">{this.props.name}</div>
25+
</div>
26+
) : null}
27+
{this.props.children}
28+
</div>
29+
);
30+
}
31+
}
32+
33+
UnlocalizedSection.plotly_editor_traits = {no_visibility_forcing: false};
34+
UnlocalizedSection.propTypes = {
35+
children: PropTypes.node,
36+
name: PropTypes.string,
37+
attr: PropTypes.string,
38+
};
1339

14-
this.sectionVisible = false;
40+
export const Section = localize(UnlocalizedSection);
1541

42+
class PlotlySection extends UnlocalizedSection {
43+
constructor(props, context) {
44+
super(props, context);
1645
this.determineVisibility(props, context);
1746
}
1847

@@ -25,7 +54,7 @@ class Section extends Component {
2554
this.sectionVisible = Boolean(isVisible);
2655

2756
React.Children.forEach(nextProps.children, child => {
28-
if (!child || this.foldVisible) {
57+
if (!child || this.sectionVisible) {
2958
return;
3059
}
3160

@@ -45,27 +74,8 @@ class Section extends Component {
4574
}
4675
});
4776
}
48-
49-
render() {
50-
if (!this.sectionVisible) {
51-
return null;
52-
}
53-
return (
54-
<div className="section">
55-
{this.props.name && <SectionHeader name={this.props.name} />}
56-
{this.props.children}
57-
</div>
58-
);
59-
}
6077
}
6178

62-
Section.plotly_editor_traits = {no_visibility_forcing: true};
63-
64-
Section.propTypes = {
65-
children: PropTypes.node,
66-
name: PropTypes.string,
67-
attr: PropTypes.string,
68-
};
69-
70-
Section.contextTypes = containerConnectedContextTypes;
71-
export default localize(Section);
79+
PlotlySection.plotly_editor_traits = {no_visibility_forcing: true};
80+
PlotlySection.contextTypes = containerConnectedContextTypes;
81+
export default localize(PlotlySection);

0 commit comments

Comments
 (0)