Skip to content

Commit 1511327

Browse files
committed
fix(PatternStopPopup): prevent stop from appearing consecutively by disabling all entries where stop
1 parent aed3e6b commit 1511327

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/editor/components/map/PatternStopPopup.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import MinuteSecondInput from '../MinuteSecondInput'
66

77
export default class PatternStopPopup extends Component {
88
render () {
9+
console.log(this.props)
910
const { stop, index, patternStop, activePattern, entityEdited, saveActiveEntity, setActiveEntity, feedSource, removeStopFromPattern, addStopToPattern, updateActiveEntity, controlPoints } = this.props
11+
const {patternStops} = activePattern
12+
const lastIndex = patternStops.length - 1
13+
const addToEndDisabled = index >= lastIndex || patternStops[lastIndex].stopId === stop.id
14+
const addToBeginningDisabled = index === 0 || patternStops[0].stopId === stop.id
1015
return (
1116
<div
1217
style={{minWidth: '240px'}} // keep button group from separating
@@ -49,7 +54,7 @@ export default class PatternStopPopup extends Component {
4954
>
5055
<Button
5156
bsStyle='success'
52-
disabled={index >= activePattern.patternStops.length - 2}
57+
disabled={addToEndDisabled}
5358
onClick={(e) => {
5459
addStopToPattern(activePattern, stop)
5560
}}
@@ -59,23 +64,28 @@ export default class PatternStopPopup extends Component {
5964
<Dropdown.Toggle bsStyle='success' />
6065
<Dropdown.Menu style={{maxHeight: '200px', overflowY: 'scroll'}}>
6166
<MenuItem
62-
disabled={index >= activePattern.patternStops.length - 1}
67+
disabled={addToEndDisabled}
6368
value={activePattern.patternStops.length}
6469
eventKey={activePattern.patternStops.length}>
6570
Add to end (default)
6671
</MenuItem>
67-
{activePattern.patternStops && activePattern.patternStops.map((stop, i) => {
72+
{activePattern.patternStops && activePattern.patternStops.map((s, i) => {
6873
// addIndex is in "reverse" order
6974
const addIndex = activePattern.patternStops.length - i
75+
const addAtIndexDisabled = (index >= addIndex - 2 && index < addIndex) ||
76+
(patternStops[addIndex - 2] && patternStops[addIndex - 2].stopId === stop.id) ||
77+
(patternStops[addIndex - 1] && patternStops[addIndex - 1].stopId === stop.id)
78+
// (patternStops[addIndex + 1] && patternStops[addIndex + 1].stopId === stop.id)
7079
// skip MenuItem index is the same as the pattern stop index
71-
if (index === addIndex - 1) {
80+
if (index === addIndex - 1 || addIndex === 1) {
7281
return null
7382
}
7483
// disable adding stop to current position or directly before/after current position
7584
return (
7685
<MenuItem
77-
disabled={index >= addIndex - 2 && index < addIndex}
86+
disabled={addAtIndexDisabled}
7887
value={addIndex - 1}
88+
title={addAtIndexDisabled ? `Cannot have the same stop appear consecutively in list` : ''}
7989
key={i}
8090
eventKey={addIndex - 1}
8191
>
@@ -84,7 +94,7 @@ export default class PatternStopPopup extends Component {
8494
)
8595
})}
8696
<MenuItem
87-
disabled={index === 0}
97+
disabled={addToBeginningDisabled}
8898
value={0}
8999
eventKey={0}
90100
>

0 commit comments

Comments
 (0)