Skip to content

Commit bf7420c

Browse files
committed
review adjustments
1 parent e812c1e commit bf7420c

File tree

4 files changed

+72
-68
lines changed

4 files changed

+72
-68
lines changed

dev/App.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class App extends Component {
186186
// chartHelp={chartHelp}
187187
>
188188
<DefaultEditor
189-
// order={[
189+
// menuPanelOrder={[
190190
// {group: 'Dev', name: 'JSON'},
191191
// {group: 'Dev', name: 'Inspector'},
192192
// {group: 'Structure', name: 'Create'},

src/DefaultEditor.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class DefaultEditor extends Component {
6969
const logo = this.props.logoSrc && <Logo src={this.props.logoSrc} />;
7070

7171
return (
72-
<PanelMenuWrapper order={this.props.order}>
72+
<PanelMenuWrapper menuPanelOrder={this.props.menuPanelOrder}>
7373
{logo ? logo : null}
7474
<GraphCreatePanel group={_('Structure')} name={_('Traces')} />
7575
<GraphSubplotsPanel group={_('Structure')} name={_('Subplots')} />
@@ -95,7 +95,7 @@ class DefaultEditor extends Component {
9595
DefaultEditor.propTypes = {
9696
children: PropTypes.node,
9797
logoSrc: PropTypes.string,
98-
order: PropTypes.array,
98+
menuPanelOrder: PropTypes.array,
9999
};
100100

101101
DefaultEditor.contextTypes = {

src/components/PanelMenuWrapper.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ class PanelsWithSidebar extends Component {
4747
}
4848

4949
computeMenuOptions(props) {
50-
const {children, order} = props;
50+
const {children, menuPanelOrder} = props;
5151
const sections = [];
5252
const groupLookup = {};
5353
let groupIndex;
5454
const panels = React.Children.toArray(children);
5555

56-
if (order) {
57-
sortMenu(panels, order);
56+
if (menuPanelOrder) {
57+
sortMenu(panels, menuPanelOrder);
5858
}
5959

6060
panels.forEach(child => {
@@ -107,7 +107,7 @@ class PanelsWithSidebar extends Component {
107107

108108
PanelsWithSidebar.propTypes = {
109109
children: PropTypes.node,
110-
order: PropTypes.array,
110+
menuPanelOrder: PropTypes.array,
111111
};
112112

113113
PanelsWithSidebar.childContextTypes = {

src/lib/__tests__/sortMenu-test.js

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
import sortMenu from '../sortMenu';
22

3+
function stringify(array) {
4+
let string = '';
5+
array.forEach(obj => {
6+
string += JSON.stringify(obj);
7+
});
8+
return string;
9+
}
10+
311
describe('sortMenu', () => {
412
it('modifies original array to follow the group, then name order provided', () => {
513
const initialArray = [
614
{props: {group: 'DEV', name: 'Inspector'}},
715
{props: {group: 'DEV', name: 'JSON'}},
816
];
917
const orderProp = [{group: 'DEV', name: 'JSON'}, {group: 'DEV', name: 'Inspector'}];
10-
sortMenu(initialArray, orderProp);
1118

12-
expect(initialArray[0].props.name).toBe('JSON');
13-
expect(initialArray[1].props.name).toBe('Inspector');
19+
sortMenu(initialArray, orderProp);
20+
expect(stringify(initialArray)).toBe(
21+
stringify([{props: {group: 'DEV', name: 'JSON'}}, {props: {group: 'DEV', name: 'Inspector'}}])
22+
);
1423
});
1524

1625
it('sorts the array by group, then by name', () => {
@@ -22,7 +31,6 @@ describe('sortMenu', () => {
2231
{props: {group: 'DEV', name: 'Inspector'}},
2332
{props: {group: 'DEV', name: 'JSON'}},
2433
];
25-
2634
const orderProp = [
2735
{group: 'DEV', name: 'JSON'},
2836
{group: 'DEV', name: 'Inspector'},
@@ -33,18 +41,16 @@ describe('sortMenu', () => {
3341
];
3442

3543
sortMenu(initialArray, orderProp);
36-
expect(initialArray[0].props.group).toBe('DEV');
37-
expect(initialArray[0].props.name).toBe('JSON');
38-
expect(initialArray[1].props.group).toBe('DEV');
39-
expect(initialArray[1].props.name).toBe('Inspector');
40-
expect(initialArray[2].props.group).toBe('Structure');
41-
expect(initialArray[2].props.name).toBe('Subplots');
42-
expect(initialArray[3].props.group).toBe('Structure');
43-
expect(initialArray[3].props.name).toBe('Create');
44-
expect(initialArray[4].props.group).toBe('Style');
45-
expect(initialArray[4].props.name).toBe('Color Bars');
46-
expect(initialArray[5].props.group).toBe('Style');
47-
expect(initialArray[5].props.name).toBe('Annotation');
44+
expect(stringify(initialArray)).toBe(
45+
stringify([
46+
{props: {group: 'DEV', name: 'JSON'}},
47+
{props: {group: 'DEV', name: 'Inspector'}},
48+
{props: {group: 'Structure', name: 'Subplots'}},
49+
{props: {group: 'Structure', name: 'Create'}},
50+
{props: {group: 'Style', name: 'Color Bars'}},
51+
{props: {group: 'Style', name: 'Annotation'}},
52+
])
53+
);
4854
});
4955

5056
it('puts not mentionned panels to the bottom of list and sorts alphabetically', () => {
@@ -64,18 +70,16 @@ describe('sortMenu', () => {
6470
];
6571

6672
sortMenu(initialArray, orderProp);
67-
expect(initialArray[0].props.group).toBe('Structure');
68-
expect(initialArray[0].props.name).toBe('Subplots');
69-
expect(initialArray[1].props.group).toBe('Structure');
70-
expect(initialArray[1].props.name).toBe('Create');
71-
expect(initialArray[2].props.group).toBe('Style');
72-
expect(initialArray[2].props.name).toBe('Color Bars');
73-
expect(initialArray[3].props.group).toBe('Style');
74-
expect(initialArray[3].props.name).toBe('Annotation');
75-
expect(initialArray[4].props.group).toBe('DEV');
76-
expect(initialArray[4].props.name).toBe('Inspector');
77-
expect(initialArray[5].props.group).toBe('DEV');
78-
expect(initialArray[5].props.name).toBe('JSON');
73+
expect(stringify(initialArray)).toBe(
74+
stringify([
75+
{props: {group: 'Structure', name: 'Subplots'}},
76+
{props: {group: 'Structure', name: 'Create'}},
77+
{props: {group: 'Style', name: 'Color Bars'}},
78+
{props: {group: 'Style', name: 'Annotation'}},
79+
{props: {group: 'DEV', name: 'Inspector'}},
80+
{props: {group: 'DEV', name: 'JSON'}},
81+
])
82+
);
7983
});
8084

8185
it('orders not mentionned subpanels at the end, alphabetically', () => {
@@ -85,17 +89,17 @@ describe('sortMenu', () => {
8589
{props: {group: 'Style', name: 'Axes'}},
8690
{props: {group: 'Structure', name: 'Create'}},
8791
];
88-
const orderProp = [{group: 'Style', name: 'Traces'}, {group: 'Structure', name: 'Create'}];
92+
const orderProp = [{group: 'Style', name: 'Traces'}];
8993

9094
sortMenu(initialArray, orderProp);
91-
expect(initialArray[0].props.group).toBe('Style');
92-
expect(initialArray[0].props.name).toBe('Traces');
93-
expect(initialArray[1].props.group).toBe('Style');
94-
expect(initialArray[1].props.name).toBe('Axes');
95-
expect(initialArray[2].props.group).toBe('Style');
96-
expect(initialArray[2].props.name).toBe('General');
97-
expect(initialArray[3].props.group).toBe('Structure');
98-
expect(initialArray[3].props.name).toBe('Create');
95+
expect(stringify(initialArray)).toBe(
96+
stringify([
97+
{props: {group: 'Style', name: 'Traces'}},
98+
{props: {group: 'Style', name: 'Axes'}},
99+
{props: {group: 'Style', name: 'General'}},
100+
{props: {group: 'Structure', name: 'Create'}},
101+
])
102+
);
99103
});
100104

101105
it('ignores non existent panel groups', () => {
@@ -114,14 +118,14 @@ describe('sortMenu', () => {
114118
];
115119

116120
sortMenu(initialArray, orderProp);
117-
expect(initialArray[0].props.group).toBe('Structure');
118-
expect(initialArray[0].props.name).toBe('Create');
119-
expect(initialArray[1].props.group).toBe('Structure');
120-
expect(initialArray[1].props.name).toBe('Subplots');
121-
expect(initialArray[2].props.group).toBe('Style');
122-
expect(initialArray[2].props.name).toBe('Color Bars');
123-
expect(initialArray[3].props.group).toBe('Style');
124-
expect(initialArray[3].props.name).toBe('Annotation');
121+
expect(stringify(initialArray)).toBe(
122+
stringify([
123+
{props: {group: 'Structure', name: 'Create'}},
124+
{props: {group: 'Structure', name: 'Subplots'}},
125+
{props: {group: 'Style', name: 'Color Bars'}},
126+
{props: {group: 'Style', name: 'Annotation'}},
127+
])
128+
);
125129
});
126130

127131
it('ignores non existent panel names', () => {
@@ -139,14 +143,14 @@ describe('sortMenu', () => {
139143
];
140144

141145
sortMenu(initialArray, orderProp);
142-
expect(initialArray[0].props.group).toBe('Style');
143-
expect(initialArray[0].props.name).toBe('Color Bars');
144-
expect(initialArray[1].props.group).toBe('Style');
145-
expect(initialArray[1].props.name).toBe('Annotation');
146-
expect(initialArray[2].props.group).toBe('Structure');
147-
expect(initialArray[2].props.name).toBe('Create');
148-
expect(initialArray[3].props.group).toBe('Structure');
149-
expect(initialArray[3].props.name).toBe('Subplots');
146+
expect(stringify(initialArray)).toBe(
147+
stringify([
148+
{props: {group: 'Style', name: 'Color Bars'}},
149+
{props: {group: 'Style', name: 'Annotation'}},
150+
{props: {group: 'Structure', name: 'Create'}},
151+
{props: {group: 'Structure', name: 'Subplots'}},
152+
])
153+
);
150154
});
151155

152156
it('ignores invalid combinations', () => {
@@ -164,13 +168,13 @@ describe('sortMenu', () => {
164168
];
165169

166170
sortMenu(initialArray, orderProp);
167-
expect(initialArray[0].props.group).toBe('Style');
168-
expect(initialArray[0].props.name).toBe('Color Bars');
169-
expect(initialArray[1].props.group).toBe('Style');
170-
expect(initialArray[1].props.name).toBe('Annotation');
171-
expect(initialArray[2].props.group).toBe('Structure');
172-
expect(initialArray[2].props.name).toBe('Create');
173-
expect(initialArray[3].props.group).toBe('Structure');
174-
expect(initialArray[3].props.name).toBe('Subplots');
171+
expect(stringify(initialArray)).toBe(
172+
stringify([
173+
{props: {group: 'Style', name: 'Color Bars'}},
174+
{props: {group: 'Style', name: 'Annotation'}},
175+
{props: {group: 'Structure', name: 'Create'}},
176+
{props: {group: 'Structure', name: 'Subplots'}},
177+
])
178+
);
175179
});
176180
});

0 commit comments

Comments
 (0)