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.

feat(calendar): find calendar events in the @ mention menu (#8667)

gbirman0534ae5a813e
diff --git a/apps/web/src/features/calendar-view/calendar-only-search-filters.ts b/apps/web/src/features/calendar-view/calendar-only-search-filters.ts
new file mode 100644
index 0000000000..656491afbf
--- /dev/null
+++ b/apps/web/src/features/calendar-view/calendar-only-search-filters.ts
@@ -0,0 +1,20 @@
+import type { EntityFilters } from '@service-search/generated/models';
+
+const NIL_UUID = '00000000-0000-0000-0000-000000000000';
+
+/**
+ * Restrict unified search to calendar events: every other searchable type has
+ * a NIL id in its primary field, which the search service reads as "exclude
+ * this type", while calendar events carry no id filter and so are the only
+ * matches. This mirrors what the Search view's Calendar type produces.
+ */
+export const CALENDAR_ONLY_SEARCH_FILTERS: EntityFilters = {
+ document_filters: { document_ids: [NIL_UUID] },
+ email_filters: { email_thread_ids: [NIL_UUID] },
+ channel_filters: { channel_ids: [NIL_UUID] },
+ channel_thread_filters: { thread_ids: [NIL_UUID] },
+ chat_filters: { chat_ids: [NIL_UUID] },
+ project_filters: { project_ids: [NIL_UUID] },
+ call_filters: { call_ids: [NIL_UUID] },
+ foreign_entity_filters: { ids: [NIL_UUID] },
+};
diff --git a/apps/web/src/features/calendar-view/components/CalendarSearch.tsx b/apps/web/src/features/calendar-view/components/CalendarSearch.tsx
index d9e2e62292..941727cd7a 100644
--- a/apps/web/src/features/calendar-view/components/CalendarSearch.tsx
+++ b/apps/web/src/features/calendar-view/components/CalendarSearch.tsx
@@ -38,7 +38,6 @@ import {
useCalendarSearchPreviewsQuery,
} from '@queries/calendar/mention-preview';
import { useSearchSoupQuery } from '@queries/soup/search';
-import type { EntityFilters } from '@service-search/generated/models';
import { Button, cn, EmptyStatePanel, Layer } from '@ui';
import {
createEffect,
@@ -50,6 +49,7 @@ import {
onMount,
Show,
} from 'solid-js';
+import { CALENDAR_ONLY_SEARCH_FILTERS } from '../calendar-only-search-filters';
import { createCalendarRange } from '../calendar-range';
import {
eventTimeFromOccurrenceKey,
@@ -65,25 +65,6 @@ type CalendarSearchResult = WithSearch<
>;
type EventTime = NonNullable<CalendarSearchResult['time']>;
-const NIL_UUID = '00000000-0000-0000-0000-000000000000';
-
-/**
- * Restrict unified search to calendar events: every other searchable type has
- * a NIL id in its primary field, which the search service reads as "exclude
- * this type", while calendar events carry no id filter and so are the only
- * matches. This mirrors what the Search view's Calendar type produces.
- */
-const CALENDAR_ONLY_FILTERS: EntityFilters = {
- document_filters: { document_ids: [NIL_UUID] },
- email_filters: { email_thread_ids: [NIL_UUID] },
- channel_filters: { channel_ids: [NIL_UUID] },
- channel_thread_filters: { thread_ids: [NIL_UUID] },
- chat_filters: { chat_ids: [NIL_UUID] },
- project_filters: { project_ids: [NIL_UUID] },
- call_filters: { call_ids: [NIL_UUID] },
- foreign_entity_filters: { ids: [NIL_UUID] },
-};
-
const searchEventKey = (eventId: string, occurrenceKey?: string) =>
JSON.stringify([eventId, occurrenceKey ?? null]);
@@ -390,7 +371,7 @@ function CalendarSearchControl(props: {
match_type: selected.matchType,
query: debouncedQuery(),
filters: {
- ...CALENDAR_ONLY_FILTERS,
+ ...CALENDAR_ONLY_SEARCH_FILTERS,
calendar_event_filters:
selected.statuses.length ||
selected.organizers.length ||
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
index d6622a92c9..81b215be9b 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.test.tsx
@@ -16,6 +16,8 @@ const mocks = vi.hoisted(() => ({
contacts: [] as import('@core/context/quickAccess').EntityItem[],
hasMoreContacts: false,
loadMoreContacts: vi.fn(async () => {}),
+ calendarEvents:
+ [] as import('../../../utils/mentionsUtils').CalendarEventMentionItem[],
}));
vi.mock('@app/features/crm/record-adapter', () => ({
@@ -96,6 +98,9 @@ vi.mock('./hooks/useBookingLinkMention', () => ({
isLoading: () => false,
}),
}));
+vi.mock('./hooks/useCalendarEventMention', () => ({
+ useCalendarEventMention: () => ({ events: () => mocks.calendarEvents }),
+}));
vi.mock('@core/component/EntityIcon', () => ({ EntityIcon: () => null }));
vi.mock('@core/component/UserIcon', () => ({ UserIcon: () => null }));
vi.mock('@ui', () => ({
@@ -113,6 +118,7 @@ afterEach(() => {
mocks.contacts = [];
mocks.hasMoreContacts = false;
mocks.loadMoreContacts.mockClear();
+ mocks.calendarEvents = [];
cleanup();
vi.useRealTimers();
vi.restoreAllMocks();
@@ -288,6 +294,38 @@ it('offers CRM companies and contacts', () => {
expect(mocks.requestedBuckets).toContain('crm_contact');
});
+it('offers calendar events and picks one', () => {
+ Element.prototype.scrollIntoView = vi.fn();
+ vi.mocked(useEmailSearchMention).mockReturnValue({
+ emails: () => [],
+ totalCount: () => 0,
+ hasMore: () => false,
+ isLoadingMore: () => false,
+ loadMore: async () => {},
+ } as unknown as ReturnType<typeof useEmailSearchMention>);
+ mocks.calendarEvents = [
+ {
+ kind: 'calendarEvent',
+ id: 'event-1',
+ data: { eventId: 'event-1', title: 'Planning', when: 'Mon, Oct 26' },
+ },
+ ];
+ const onPick = vi.fn();
+ const menu = createMenuOperations();
+ menu.openMenu();
+ render(() => (
+ <MentionsMenu
+ menu={menu}
+ users={() => []}
+ anchor={document.createElement('div')}
+ onPick={onPick}
+ />
+ ));
+ expect(screen.getByText('Calendar events')).toBeTruthy();
+ fireEvent.click(screen.getByText('Planning'));
+ expect(onPick).toHaveBeenCalledWith(mocks.calendarEvents[0]);
+});
+
it('opens cell pickers without replaying the menu entrance animation', () => {
const menu = createMenuOperations();
menu.openMenu();
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
index 9cd1ab7cfd..60533aac8b 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenu.tsx
@@ -53,6 +53,7 @@ import { ItemBin } from './components/ItemBin';
import { MentionsMenuItem } from './components/MentionsMenuItem';
import { createMentionPageLoader } from './hooks/createMentionPageLoader';
import { useBookingLinkMention } from './hooks/useBookingLinkMention';
+import { useCalendarEventMention } from './hooks/useCalendarEventMention';
import { useEmailSearchMention } from './hooks/useEmailSearchMention';
import {
useEntityMention,
@@ -271,6 +272,13 @@ function MentionsMenuInner(props: MentionsMenuProps) {
enabled: bookingLinksEnabled,
searchTerm,
});
+ const { events: calendarEvents } = useCalendarEventMention({
+ enabled: () =>
+ props.menu.isOpen() &&
+ !hasCustomEntities() &&
+ (!props.sources || props.sources.includes('calendarEvents')),
+ searchTerm,
+ });
const openTabs = createLazyMemo(() => {
const splitManager = globalSplitManager();
@@ -335,6 +343,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
...(sourceEnabled('agentSessions') ? agentSessions() : []),
...(sourceEnabled('companies') ? (companies() ?? []) : []),
...(sourceEnabled('emails') ? (emails() ?? []) : []),
+ ...(sourceEnabled('calendarEvents') ? calendarEvents() : []),
...(sourceEnabled('dates') ? (dates() ?? []) : []),
];
return sortMobileMentions(combined, searchTerm(), users);
@@ -361,6 +370,7 @@ function MentionsMenuInner(props: MentionsMenuProps) {
? (companyMention?.totalCount() ?? 0)
: 0) +
(sourceEnabled('emails') ? totalEmailCount() : 0) +
+ (sourceEnabled('calendarEvents') ? calendarEvents().length : 0) +
(sourceEnabled('dates') ? (dates()?.length ?? 0) : 0),
hasMore: () =>
(sourceEnabled('users') &&
@@ -460,6 +470,12 @@ function MentionsMenuInner(props: MentionsMenuProps) {
isLoadingMore: isLoadingMoreEmails,
loadMore: loadMoreEmails,
},
+ {
+ id: 'calendarEvents',
+ label: 'Calendar events',
+ getData: calendarEvents,
+ getFullCount: () => calendarEvents().length,
+ },
{
id: 'dates',
label: 'Dates',
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
index d1dfeaf166..cd17d1342e 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/MentionsMenuController.ts
@@ -13,7 +13,8 @@ export type MentionBucketId =
| 'emails'
| 'dates'
| 'openTabs'
- | 'bookingLinks';
+ | 'bookingLinks'
+ | 'calendarEvents';
export interface BucketConfig<T extends MentionItem = MentionItem> {
id: MentionBucketId;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
index 7468c4bd47..00c9436bf6 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/components/MentionsMenuItem.tsx
@@ -54,6 +54,10 @@ export function MentionsMenuItem(props: {
name: data.title,
detail: `${data.durationMinutes} min · ${data.owner}`,
}))
+ .with({ kind: 'calendarEvent' }, ({ data }) => ({
+ name: data.title,
+ detail: data.when,
+ }))
.otherwise(() => ({ name: name(), detail: undefined }));
const icon = () => {
@@ -79,6 +83,9 @@ export function MentionsMenuItem(props: {
case 'bookingLink':
return <CalendarBlankIcon class="size-4 text-accent" />;
+ case 'calendarEvent':
+ return <EntityIcon targetType="calendar" size="xs" />;
+
case 'entity':
if (props.item.bucket === 'email') {
return <EmailIcon class="size-4 text-ink-muted" />;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.test.ts
new file mode 100644
index 0000000000..0414699807
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.test.ts
@@ -0,0 +1,87 @@
+import type { CalendarEventEntity } from '@entity';
+import { useSearchSoupQuery } from '@queries/soup/search';
+import { createRoot } from 'solid-js';
+import { expect, it, vi } from 'vitest';
+
+vi.mock('@app/features/calendar/hooks/use-calendar-ui-flag', () => ({
+ useCalendarSearchUiFlag: () => () => true,
+}));
+vi.mock('@queries/soup/search', () => ({ useSearchSoupQuery: vi.fn() }));
+
+import {
+ calendarEventMentionItems,
+ useCalendarEventMention,
+} from './useCalendarEventMention';
+
+function event(
+ id: string,
+ overrides: Partial<CalendarEventEntity> = {}
+): CalendarEventEntity {
+ return {
+ type: 'calendar_event',
+ id,
+ name: 'Standup',
+ ownerId: 'macro|[email protected]',
+ status: 'confirmed',
+ isReadOnly: false,
+ time: {
+ kind: 'timed',
+ startsAt: '2026-10-26T13:00:00Z',
+ endsAt: '2026-10-26T13:30:00Z',
+ },
+ ...overrides,
+ } as CalendarEventEntity;
+}
+
+it('offers each event once, pinned to its occurrence only when it repeats', () => {
+ const items = calendarEventMentionItems([
+ event('series', {
+ isRecurring: true,
+ occurrenceKey: '2026-10-27T13:00:00Z',
+ }),
+ event('series', {
+ isRecurring: true,
+ occurrenceKey: '2026-10-28T13:00:00Z',
+ }),
+ event('single', { occurrenceKey: '2026-10-26T13:00:00Z' }),
+ event('untitled', { name: '' }),
+ ]);
+
+ expect(items.map((item) => item.id)).toEqual([
+ 'series',
+ 'single',
+ 'untitled',
+ ]);
+ expect(items[0].data.occurrenceKey).toBe('2026-10-27T13:00:00Z');
+ expect(items[1].data.occurrenceKey).toBeUndefined();
+ expect(items[2].data.title).toBe('Untitled event');
+ expect(items[0].data.when).toBeTruthy();
+});
+
+function mentionTitles(search: {
+ isPending: boolean;
+ status: string;
+ data: CalendarEventEntity[] | undefined;
+}) {
+ vi.mocked(useSearchSoupQuery).mockReturnValue(
+ search as unknown as ReturnType<typeof useSearchSoupQuery>
+ );
+ return createRoot((dispose) => {
+ const { events } = useCalendarEventMention({
+ enabled: () => true,
+ searchTerm: () => 'Standup',
+ });
+ const titles = events().map((item) => item.data.title);
+ dispose();
+ return titles;
+ });
+}
+
+it('keeps the found events when a later search fails, and waits for the first one', () => {
+ expect(
+ mentionTitles({ isPending: false, status: 'error', data: [event('a')] })
+ ).toEqual(['Standup']);
+ expect(
+ mentionTitles({ isPending: true, status: 'pending', data: undefined })
+ ).toEqual([]);
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.ts
new file mode 100644
index 0000000000..c129f978a8
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/hooks/useCalendarEventMention.ts
@@ -0,0 +1,112 @@
+import { useCalendarSearchUiFlag } from '@app/features/calendar/hooks/use-calendar-ui-flag';
+import { CALENDAR_ONLY_SEARCH_FILTERS } from '@app/features/calendar-view/calendar-only-search-filters';
+import type { CalendarEventEntity, EntityData, WithSearch } from '@entity';
+import { queryReadyGate } from '@queries/gate';
+import {
+ type SearchSoupQueryArgs,
+ useSearchSoupQuery,
+} from '@queries/soup/search';
+import { createLazyMemo } from '@solid-primitives/memo';
+import type { Accessor } from 'solid-js';
+import type { CalendarEventMentionItem } from '../../../../utils/mentionsUtils';
+
+/** The calendar's own search waits for this many characters, and so does the menu. */
+const MIN_QUERY_LENGTH = 3;
+
+type UseCalendarEventMentionOptions = {
+ searchTerm: Accessor<string>;
+ enabled: Accessor<boolean>;
+};
+
+/** When the row's instance starts: its occurrence when search resolved one. */
+function calendarEventMentionWhen(
+ event: Pick<CalendarEventEntity, 'time' | 'occurrenceKey'>
+): string | undefined {
+ const time = event.time;
+ if (!time) return;
+ if (time.kind === 'allDay') {
+ const date = new Date(
+ `${(event.occurrenceKey ?? time.startDate).slice(0, 10)}T00:00:00Z`
+ );
+ if (Number.isNaN(date.getTime())) return;
+ return new Intl.DateTimeFormat(undefined, {
+ weekday: 'short',
+ month: 'short',
+ day: 'numeric',
+ timeZone: 'UTC',
+ }).format(date);
+ }
+ const start = new Date(event.occurrenceKey ?? time.startsAt);
+ if (Number.isNaN(start.getTime())) return;
+ return new Intl.DateTimeFormat(undefined, {
+ weekday: 'short',
+ month: 'short',
+ day: 'numeric',
+ hour: 'numeric',
+ minute: '2-digit',
+ }).format(start);
+}
+
+/** One row per event, pinned to its occurrence when it repeats, as Copy event does. */
+export function calendarEventMentionItems(
+ results: readonly CalendarEventEntity[]
+): CalendarEventMentionItem[] {
+ const seen = new Set<string>();
+ const items: CalendarEventMentionItem[] = [];
+ for (const event of results) {
+ if (seen.has(event.id)) continue;
+ seen.add(event.id);
+ items.push({
+ kind: 'calendarEvent',
+ id: event.id,
+ data: {
+ eventId: event.id,
+ title: event.name || 'Untitled event',
+ occurrenceKey: event.isRecurring ? event.occurrenceKey : undefined,
+ when: calendarEventMentionWhen(event),
+ },
+ });
+ }
+ return items;
+}
+
+/**
+ * Calendar events for the mention menu, through the same unified search the
+ * calendar's own search uses, and only where that search is offered.
+ */
+export function useCalendarEventMention(
+ options: UseCalendarEventMentionOptions
+) {
+ const calendarSearch = useCalendarSearchUiFlag();
+ const term = () => options.searchTerm().trim();
+ const enabled = () =>
+ options.enabled() && calendarSearch() && term().length >= MIN_QUERY_LENGTH;
+
+ const args = createLazyMemo(
+ (): SearchSoupQueryArgs => ({
+ params: { cursor: null, page_size: 10 },
+ body: {
+ match_type: 'partial',
+ search_on: 'name',
+ query: term(),
+ filters: CALENDAR_ONLY_SEARCH_FILTERS,
+ },
+ })
+ );
+ const search = useSearchSoupQuery(args, () => ({ enabled: enabled() }));
+
+ const events = createLazyMemo((): CalendarEventMentionItem[] => {
+ if (!enabled() || !queryReadyGate(search)) return [];
+ return calendarEventMentionItems(
+ search.data.filter(
+ (
+ entity
+ ): entity is WithSearch<
+ Extract<EntityData, { type: 'calendar_event' }>
+ > => entity.type === 'calendar_event'
+ )
+ );
+ });
+
+ return { events };
+}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/calendar-event-selection.test.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/calendar-event-selection.test.ts
new file mode 100644
index 0000000000..5c31bccf7a
--- /dev/null
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/calendar-event-selection.test.ts
@@ -0,0 +1,51 @@
+import type { LexicalEditor } from 'lexical';
+import { expect, it, vi } from 'vitest';
+
+const { trackMention } = vi.hoisted(() => ({ trackMention: vi.fn() }));
+vi.mock('@core/signal/mention', () => ({ trackMention }));
+// The block table loads every block module; events here never need it.
+vi.mock('@core/constant/allBlocks', () => ({ fileTypeToBlockName: vi.fn() }));
+vi.mock('../../../../plugins', () => ({
+ REMOVE_INLINE_SEARCH_COMMAND: 'remove-search',
+}));
+vi.mock('../../../../plugins/mentions', () => ({
+ INSERT_AGENT_SESSION_MENTION_COMMAND: 'insert-session',
+ INSERT_DOCUMENT_MENTION_COMMAND: 'insert-document',
+ INSERT_DATE_MENTION_COMMAND: 'insert-date',
+ INSERT_GROUP_MENTION_COMMAND: 'insert-group',
+}));
+vi.mock('../../../../utils/mentionsUtils', () => ({
+ handleUserMention: vi.fn(),
+}));
+
+import { createItemHandler } from './mentionHandlers';
+
+it('inserts a picked event as the calendar mention Copy event pastes', async () => {
+ const dispatchCommand = vi.fn();
+ const onDocumentMention = vi.fn();
+ const handler = createItemHandler({
+ editor: { dispatchCommand } as unknown as LexicalEditor,
+ blockId: 'channel-1',
+ blockName: 'channel',
+ onDocumentMention,
+ });
+
+ await handler({
+ kind: 'calendarEvent',
+ id: 'event-1',
+ data: {
+ eventId: 'event-1',
+ title: 'Planning',
+ occurrenceKey: '2026-10-26T13:00:00+00:00',
+ },
+ });
+
+ expect(dispatchCommand).toHaveBeenNthCalledWith(2, 'insert-document', {
+ documentId: 'event-1',
+ documentName: 'Planning',
+ blockName: 'calendar',
+ blockParams: { occurrenceKey: '2026-10-26T13:00:00+00:00' },
+ });
+ expect(trackMention).not.toHaveBeenCalled();
+ expect(onDocumentMention).not.toHaveBeenCalled();
+});
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
index ad5a1fb476..7fa09ecf75 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/entityUtils.ts
@@ -57,6 +57,7 @@ export function getMentionItemName(item: MentionItem): string {
.filter(Boolean)
.join(' ');
case 'bookingLink':
+ case 'calendarEvent':
return item.data.title;
case 'entity':
return item.data.name ?? (item.bucket === 'email' ? 'No Subject' : '');
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
index d119d9ca56..c2a200a04d 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mentionHandlers.ts
@@ -13,6 +13,7 @@ import {
} from '../../../../plugins/mentions';
import type {
BookingLinkMentionItem,
+ CalendarEventMentionItem,
HandlerDependencies,
MentionItem,
} from '../../../../utils/mentionsUtils';
@@ -196,6 +197,24 @@ async function handleBookingLinkMention(
});
}
+/**
+ * Insert a calendar event chip, the same node Copy event pastes: a series
+ * mention for a single event, an instance mention for a repeating one.
+ * Posting it in a channel shares the event with the channel's members.
+ */
+async function handleCalendarEventMention(
+ item: CalendarEventMentionItem,
+ dependencies: HandlerDependencies
+): Promise<void> {
+ const { eventId, title, occurrenceKey } = item.data;
+ dependencies.editor.dispatchCommand(INSERT_DOCUMENT_MENTION_COMMAND, {
+ documentId: eventId,
+ documentName: title,
+ blockName: 'calendar',
+ blockParams: occurrenceKey ? { occurrenceKey } : undefined,
+ });
+}
+
/**
* Creates a handler for MentionItem selection.
*/
@@ -220,6 +239,8 @@ export function createItemHandler(dependencies: HandlerDependencies) {
);
case 'bookingLink':
return await handleBookingLinkMention(item, dependencies);
+ case 'calendarEvent':
+ return await handleCalendarEventMention(item, dependencies);
case 'entity':
return await handleEntityMention(item, dependencies);
}
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
index 1fd8cdc31c..0efc47a606 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/component/menu/MentionsMenu/utils/mobileSort.ts
@@ -4,7 +4,8 @@ import type { MentionItem } from '../../../../utils/mentionsUtils';
function getMentionName(item: MentionItem): string {
if (item.kind === 'date') return item.data.displayText;
if (item.kind === 'group') return item.data.groupAlias;
- if (item.kind === 'bookingLink') return item.data.title;
+ if (item.kind === 'bookingLink' || item.kind === 'calendarEvent')
+ return item.data.title;
return item.searchText;
}
@@ -12,7 +13,8 @@ function getMentionTimestamps(item: MentionItem) {
if (
item.kind === 'date' ||
item.kind === 'group' ||
- item.kind === 'bookingLink'
+ item.kind === 'bookingLink' ||
+ item.kind === 'calendarEvent'
)
return {};
return item.timestamps;
diff --git a/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts b/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
index 0af3f210bc..7363b6bcea 100644
--- a/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
+++ b/apps/web/src/lib/core/component/LexicalMarkdown/utils/mentionsUtils.ts
@@ -395,8 +395,22 @@ export type BookingLinkMentionItem = {
};
};
+/** A calendar event found by unified search, mentioned the way Copy event copies it. */
+export type CalendarEventMentionItem = {
+ kind: 'calendarEvent';
+ id: string;
+ data: {
+ eventId: string;
+ title: string;
+ /** Pins one instance of a recurring series; absent for a single event. */
+ occurrenceKey?: string;
+ /** When the mentioned instance starts, for the menu row. */
+ when?: string;
+ };
+};
+
/**
- * MentionItem = QuickAccessItem + Date + Group + BookingLink.
+ * MentionItem = QuickAccessItem + Date + Group + BookingLink + CalendarEvent.
* Used in MentionsMenu to unify all mentionable item types.
*/
export type AgentSessionMentionItem = Omit<
@@ -409,7 +423,8 @@ export type MentionItem =
| DateMentionItem
| GroupMentionItem
| AgentSessionMentionItem
- | BookingLinkMentionItem;
+ | BookingLinkMentionItem
+ | CalendarEventMentionItem;
/**
* Type guard for DateMentionItem.
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 15ce8b5c9d..ea6f1b2a84 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -641,6 +641,12 @@ in the background without returning to its skeleton. OOO changes, sharing change
and notifications without that guarantee still clear cached rows and close open
OOO details immediately before refetching.
+To mention an event, press `Copy event` in its details and paste, or type `@` and at least
+three characters of its title in a composer that offers event mentions (message, comment and
+document composers; spreadsheet and database cells and typed reference fields do not): where calendar search is on
+(`enable-calendar-search-ui`), the menu lists matches under `Calendar events` (all of them in
+one list on phones), one row per event with when it starts, and picking one inserts the same
+chip a paste does, pinned to the found instance of a repeating event.
A calendar event mentioned in a channel message opens the calendar focused on the viewer's
own copy of the meeting. When a person holds the event on their own calendar and posts the
mention, it is shared read-only with the channel's current members: a member without a copy of