@@ -6,7 +6,12 @@ import MinuteSecondInput from '../MinuteSecondInput'
6
6
7
7
export default class PatternStopPopup extends Component {
8
8
render ( ) {
9
+ console . log ( this . props )
9
10
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
10
15
return (
11
16
< div
12
17
style = { { minWidth : '240px' } } // keep button group from separating
@@ -49,7 +54,7 @@ export default class PatternStopPopup extends Component {
49
54
>
50
55
< Button
51
56
bsStyle = 'success'
52
- disabled = { index >= activePattern . patternStops . length - 2 }
57
+ disabled = { addToEndDisabled }
53
58
onClick = { ( e ) => {
54
59
addStopToPattern ( activePattern , stop )
55
60
} }
@@ -59,23 +64,28 @@ export default class PatternStopPopup extends Component {
59
64
< Dropdown . Toggle bsStyle = 'success' />
60
65
< Dropdown . Menu style = { { maxHeight : '200px' , overflowY : 'scroll' } } >
61
66
< MenuItem
62
- disabled = { index >= activePattern . patternStops . length - 1 }
67
+ disabled = { addToEndDisabled }
63
68
value = { activePattern . patternStops . length }
64
69
eventKey = { activePattern . patternStops . length } >
65
70
Add to end (default)
66
71
</ MenuItem >
67
- { activePattern . patternStops && activePattern . patternStops . map ( ( stop , i ) => {
72
+ { activePattern . patternStops && activePattern . patternStops . map ( ( s , i ) => {
68
73
// addIndex is in "reverse" order
69
74
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)
70
79
// skip MenuItem index is the same as the pattern stop index
71
- if ( index === addIndex - 1 ) {
80
+ if ( index === addIndex - 1 || addIndex === 1 ) {
72
81
return null
73
82
}
74
83
// disable adding stop to current position or directly before/after current position
75
84
return (
76
85
< MenuItem
77
- disabled = { index >= addIndex - 2 && index < addIndex }
86
+ disabled = { addAtIndexDisabled }
78
87
value = { addIndex - 1 }
88
+ title = { addAtIndexDisabled ? `Cannot have the same stop appear consecutively in list` : '' }
79
89
key = { i }
80
90
eventKey = { addIndex - 1 }
81
91
>
@@ -84,7 +94,7 @@ export default class PatternStopPopup extends Component {
84
94
)
85
95
} ) }
86
96
< MenuItem
87
- disabled = { index === 0 }
97
+ disabled = { addToBeginningDisabled }
88
98
value = { 0 }
89
99
eventKey = { 0 }
90
100
>
0 commit comments