Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(md): update mobile mentions menu to always show 2 users if available (#3462)
Seamus155845f9d695
diff --git a/js/app/packages/block-md/component/configured-discussion-markdown-editor.ts b/js/app/packages/block-md/component/configured-discussion-markdown-editor.tsindex bee8d6ed10..19c8890ce8 100644--- a/js/app/packages/block-md/component/configured-discussion-markdown-editor.ts+++ b/js/app/packages/block-md/component/configured-discussion-markdown-editor.ts@@ -32,11 +32,12 @@ export function createConfiguredDiscussionMarkdownEditor(editor.namespace(options.namespace);if (options.enableMentions !== false) {+ // Intentionally no `block: 'channel'` — discussions live inside docs/tasks,+ // not channels, so `@here` doesn't belong here.editor.withMentions({onCreate: options.onMentionCreate,onRemove: options.onMentionRemove,users: options.users,- block: 'channel',});}diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsxindex 66e6d3a218..66e97c399c 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx@@ -210,14 +210,15 @@ function MentionsMenuInner(props: MentionsMenuProps) {const [mountSelection, setMountSelection] = createSignal<Selection | null>();const mobileAllItems = createLazyMemo((): MentionItem[] => {+ const users = usersAndGroups() ?? [];const combined: MentionItem[] = [- ...(usersAndGroups() ?? []),+ ...users,...(docs() ?? []),...(channels() ?? []),...(emails() ?? []),...(dates() ?? []),];- return sortMobileMentions(combined, searchTerm());+ return sortMobileMentions(combined, searchTerm(), users);});const bucketConfigs = createLazyMemo((): BucketConfig[] => {diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.test.ts b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.test.tsindex e3b67258e3..0c99d8240a 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.test.ts+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.test.ts@@ -228,4 +228,100 @@ describe('sortMobileMentions', () => {expect(result[0].id).toBe('d1');});++ describe('top user pinning', () => {+ test('pins the first 2 candidates above the rest of the sorted list', () => {+ const now = new Date();+ const alice = userItem('u1', 'Alice', now);+ const bob = userItem('u2', 'Bob', now);+ const carol = userItem('u3', 'Carol', now);+ const doc = docItem('d1', 'Doc', now);++ const result = sortMobileMentions([carol, doc, alice, bob], '', [+ alice,+ bob,+ carol,+ ]);++ expect(result.slice(0, 2).map((i) => i.id)).toEqual(['u1', 'u2']);+ });++ test('does not duplicate pinned candidates in the rest of the list', () => {+ const now = new Date();+ const alice = userItem('u1', 'Alice', now);+ const bob = userItem('u2', 'Bob', now);+ const doc = docItem('d1', 'Doc', now);++ const result = sortMobileMentions([alice, bob, doc], '', [alice, bob]);++ expect(result.map((i) => i.id)).toEqual(['u1', 'u2', 'd1']);+ });++ test('pins fewer than 2 when there are fewer than 2 candidates', () => {+ const now = new Date();+ const alice = userItem('u1', 'Alice', now);+ const doc = docItem('d1', 'Doc', now);++ const result = sortMobileMentions([alice, doc], '', [alice]);++ expect(result[0].id).toBe('u1');+ expect(result.length).toBe(2);+ });++ test('pins users even when the blended sort would rank docs above them', () => {+ const now = new Date();+ const staleUser = userItem(+ 'u1',+ 'Old User',+ new Date(now.getTime() - 14 * 24 * HOUR)+ );+ const freshDoc = docItem('d1', 'Just Viewed', now);++ const result = sortMobileMentions([staleUser, freshDoc], '', [staleUser]);++ expect(result[0].id).toBe('u1');+ });++ test('respects the candidate order when pinning', () => {+ const now = new Date();+ const a = userItem('u1', 'AAA', now);+ const b = userItem('u2', 'BBB', new Date(now.getTime() - HOUR));++ // Candidates pre-sorted as [b, a] should pin b first even though a is fresher.+ const result = sortMobileMentions([a, b], '', [b, a]);++ expect(result.slice(0, 2).map((i) => i.id)).toEqual(['u2', 'u1']);+ });++ test('pins @here at position 1 when present (channel block case)', () => {+ const now = new Date();+ const here = groupItem('here');+ const alice = userItem('u1', 'Alice', now);+ const bob = userItem('u2', 'Bob', new Date(now.getTime() - HOUR));+ const doc = docItem('d1', 'Doc', now);++ // useUsersMention returns groups before users, so candidates lead with `here`.+ const result = sortMobileMentions([alice, bob, doc], '', [+ here,+ alice,+ bob,+ ]);++ expect(result.slice(0, 2).map((i) => i.id)).toEqual(['here', 'u1']);+ });++ test('no pinning when topUserCandidates is empty (default arg)', () => {+ const now = new Date();+ const veryStaleUser = userItem(+ 'u1',+ 'Old User',+ new Date(now.getTime() - 14 * 24 * HOUR)+ );+ const freshDoc = docItem('d1', 'Just Viewed', now);++ const result = sortMobileMentions([veryStaleUser, freshDoc], '');++ expect(result[0].id).toBe('d1');+ });+ });});diff --git a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.tsindex be80d201bb..18bdc70434 100644--- a/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts+++ b/js/app/packages/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts@@ -48,10 +48,23 @@ function createMobileSearchConfig(};}+/**+ * How many entries from {@link topUserCandidates} get pinned above the rest+ * of the mobile mention hits. Mirrors desktop's user bucket without a visual+ * separator — user mentions are the common case, so we keep the freshest+ * couple within easy reach even when docs/channels would otherwise out-rank+ * them in the blended sort.+ */+const TOP_USERS = 2;+export function sortMobileMentions(items: MentionItem[],- query: string+ query: string,+ topUserCandidates: MentionItem[] = []): MentionItem[] {+ const pinned = topUserCandidates.slice(0, TOP_USERS);+ const pinnedIds = new Set(pinned.map((item) => item.id));+const hasQuery = query.trim().length > 0;const search = createFreshSearch<MentionItem>({config: createMobileSearchConfig(hasQuery),@@ -59,5 +72,9 @@ export function sortMobileMentions(isDmItem,getTimestamp: getMentionTimestamps,});- return search(items, query).map(({ item }) => item);+ const rest = search(items, query)+ .map(({ item }) => item)+ .filter((item) => !pinnedIds.has(item.id));++ return [...pinned, ...rest];}