mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +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) => {
|
||||
v.id = Math.round(Math.random() * 10000000);
|
||||
methods.pushToList('strategies', v);
|
||||
};
|
||||
|
||||
|
@ -13,7 +13,12 @@ function getId (props) {
|
||||
// best is to emulate the "input-storage"?
|
||||
const mapStateToProps = createMapper({
|
||||
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) => {
|
||||
props.editmode = true;
|
||||
return props;
|
||||
@ -38,6 +43,7 @@ const prepare = (methods, dispatch) => {
|
||||
};
|
||||
|
||||
methods.addStrategy = (v) => {
|
||||
v.id = Math.round(Math.random() * 10000000);
|
||||
methods.pushToList('strategies', v);
|
||||
};
|
||||
|
||||
|
@ -32,7 +32,7 @@ class StrategiesList extends React.Component {
|
||||
const blocks = configuredStrategies.map((strategy, i) => (
|
||||
<ConfigureStrategy
|
||||
index={i}
|
||||
key={`${strategy.name}-${i}`}
|
||||
key={strategy.id}
|
||||
strategy={strategy}
|
||||
moveStrategy={moveStrategy}
|
||||
removeStrategy={removeStrategy.bind(null, i)}
|
||||
|
@ -26,18 +26,26 @@ const helpText = {
|
||||
const dragSource = {
|
||||
beginDrag (props) {
|
||||
return {
|
||||
id: props.id,
|
||||
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 = {
|
||||
drop (props, monitor) {
|
||||
const dragIndex = monitor.getItem().index;
|
||||
const toIndex = props.index;
|
||||
if (dragIndex !== toIndex) {
|
||||
props.moveStrategy(dragIndex, toIndex);
|
||||
}
|
||||
drop (props) {
|
||||
return {
|
||||
index: props.index,
|
||||
};
|
||||
},
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user