diff --git a/packages/builder/src/pages/builder/portal/account/auditLogs/index.svelte b/packages/builder/src/pages/builder/portal/account/auditLogs/index.svelte index e5865a456a..a6dba59196 100644 --- a/packages/builder/src/pages/builder/portal/account/auditLogs/index.svelte +++ b/packages/builder/src/pages/builder/portal/account/auditLogs/index.svelte @@ -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( diff --git a/packages/client/src/components/app/forms/RelationshipField.svelte b/packages/client/src/components/app/forms/RelationshipField.svelte index 9766eb45e4..3444a2ff8b 100644 --- a/packages/client/src/components/app/forms/RelationshipField.svelte +++ b/packages/client/src/components/app/forms/RelationshipField.svelte @@ -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}