Skip to content

Commit 35c50ab

Browse files
authored
Merge pull request #250 from plotly/aulneau-fixes-1
Language style fixes, empty state for style panels
2 parents e56af20 + 5af29bc commit 35c50ab

File tree

21 files changed

+463
-342
lines changed

21 files changed

+463
-342
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ All Fields except `<Info />` accept an `attr` property to bind them to a key in
158158

159159
* `<TraceAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to traces via `connectTraceToPlot()`.
160160
* `<LayoutPanel />`: `<Panel />` whose children are connected to the `layout` figure key
161+
* `<TraceRequiredPanel />`: `<LayoutPanel />` renders `<PanelEmpty />` if no trace data is set
161162
* `<AnnotationAccordion />`: `<Panel />` whose children are replicated into `<Folds />` connected to annotations via `connectAnnotationToLayout()`. For use in a `<LayoutPanel />`.
162163
* `<AxesFold />`: `<Fold />` whose children are bound to axis-specific keys. For use in a `<LayoutPanel />` in concert with `<AxesSelector />` (see below).
163164
* `<TraceMarkerSection />`: `<Section />` with trace-specific name handling. For use in containers bound to traces e.g. as children of `<TraceAccordion />`.

scripts/translationKeys/combined-translation-keys.txt

Lines changed: 124 additions & 126 deletions
Large diffs are not rendered by default.

scripts/translationKeys/translation-keys.txt

Lines changed: 124 additions & 126 deletions
Large diffs are not rendered by default.

src/DefaultEditor.js

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ import {
2929
SymbolSelector,
3030
TraceAccordion,
3131
TraceMarkerSection,
32+
TraceRequiredPanel,
3233
TraceSelector,
33-
LayoutPanel,
3434
AxesFold,
3535
} from './components';
3636
import {localize} from './lib';
@@ -69,7 +69,8 @@ class DefaultEditor extends Component {
6969
<DataSelector label="Z" attr="z" clearable={false} hasBlank />
7070
</TraceAccordion>
7171
</Panel>
72-
<Panel group="Style" name="Traces">
72+
73+
<TraceRequiredPanel group="Style" name="Traces">
7374
<TraceAccordion>
7475
<Section name={_('Trace')}>
7576
<Numeric label={_('Opacity')} step={0.1} attr="opacity" />
@@ -164,8 +165,9 @@ class DefaultEditor extends Component {
164165
/>
165166
</Section>
166167
</TraceAccordion>
167-
</Panel>
168-
<LayoutPanel group="Style" name={_('Layout')}>
168+
</TraceRequiredPanel>
169+
170+
<TraceRequiredPanel group="Style" name={_('Layout')}>
169171
<Fold name={_('Canvas')}>
170172
<Radio
171173
attr="autosize"
@@ -211,8 +213,9 @@ class DefaultEditor extends Component {
211213
<Numeric label={_('Right')} attr="margin.r" units="px" />
212214
<Numeric label={_('Padding')} attr="margin.pad" units="px" />
213215
</Fold>
214-
</LayoutPanel>
215-
<LayoutPanel group="Style" name={_('Notes')}>
216+
</TraceRequiredPanel>
217+
218+
<TraceRequiredPanel group="Style" name={_('Notes')}>
216219
<AnnotationAccordion canAdd>
217220
<Section name={_('Note Text')}>
218221
<MultiFormatTextEditor attr="text" />
@@ -290,8 +293,9 @@ class DefaultEditor extends Component {
290293
<Numeric label={_('Position')} attr="y" hideArrows />
291294
</Section>
292295
</AnnotationAccordion>
293-
</LayoutPanel>
294-
<LayoutPanel group="Style" name={_('Axes')}>
296+
</TraceRequiredPanel>
297+
298+
<TraceRequiredPanel group="Style" name={_('Axes')}>
295299
<AxesFold name={_('Titles')}>
296300
<AxesSelector />
297301
<MultiFormatTextEditor attr="title" />
@@ -342,8 +346,9 @@ class DefaultEditor extends Component {
342346
<AxesFold name={_('Layout')}>
343347
<AxesSelector />
344348
</AxesFold>
345-
</LayoutPanel>
346-
<LayoutPanel group="Style" name={_('Legend')}>
349+
</TraceRequiredPanel>
350+
351+
<TraceRequiredPanel group="Style" name={_('Legend')}>
347352
<Fold hideHeader>
348353
<Section name={_('Legend')}>
349354
<Radio
@@ -435,7 +440,7 @@ class DefaultEditor extends Component {
435440
/>
436441
</Section>
437442
</Fold>
438-
</LayoutPanel>
443+
</TraceRequiredPanel>
439444
</PanelMenuWrapper>
440445
);
441446
}

src/components/containers/Panel.js

Lines changed: 35 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import React, {Component, cloneElement} from 'react';
44
import update from 'immutability-helper';
55
import {bem} from 'lib';
66

7-
export default class Panel extends Component {
7+
class Panel extends Component {
88
constructor(props) {
99
super(props);
1010
this.state = {
@@ -62,6 +62,38 @@ export default class Panel extends Component {
6262
return array.map((e, i) => i !== lastIndex);
6363
}
6464

65+
calculateFolds() {
66+
// to get proper number of child folds and initialize component state
67+
const {visible} = this.props;
68+
const {nbOfFolds} = this.state;
69+
70+
if (visible) {
71+
const currentNbOfFolds = document.getElementsByClassName('fold').length;
72+
if (nbOfFolds !== currentNbOfFolds) {
73+
if (this.isAnnotationAccordion() || this.isTraceAccordion()) {
74+
this.setState({
75+
nbOfFolds: currentNbOfFolds,
76+
individualFoldStates: this.closeAllButLast(
77+
new Array(currentNbOfFolds).fill(true)
78+
),
79+
});
80+
} else {
81+
this.setState({
82+
nbOfFolds: currentNbOfFolds,
83+
individualFoldStates: new Array(currentNbOfFolds).fill(false),
84+
});
85+
}
86+
}
87+
}
88+
}
89+
90+
componentDidUpdate() {
91+
this.calculateFolds();
92+
}
93+
componentDidMount() {
94+
this.calculateFolds();
95+
}
96+
6597
render() {
6698
const {visible} = this.props;
6799
const {individualFoldStates, nbOfFolds} = this.state;
@@ -109,33 +141,6 @@ export default class Panel extends Component {
109141
}
110142
return null;
111143
}
112-
113-
componentDidUpdate() {
114-
// to get proper number of child folds and initialize component state
115-
const {visible} = this.props;
116-
const {nbOfFolds} = this.state;
117-
118-
if (visible) {
119-
const currentNbOfFolds = document.getElementsByClassName('fold').length;
120-
if (nbOfFolds !== currentNbOfFolds) {
121-
/* eslint-disable */
122-
if (this.isAnnotationAccordion() || this.isTraceAccordion()) {
123-
this.setState({
124-
nbOfFolds: currentNbOfFolds,
125-
individualFoldStates: this.closeAllButLast(
126-
new Array(currentNbOfFolds).fill(true)
127-
),
128-
});
129-
} else {
130-
this.setState({
131-
nbOfFolds: currentNbOfFolds,
132-
individualFoldStates: new Array(currentNbOfFolds).fill(false),
133-
});
134-
}
135-
/* eslint-enable */
136-
}
137-
}
138-
}
139144
}
140145

141146
Panel.propTypes = {
@@ -157,3 +162,5 @@ Panel.childContextTypes = {
157162
individualFoldStates: PropTypes.array,
158163
toggleFold: PropTypes.func,
159164
};
165+
166+
export default Panel;

src/components/containers/PanelEmpty.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import PropTypes from 'prop-types';
22
import React, {Component} from 'react';
33
import {ChartLineIcon} from 'plotly-icons';
4-
import {bem} from 'lib';
4+
import {bem, localize} from 'lib';
55

6-
export default class PanelEmpty extends Component {
6+
class PanelEmpty extends Component {
77
render() {
8-
const {children, message, heading, icon: Icon} = this.props;
8+
const {
9+
children,
10+
localize: _,
11+
heading = _("Looks like there aren't any traces defined yet."),
12+
message = _("Go to the 'Create' tab to define traces."),
13+
icon: Icon,
14+
} = this.props;
915

1016
return (
1117
<div className={bem('panel', 'empty')}>
@@ -15,7 +21,7 @@ export default class PanelEmpty extends Component {
1521
</div>
1622
<div className="panel__empty__message__heading">{heading}</div>
1723
<div className="panel__empty__message__content">
18-
{message}
24+
<p>{message}</p>
1925
{children}
2026
</div>
2127
</div>
@@ -27,6 +33,9 @@ export default class PanelEmpty extends Component {
2733
PanelEmpty.propTypes = {
2834
heading: PropTypes.string,
2935
message: PropTypes.any,
36+
localize: PropTypes.func,
3037
children: PropTypes.node,
3138
icon: PropTypes.oneOfType([PropTypes.node, PropTypes.func]),
3239
};
40+
41+
export default localize(PanelEmpty);

src/components/containers/TraceAccordion.js

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Fold from './Fold';
2-
import PanelEmpty from 'components/containers/PanelEmpty';
32
import PropTypes from 'prop-types';
43
import React, {Component} from 'react';
54
import {EDITOR_ACTIONS} from 'lib/constants';
@@ -17,50 +16,20 @@ class TraceAccordion extends Component {
1716
}
1817

1918
render() {
20-
const {fullData, data = []} = this.context;
21-
const {canAdd, children, localize: _} = this.props;
19+
const {data = []} = this.context;
20+
const {canAdd, children} = this.props;
2221

2322
const content =
2423
data.length &&
2524
data.map((d, i) => {
26-
const fullDataTrace = fullData.filter(t => t.index === i)[0];
27-
const isEmpty =
28-
!canAdd && !fullDataTrace.visible
29-
? {
30-
messagePrimary: _('This trace does not yet have any data.'),
31-
messageSecondary: _(
32-
'Return to the Graph > Create menu above to add data.'
33-
),
34-
}
35-
: false;
36-
3725
return (
38-
<TraceFold
39-
key={i}
40-
traceIndex={i}
41-
foldIndex={i}
42-
canDelete={canAdd}
43-
isEmpty={isEmpty}
44-
>
26+
<TraceFold key={i} traceIndex={i} foldIndex={i} canDelete={canAdd}>
4527
{children}
4628
</TraceFold>
4729
);
4830
});
4931

50-
const emptyState = !canAdd &&
51-
(!data.length || (data.length === 1 && !fullData[0].visible)) && (
52-
<PanelEmpty
53-
heading={_("Looks like there aren't any traces defined yet.")}
54-
message={<p>{_("Go to the 'Create' tab to define traces.")}</p>}
55-
/>
56-
);
57-
58-
return (
59-
<div className="panel__content">
60-
{emptyState ? emptyState : null}
61-
{content ? content : null}
62-
</div>
63-
);
32+
return <div className="panel__content">{content ? content : null}</div>;
6433
}
6534
}
6635

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import React, {Component} from 'react';
2+
import PropTypes from 'prop-types';
3+
import PanelEmpty from './PanelEmpty';
4+
import Panel from './Panel';
5+
import {connectLayoutToPlot} from 'lib';
6+
7+
const LayoutPanel = connectLayoutToPlot(Panel);
8+
9+
class TraceRequiredPanel extends Component {
10+
constructor(props) {
11+
super(props);
12+
this.state = {
13+
hasTraces: false,
14+
};
15+
}
16+
checkTraceExistence() {
17+
const {visible} = this.props;
18+
const {fullData} = this.context;
19+
const {hasTraces} = this.state;
20+
21+
if (visible) {
22+
/**
23+
* Check if there is any trace data
24+
*/
25+
if (fullData.filter(trace => trace.visible).length === 0 && hasTraces) {
26+
this.setState({
27+
hasTraces: false,
28+
});
29+
} else {
30+
this.setState({
31+
hasTraces: true,
32+
});
33+
}
34+
}
35+
}
36+
37+
componentDidUpdate() {
38+
this.checkTraceExistence();
39+
}
40+
componentDidMount() {
41+
this.checkTraceExistence();
42+
}
43+
44+
render() {
45+
const {children, ...rest} = this.props;
46+
const {hasTraces} = this.state;
47+
48+
if (this.props.visible) {
49+
return hasTraces ? (
50+
<LayoutPanel {...rest}>{children}</LayoutPanel>
51+
) : (
52+
<PanelEmpty />
53+
);
54+
}
55+
return null;
56+
}
57+
}
58+
59+
TraceRequiredPanel.propTypes = {
60+
children: PropTypes.node,
61+
visible: PropTypes.bool,
62+
};
63+
64+
TraceRequiredPanel.defaultProps = {
65+
visible: true,
66+
};
67+
68+
TraceRequiredPanel.contextTypes = {
69+
fullData: PropTypes.array,
70+
};
71+
72+
export default TraceRequiredPanel;

src/components/containers/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Section from './Section';
66
import TraceAccordion from './TraceAccordion';
77
import TraceMarkerSection from './TraceMarkerSection';
88
import {LayoutPanel, AxesFold} from './derived';
9+
import TraceRequiredPanel from './TraceRequiredPanel';
910

1011
export {
1112
AnnotationAccordion,
@@ -15,6 +16,7 @@ export {
1516
Section,
1617
TraceAccordion,
1718
TraceMarkerSection,
19+
TraceRequiredPanel,
1820
LayoutPanel,
1921
AxesFold,
2022
};

src/components/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
Section,
3131
TraceAccordion,
3232
TraceMarkerSection,
33+
TraceRequiredPanel,
3334
LayoutPanel,
3435
AxesFold,
3536
} from './containers';
@@ -65,6 +66,7 @@ export {
6566
SymbolSelector,
6667
TraceAccordion,
6768
TraceMarkerSection,
69+
TraceRequiredPanel,
6870
TraceSelector,
6971
LayoutPanel,
7072
AxesFold,

0 commit comments

Comments
 (0)