Prevent duplicate property names

This commit is contained in:
jos 2016-08-26 13:25:34 +02:00
parent 9350debba2
commit 94671507b5
1 changed files with 7 additions and 1 deletions

View File

@ -46,7 +46,10 @@ export function changeProperty (data, path, oldProp, newProp) {
const object = getIn(data, dataPath)
const index = object.props.findIndex(p => p.name === oldProp)
return setIn(data, dataPath.concat(['props', index, 'name']), newProp)
// prevent duplicate property names
const uniqueNewProp = findUniqueName(newProp, object.props.map(p => p.name))
return setIn(data, dataPath.concat(['props', index, 'name']), uniqueNewProp)
}
/**
@ -173,6 +176,9 @@ export function duplicate (data, path, prop) {
const original = props[index]
const duplicate = cloneDeep(original)
// prevent duplicate property names
duplicate.name = findUniqueName(duplicate.name, props.map(p => p.name))
updated.splice(index + 1, 0, duplicate)
return updated