Skip to content

Commit a453179

Browse files
committed
Rebase
1 parent d050643 commit a453179

File tree

11 files changed

+93
-67
lines changed

11 files changed

+93
-67
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ The [custom editor example](https://github.com/plotly/react-chart-editor/tree/ma
7070
* `<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
7171
* `<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
7272
* `<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)
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

src/components/containers/PlotlyFold.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class PlotlyFold extends Component {
2525
determineVisibility(nextProps, nextContext) {
2626
this.foldVisible = false;
2727

28-
if (this.props.forceVisibility) {
28+
if (nextProps.forceVisibility) {
2929
this.foldVisible = true;
3030
return;
3131
}
@@ -167,6 +167,24 @@ PlotlyFold.contextTypes = Object.assign(
167167
export default localize(PlotlyFold);
168168

169169
export class Fold extends PlotlyFold {}
170+
171+
Fold.plotly_editor_traits = {
172+
foldable: true,
173+
};
174+
170175
Fold.defaultProps = {
171176
forceVisibility: true,
172177
};
178+
179+
Fold.propTypes = {
180+
children: PropTypes.node,
181+
className: PropTypes.string,
182+
folded: PropTypes.bool,
183+
toggleFold: PropTypes.func,
184+
hideHeader: PropTypes.bool,
185+
icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
186+
messageIfEmpty: PropTypes.string,
187+
localize: PropTypes.func,
188+
name: PropTypes.string,
189+
forceVisibility: PropTypes.bool,
190+
};

src/components/containers/PlotlyPanel.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class PlotlyPanel extends Component {
101101
toggleFold: () => this.toggleFold(index),
102102
});
103103
}
104+
104105
return child;
105106
}
106107
);
@@ -136,12 +137,6 @@ PlotlyPanel.defaultProps = {
136137
showExpandCollapse: true,
137138
};
138139

139-
PlotlyPanel.contextTypes = {
140-
layout: PropTypes.object,
141-
onUpdate: PropTypes.func,
142-
updateContainer: PropTypes.func,
143-
};
144-
145140
export default PlotlyPanel;
146141

147142
export class Panel extends PlotlyPanel {}

src/components/containers/PlotlySection.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@ export class Section extends Component {
1010
render() {
1111
return (
1212
<div className="section">
13-
<div className="section__heading">
14-
<div className="section__heading__text">{this.props.name}</div>
15-
</div>
13+
{this.props.name ? (
14+
<div className="section__heading">
15+
<div className="section__heading__text">{this.props.name}</div>
16+
</div>
17+
) : null}
1618
{this.props.children}
1719
</div>
1820
);

src/components/containers/TransformAccordion.js

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

7-
const TransformFold = connectTransformToTrace(Fold);
7+
const TransformFold = connectTransformToTrace(PlotlyFold);
88

99
class TransformAccordion extends Component {
1010
render() {
@@ -50,7 +50,11 @@ class TransformAccordion extends Component {
5050
}),
5151
};
5252

53-
return <Panel addAction={addAction}>{content ? content : null}</Panel>;
53+
return (
54+
<PlotlyPanel addAction={addAction}>
55+
{content ? content : null}
56+
</PlotlyPanel>
57+
);
5458
}
5559
}
5660

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

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,6 @@ describe('Basic PlotlyPanel rules', () => {
5555
it('HIDES Field because it needs context from PlotlyPanel', () =>
5656
expect(wrapper.find('input').length).toEqual(0));
5757
});
58-
59-
// describe('no PlotlyPanel, no context for Folds, not usable', () => {
60-
// expect(() => {
61-
// mount(
62-
// <TestEditor {...fixtures.scatter()}>
63-
// <div>
64-
// <PlotlyFold>
65-
// <div id="thediv"> ok </div>
66-
// <Numeric attr="title" />
67-
// </PlotlyFold>
68-
// </div>
69-
// </TestEditor>
70-
// );
71-
// }).toThrow();
72-
// });
7358
});
7459

7560
describe('Basic PlotlySection rules', () => {
@@ -299,7 +284,8 @@ describe('Basic PlotlyFold rules', () => {
299284

300285
it('HIDES PlotlyFold', () =>
301286
expect(wrapper.find('div.fold').length).toEqual(0));
302-
it('HIDES Info', () => expect(wrapper.find(Info).length).toEqual(0));
287+
it('HIDES Info', () =>
288+
expect(wrapper.find('.js-test-info').length).toEqual(0));
303289
it('HIDES Field', () =>
304290
expect(wrapper.find('input').length).toEqual(0));
305291
});

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

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,42 +27,47 @@ describe('Basic Panel rules', () => {
2727
const wrapper = mount(
2828
<TestEditor {...fixtures.scatter()}>
2929
<Panel>
30+
<Section>
31+
<div id="thediv"> ok </div>
32+
<Numeric attr="title" />
33+
</Section>
3034
<Fold>
31-
<Section>
32-
<div id="thediv"> ok </div>
33-
<Numeric attr="title" />
34-
</Section>
3535
<div id="theseconddiv" />
3636
</Fold>
37+
<Fold>
38+
<Info />
39+
</Fold>
3740
</Panel>
3841
</TestEditor>
3942
);
4043

41-
it('SHOWS Section, Fold, #thediv, #theseconddiv', () => {
44+
it('SHOWS Section, Fold, #thediv, #theseconddiv, Info', () => {
4245
expect(wrapper.find('div.section').length).toEqual(1);
43-
expect(wrapper.find('div.fold').length).toEqual(1);
46+
expect(wrapper.find('div.fold').length).toEqual(2);
4447
expect(wrapper.find('#thediv').length).toEqual(1);
4548
expect(wrapper.find('#theseconddiv').length).toEqual(1);
49+
expect(wrapper.find('.js-test-info').length).toEqual(1);
4650
});
4751

4852
it('HIDES Field because it needs context', () =>
4953
expect(wrapper.find('input').length).toEqual(0));
50-
});
5154

52-
// describe('no Panel, no context for Folds, not usable', () => {
53-
// expect(() => {
54-
// mount(
55-
// <TestEditor {...fixtures.scatter()}>
56-
// <div>
57-
// <Fold>
58-
// <div id="thediv"> ok </div>
59-
// <Numeric attr="title" />
60-
// </Fold>
61-
// </div>
62-
// </TestEditor>
63-
// );
64-
// }).toThrow();
65-
// });
55+
it('PANEL shows collapse functionality, FOLD is foldable', () => {
56+
expect(wrapper.find('.panel__header__collapse').length).toEqual(1);
57+
expect(
58+
wrapper
59+
.find(Fold)
60+
.first()
61+
.props().folded
62+
).toBe(false);
63+
expect(
64+
typeof wrapper
65+
.find(Fold)
66+
.first()
67+
.props().toggleFold
68+
).toBe('function');
69+
});
70+
});
6671
});
6772

6873
describe('Basic Section rules', () => {
@@ -100,6 +105,22 @@ describe('Basic Section rules', () => {
100105
it('SHOWS Field', () => expect(wrapper.find('input').length).toEqual(1));
101106
});
102107

108+
describe('PlotlyPanel > Section > Field-with-invisible-attr', () => {
109+
const wrapper = mount(
110+
<TestEditor {...fixtures.scatter()}>
111+
<LayoutPanel>
112+
<Section>
113+
<Numeric attr="not_an_attr" />
114+
</Section>
115+
</LayoutPanel>
116+
</TestEditor>
117+
);
118+
119+
it('SHOWS Section because it always shows itself', () =>
120+
expect(wrapper.find('div.section').length).toEqual(1));
121+
it('HIDES Field', () => expect(wrapper.find('input').length).toEqual(0));
122+
});
123+
103124
describe('Panel > Section > div', () => {
104125
const wrapper = mount(
105126
<TestEditor {...fixtures.scatter()}>
@@ -265,9 +286,9 @@ describe('Basic Fold rules', () => {
265286

266287
it('SHOWS Fold', () =>
267288
expect(wrapper.find('div.fold').length).toEqual(1));
268-
it('HIDES PlotlyPanel', () =>
289+
it('SHOWS PlotlyPanel', () =>
269290
expect(wrapper.find('div.panel').length).toEqual(2));
270-
it('HIDES Field', () =>
291+
it('SHOWS Field', () =>
271292
expect(wrapper.find('input').length).toEqual(1));
272293
});
273294
});
@@ -278,19 +299,16 @@ describe('Basic Fold rules', () => {
278299
<TestEditor {...fixtures.scatter()}>
279300
<LayoutPanel>
280301
<Fold>
281-
<Info>
282-
<Numeric attr="title" />
283-
</Info>
302+
<Info>ok</Info>
284303
</Fold>
285304
</LayoutPanel>
286305
</TestEditor>
287306
);
288307

289308
it('SHOWS Fold', () =>
290309
expect(wrapper.find('div.fold').length).toEqual(1));
291-
it('SHOWS Info', () => expect(wrapper.find(Info).length).toEqual(1));
292-
it('SHOWS Field', () =>
293-
expect(wrapper.find('input').length).toEqual(1));
310+
it('SHOWS Info', () =>
311+
expect(wrapper.find('.js-test-info').length).toEqual(1));
294312
});
295313
});
296314
});

src/components/fields/Info.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import React, {Component} from 'react';
33

44
export default class Info extends Component {
55
render() {
6-
return <Field {...this.props}>{this.props.children}</Field>;
6+
return (
7+
<Field {...this.props}>
8+
<div className="js-test-info">{this.props.children}</div>
9+
</Field>
10+
);
711
}
812
}
913

src/default_panels/GraphTransformsPanel.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import {
66
TraceAccordion,
77
DataSelector,
88
Dropdown,
9-
Section,
9+
PlotlySection,
1010
} from '../components';
1111
import {connectAggregationToTransform, localize} from '../lib';
1212

13-
const AggregationSection = connectAggregationToTransform(Section);
13+
const AggregationSection = connectAggregationToTransform(PlotlySection);
1414

1515
class UnlocalizedAggregations extends Component {
1616
render() {
@@ -69,9 +69,9 @@ const GraphTransformsPanel = ({localize: _}) => {
6969

7070
<DataSelector label={_('By')} attr="groups" />
7171

72-
<Section name={_('Aggregations')} attr="aggregations">
72+
<PlotlySection name={_('Aggregations')} attr="aggregations">
7373
<Aggregations />
74-
</Section>
74+
</PlotlySection>
7575
</TransformAccordion>
7676
</TraceAccordion>
7777
);

src/default_panels/StyleTracesPanel.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {
1212
NumericFractionInverse,
1313
Radio,
1414
TextEditor,
15-
Section,
1615
PlotlySection,
1716
LayoutSection,
1817
SymbolSelector,

0 commit comments

Comments
 (0)