1
0
Fork 0
mirror of synced 2024-07-28 17:46:09 +12:00

Fix reduces

This commit is contained in:
Adria Navarro 2023-09-25 18:21:02 +02:00
parent 28fc050299
commit e3c3edb8bd

View file

@ -54,30 +54,24 @@
// Persist the initial values as options, allowing them to be present in the dropdown, // Persist the initial values as options, allowing them to be present in the dropdown,
// even if they are not in the inital fetch results // even if they are not in the inital fetch results
initialValuesProcessed = true initialValuesProcessed = true
optionsObj = { optionsObj = fieldState?.value?.reduce((accumulator, value) => {
...optionsObj, accumulator[value._id] = {
...fieldState?.value?.reduce((accumulator, value) => { _id: value._id,
accumulator[value._id] = { [primaryDisplay]: value.primaryDisplay,
_id: value._id, }
[primaryDisplay]: value.primaryDisplay, return accumulator
} }, optionsObj)
return accumulator
}, {}),
}
} }
} }
$: enrichedOptions = enrichOptions(optionsObj, $fetch.rows) $: enrichedOptions = enrichOptions(optionsObj, $fetch.rows)
const enrichOptions = (optionsObj, fetchResults) => { const enrichOptions = (optionsObj, fetchResults) => {
const result = { const result = (fetchResults || [])?.reduce((accumulator, row) => {
...optionsObj, if (!accumulator[row._id]) {
...(fetchResults || [])?.reduce((accumulator, row) => { accumulator[row._id] = row
if (!optionsObj[row._id]) { }
accumulator[row._id] = row return accumulator
} }, optionsObj)
return accumulator
}, {}),
}
return Object.values(result) return Object.values(result)
} }