diff --git a/packages/presentation/src/components/ObjectSearchPopup.svelte b/packages/presentation/src/components/ObjectSearchPopup.svelte index 07ba01e621..5469be78c5 100644 --- a/packages/presentation/src/components/ObjectSearchPopup.svelte +++ b/packages/presentation/src/components/ObjectSearchPopup.svelte @@ -128,17 +128,17 @@ } } categoryStatus = newCategoryStatus - } - $: updateItems(category, query, relatedDocuments) - $: if (items.length === 0) { - for (const c of categories) { - if ((categoryStatus[c._id] ?? 0) > 0) { - category = c - break + if (items.length === 0) { + for (const c of categories) { + if (category !== c && (categoryStatus[c._id] ?? 0) > 0) { + category = c + break + } } } } + $: updateItems(category, query, relatedDocuments) const manager = createFocusManager() diff --git a/plugins/contact-resources/src/index.ts b/plugins/contact-resources/src/index.ts index 552df46cd5..eac88bc32c 100644 --- a/plugins/contact-resources/src/index.ts +++ b/plugins/contact-resources/src/index.ts @@ -108,8 +108,38 @@ async function queryContact ( search: string, filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] } ): Promise { - let q: DocumentQuery = { name: { $like: `%${search}%` } } - if (_class === contact.class.Employee) q = { ...q, active: true } + const q: DocumentQuery = { name: { $like: `%${search}%` } } + return await doContactQuery(_class, q, filter, client) +} + +async function queryEmployee ( + client: Client, + search: string, + filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] } +): Promise { + const q1 = await doContactQuery(contact.class.Employee, { name: { $like: `%${search}%` } }, filter, client) + const q2 = await doContactQuery( + contact.class.Employee, + { displayName: { $like: `%${search}%` } }, + { + in: filter?.in, + nin: [...(filter?.nin ?? []), ...Array.from(q1.map((it) => ({ _id: it.doc._id, _class: it.doc._class })))] + }, + client + ) + + return q1.concat(q2) +} + +async function doContactQuery ( + _class: Ref>, + q: DocumentQuery, + filter: { in?: RelatedDocument[] | undefined, nin?: RelatedDocument[] | undefined } | undefined, + client: Client +): Promise { + if (_class === contact.class.Employee) { + q = { ...q, active: true } + } if (filter?.in !== undefined || filter?.nin !== undefined) { q._id = {} if (filter.in !== undefined) { @@ -199,7 +229,7 @@ export default async (): Promise => ({ client: Client, query: string, filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] } - ) => await queryContact(contact.class.Employee, client, query, filter), + ) => await queryEmployee(client, query, filter), PersonQuery: async (client: Client, query: string, filter?: { in?: RelatedDocument[], nin?: RelatedDocument[] }) => await queryContact(contact.class.Person, client, query, filter), OrganizationQuery: async (