Return hydrated template values with correct selected and picked fields

pull/10616/head
ebb-tide 2018-06-28 16:26:23 -07:00
parent 27a7a6c642
commit 51b0e19424
1 changed files with 15 additions and 20 deletions

View File

@ -196,30 +196,25 @@ const ui = (state = initialState, action) => {
if (template.id !== templateID) { if (template.id !== templateID) {
return template return template
} }
// || template.type === 'csv'
// get this to run for csvs?
const pickedValue = _.get(template, 'values', []).find(v => v.picked) const pickedValue = _.get(template, 'values', []).find(v => v.picked)
let val const selectedValue = _.get(template, 'values', []).find(
if (pickedValue) { v => v.selected
val = values.map(value => ({ )
picked: _.get(pickedValue, 'value') === value,
value,
type: TEMPLATE_VARIABLE_TYPES[template.type],
}))
} else {
const selectedValue = _.get(template, 'values', []).find(
v => v.selected
)
val = values.map(value => ({
picked: _.get(selectedValue, 'value') === value,
value,
type: TEMPLATE_VARIABLE_TYPES[template.type],
}))
}
const newValues = values.map(value => {
const isPicked = _.get(pickedValue, 'value', null) === value
const isSelected = _.get(selectedValue, 'value', null) === value
const newValue = {
picked: pickedValue ? isPicked : isSelected,
selected: isSelected,
value,
type: TEMPLATE_VARIABLE_TYPES[template.type],
}
return newValue
})
return { return {
...template, ...template,
values: val, values: newValues,
} }
}) })