Skip to content

Commit f8bded6

Browse files
committed
add constant for readability
1 parent 9aaaf96 commit f8bded6

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

src/components/PanelMenuWrapper.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,20 @@ class PanelsWithSidebar extends Component {
6161
const nameOrder = order.map(panel => panel.name).filter(this.getUniqueValues);
6262

6363
orderedChildren.sort((a, b) => {
64+
const panelAHasCustomOrder = groupOrder.includes(a.props.group);
65+
const panelBHasCustomOrder = groupOrder.includes(b.props.group);
66+
6467
// if one of the elements is not in the groupOrder array, then it goes to the end of the list
65-
if (groupOrder.includes(a.props.group) && !groupOrder.includes(b.props.group)) {
68+
if (panelAHasCustomOrder && !panelBHasCustomOrder) {
6669
return -1;
6770
}
68-
if (!groupOrder.includes(a.props.group) && groupOrder.includes(b.props.group)) {
71+
if (!panelAHasCustomOrder && panelBHasCustomOrder) {
6972
return 1;
7073
}
7174

7275
// if both elements are not in the groupOrder array, they get sorted alphabetically,
7376
// by group, then by name
74-
if (!groupOrder.includes(a.props.group) && !groupOrder.includes(b.props.group)) {
77+
if (!panelAHasCustomOrder && !panelBHasCustomOrder) {
7578
const sortByGroup =
7679
a.props.group === b.props.group ? 0 : a.props.group < b.props.group ? -1 : 1;
7780
const sortByName =
@@ -81,7 +84,7 @@ class PanelsWithSidebar extends Component {
8184

8285
// if both elements are in the groupOrder array, they get sorted according to their order in
8386
// the groupOrder, then nameOrder arrays.
84-
if (groupOrder.includes(a.props.group) && groupOrder.includes(b.props.group)) {
87+
if (panelAHasCustomOrder && panelBHasCustomOrder) {
8588
const sortByGroup = groupOrder.indexOf(a.props.group) - groupOrder.indexOf(b.props.group);
8689
const sortByName = nameOrder.indexOf(a.props.name) - nameOrder.indexOf(b.props.name);
8790
return sortByGroup || sortByName;

0 commit comments

Comments
 (0)