Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

fix(recipient-selector): tune fresh-search, fix slow search on lots of contacts (#4429)

Seamus476d20a2853f
diff --git a/js/app/packages/core/component/RecipientSelector.tsx b/js/app/packages/core/component/RecipientSelector.tsx
index c39a646ac4..bc213d4845 100644
--- a/js/app/packages/core/component/RecipientSelector.tsx
+++ b/js/app/packages/core/component/RecipientSelector.tsx
@@ -42,6 +42,7 @@ import {
onMount,
Show,
Switch,
+ untrack,
} from 'solid-js';
import { type VirtualizerHandle, VList } from 'virtua/solid';
@@ -398,18 +399,47 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
return email ? email.split('@')[1] : undefined;
});
- // Create search function for recipients - only used for initial sorting with no query
- const recipientSearch = createFreshSearch<CombinedRecipientItem>({
- config: FreshSearchPresets.baseUserSearch<CombinedRecipientItem>(
+ const baseRecipientSearchConfig =
+ FreshSearchPresets.baseUserSearch<CombinedRecipientItem>(
currentUserDomain,
getRecipientOptionEmail
- ),
+ );
+
+ // Create search function for recipients - only used for initial sorting with no query
+ const recipientSearch = createFreshSearch<CombinedRecipientItem>({
+ config: {
+ ...baseRecipientSearchConfig,
+ brevityWeight: 1,
+ timeWeight: 1.5,
+ boostFn: (item) => {
+ const sameDomainBoost = baseRecipientSearchConfig.boostFn?.(item) ?? 0;
+ const isSearching = untrack(() => inputValue().trim().length > 0);
+ if (!isSearching) return sameDomainBoost;
+
+ const personBoost =
+ item.kind === 'user' || item.kind === 'contact' ? 0.25 : 0;
+ return sameDomainBoost * 0.125 + personBoost;
+ },
+ useViewedAt: true,
+ },
getName: getRecipientOptionTextValue,
isChannelItem: (item) => item.kind === 'channel',
- getTimestamp: (item) => ({
- lastInteraction:
- item.kind === 'user' ? item.data.lastInteraction : undefined,
- }),
+ getTimestamp: (item) => {
+ if (item.kind === 'user') {
+ return { lastInteraction: item.data.lastInteraction };
+ }
+ if (item.kind === 'channel') {
+ const channel = item.data as typeof item.data & {
+ interacted_at?: string | null;
+ viewed_at?: string | null;
+ };
+ return {
+ viewedAt: channel.viewed_at,
+ updatedAt: channel.interacted_at ?? channel.updated_at,
+ };
+ }
+ return {};
+ },
});
const selectedEmails = createMemo(() => {
@@ -466,14 +496,19 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
});
const options = createMemo(() => {
- const { emails, sorted } = recipients();
+ const { raw, emails, sorted } = recipients();
const currentUserInput = inputValue();
// Check if currentUserInput matches any existing email
const hasExactEmailMatch =
currentUserInput && emails.has(currentUserInput.toLowerCase());
- const allOptions = [...sorted, ...customUsers()];
+ const searchTerm = currentUserInput.trim();
+ const searched = searchTerm
+ ? recipientSearch(raw, searchTerm).map((item) => item.item)
+ : sorted;
+
+ const allOptions = [...searched, ...customUsers()];
// Only add custom input if it doesn't match an existing email
if (
@@ -529,6 +564,7 @@ export function RecipientSelector<K extends CombinedRecipientKind>(
optionValue={getRecipientOptionValue}
optionTextValue={getRecipientOptionTextValue}
optionDisabled={getOptionDisabled}
+ defaultFilter={() => true}
value={props.selectedOptions as CombinedRecipientItem[]}
onChange={debouncedHandleChange}
onInputChange={onInputChange}