1
0
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:
sveisvei 2016-12-31 09:55:07 +01:00
parent 7243dce22d
commit bad6c95fa2
4 changed files with 23 additions and 8 deletions

View File

@ -32,6 +32,7 @@ const prepare = (methods, dispatch) => {
};
methods.addStrategy = (v) => {
v.id = Math.round(Math.random() * 10000000);
methods.pushToList('strategies', v);
};

View File

@ -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);
};

View File

@ -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)}

View File

@ -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,
};
},
};