1
0
Fork 0
mirror of synced 2024-08-13 09:01:40 +12:00

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

View file

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