Improve readability

This commit is contained in:
Adria Navarro 2023-09-25 10:16:01 +02:00
parent 3fc396db8a
commit 825f1c639e
2 changed files with 31 additions and 23 deletions

View File

@ -86,15 +86,16 @@
$: userPage = $userPageInfo.page
$: logsPage = $logsPageInfo.page
$: userList = {
...(userList || {}),
...$users.data?.reduce((p, c) => {
p[c._id] = c
return p
let usersObj = {}
$: usersObj = {
...usersObj,
...$users.data?.reduce((accumulator, user) => {
accumulator[user._id] = user
return accumulator
}, {}),
}
$: sortedUsers = sort(
enrich(Object.values(userList), selectedUsers, "_id"),
enrich(Object.values(usersObj), selectedUsers, "_id"),
"email"
)
$: sortedEvents = sort(

View File

@ -45,30 +45,37 @@
$: expandedDefaultValue = expand(defaultValue)
$: primaryDisplay = tableDefinition?.primaryDisplay
$: initialValues =
initialValues ||
(primaryDisplay &&
fieldState?.value?.map(x => ({
_id: x._id,
[primaryDisplay]: x.primaryDisplay,
})))
$: allOptions = {
...(allOptions || {}),
...[...($fetch.rows || []), ...(initialValues || [])]?.reduce((p, c) => {
p[c._id] = c
return p
let optionsObj = {}
let initialValuesProcessed
$: {
if (!initialValuesProcessed && primaryDisplay) {
initialValuesProcessed = true
optionsObj = {
...optionsObj,
...fieldState?.value?.reduce((accumulator, value) => {
accumulator[value._id] = {
_id: value._id,
[primaryDisplay]: value.primaryDisplay,
}
return accumulator
}, {}),
}
}
}
$: optionsObj = {
...optionsObj,
...($fetch.rows || [])?.reduce((accumulator, row) => {
accumulator[row._id] = row
return accumulator
}, {}),
}
$: options = Object.values(allOptions)
$: fetchRows(searchTerm, primaryDisplay)
const fetchRows = (searchTerm, primaryDisplay) => {
const allRowsFetched =
$fetch.loaded &&
!Object.keys($fetch.query.string).length &&
!Object.keys($fetch.query?.string || {}).length &&
!$fetch.hasNextPage
if (!allRowsFetched) {
// Don't request until we have the primary display
@ -140,7 +147,7 @@
{#if fieldState}
<svelte:component
this={component}
{options}
options={Object.values(optionsObj)}
{autocomplete}
value={selectedValue}
on:change={multiselect ? multiHandler : singleHandler}