mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	have a random somewhat uid per entry for sort to work
This commit is contained in:
		
							parent
							
								
									7243dce22d
								
							
						
					
					
						commit
						bad6c95fa2
					
				| @ -32,6 +32,7 @@ const prepare = (methods, dispatch) => { | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     methods.addStrategy = (v) => { |     methods.addStrategy = (v) => { | ||||||
|  |         v.id = Math.round(Math.random() * 10000000); | ||||||
|         methods.pushToList('strategies', v); |         methods.pushToList('strategies', v); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -13,7 +13,12 @@ function getId (props) { | |||||||
| // best is to emulate the "input-storage"? | // best is to emulate the "input-storage"? | ||||||
| const mapStateToProps = createMapper({ | const mapStateToProps = createMapper({ | ||||||
|     id: getId, |     id: getId, | ||||||
|     getDefault: (state, ownProps) => ownProps.featureToggle, |     getDefault: (state, ownProps) => { | ||||||
|  |         ownProps.featureToggle.strategies.forEach((strategy, index) => { | ||||||
|  |             strategy.id = Math.round(Math.random() * 1000000 * (1 + index)); | ||||||
|  |         }); | ||||||
|  |         return ownProps.featureToggle; | ||||||
|  |     }, | ||||||
|     prepare: (props) => { |     prepare: (props) => { | ||||||
|         props.editmode = true; |         props.editmode = true; | ||||||
|         return props; |         return props; | ||||||
| @ -38,6 +43,7 @@ const prepare =  (methods, dispatch) => { | |||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     methods.addStrategy = (v) => { |     methods.addStrategy = (v) => { | ||||||
|  |         v.id = Math.round(Math.random() * 10000000); | ||||||
|         methods.pushToList('strategies', v); |         methods.pushToList('strategies', v); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ class StrategiesList extends React.Component { | |||||||
|         const blocks = configuredStrategies.map((strategy, i) => ( |         const blocks = configuredStrategies.map((strategy, i) => ( | ||||||
|             <ConfigureStrategy |             <ConfigureStrategy | ||||||
|                 index={i} |                 index={i} | ||||||
|                 key={`${strategy.name}-${i}`} |                 key={strategy.id} | ||||||
|                 strategy={strategy} |                 strategy={strategy} | ||||||
|                 moveStrategy={moveStrategy} |                 moveStrategy={moveStrategy} | ||||||
|                 removeStrategy={removeStrategy.bind(null, i)} |                 removeStrategy={removeStrategy.bind(null, i)} | ||||||
|  | |||||||
| @ -26,18 +26,26 @@ const helpText = { | |||||||
| const dragSource = { | const dragSource = { | ||||||
|     beginDrag (props) { |     beginDrag (props) { | ||||||
|         return { |         return { | ||||||
|  |             id: props.id, | ||||||
|             index: props.index, |             index: props.index, | ||||||
|         }; |         }; | ||||||
|     }, |     }, | ||||||
|  |     endDrag (props, monitor) { | ||||||
|  |         if (!monitor.didDrop()) { | ||||||
|  |             return; | ||||||
|  |         } | ||||||
|  |         const result = monitor.getDropResult(); | ||||||
|  |         if (typeof result.index === 'number' && props.index !== result.index) { | ||||||
|  |             props.moveStrategy(props.index, result.index); | ||||||
|  |         } | ||||||
|  |     }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| const dragTarget = { | const dragTarget = { | ||||||
|     drop (props, monitor) { |     drop (props) { | ||||||
|         const dragIndex = monitor.getItem().index; |         return { | ||||||
|         const toIndex = props.index; |             index: props.index, | ||||||
|         if (dragIndex !== toIndex) { |         }; | ||||||
|             props.moveStrategy(dragIndex, toIndex); |  | ||||||
|         } |  | ||||||
|     }, |     }, | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user