diff --git a/plugins/contact-resources/src/components/AccountArrayEditor.svelte b/plugins/contact-resources/src/components/AccountArrayEditor.svelte index 802c682e9e..3e609ff0fe 100644 --- a/plugins/contact-resources/src/components/AccountArrayEditor.svelte +++ b/plugins/contact-resources/src/components/AccountArrayEditor.svelte @@ -24,7 +24,7 @@ import UserBoxList from './UserBoxList.svelte' export let label: IntlString - export let value: AccountUuid[] | undefined + export let value: AccountUuid | AccountUuid[] | undefined export let onChange: ((refs: AccountUuid[]) => void | Promise) | undefined export let readonly = false export let kind: ButtonKind = 'link' @@ -34,13 +34,16 @@ export let excludeItems: Ref[] = [] export let emptyLabel: IntlString | undefined = undefined export let allowGuests: boolean = false + export let attributeKey: string | undefined = undefined + + $: accounts = typeof value === 'string' ? [value] : value ?? [] let timer: any = null const client = getClient() let update: (() => Promise) | undefined - $: valueByPersonRef = new Map( - (value ?? []).map((p) => { + $: accountsByPersonRef = new Map( + accounts.map((p) => { const person = $employeeRefByAccountUuidStore.get(p) if (person === undefined) { @@ -60,7 +63,7 @@ const newAccounts: AccountUuid[] = [] for (const person of newPersons) { - const acc = valueByPersonRef.get(person) + const acc = accountsByPersonRef.get(person) if (acc !== undefined) { newAccounts.push(acc) } else { @@ -86,7 +89,7 @@ void update?.() }) - $: employees = (value ?? []).map((p) => $employeeRefByAccountUuidStore.get(p)).filter(notEmpty) + $: employees = accounts.map((p) => $employeeRefByAccountUuidStore.get(p)).filter(notEmpty) $: docQuery = excludeItems.length === 0 && includeItems.length === 0 ? {}