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(email): keep the calendar file dialog's card and close it on navigation (#8687)

gbirman4a5da37a4e3b
diff --git a/apps/web/src/features/email-message/components/calendar-file-preview.tsx b/apps/web/src/features/email-message/components/calendar-file-preview.tsx
index 4b29b4d509..32260cdb9f 100644
--- a/apps/web/src/features/email-message/components/calendar-file-preview.tsx
+++ b/apps/web/src/features/email-message/components/calendar-file-preview.tsx
@@ -12,6 +12,8 @@ export function CalendarFilePreview(props: {
fileName: string;
open: boolean;
onClose: () => void;
+ /** Whether closing returns focus to the attachment; false when leaving it. */
+ restoreFocus?: () => boolean;
onDownload?: () => void;
children: JSX.Element;
}) {
@@ -21,6 +23,9 @@ export function CalendarFilePreview(props: {
onOpenChange={(open) => {
if (!open) props.onClose();
}}
+ onCloseAutoFocus={(event) => {
+ if (props.restoreFocus?.() === false) event.preventDefault();
+ }}
position="center"
class="w-140 max-w-full"
>
diff --git a/apps/web/src/features/email-message/views/email-message.test.tsx b/apps/web/src/features/email-message/views/email-message.test.tsx
index ae272c2d50..9ee3162187 100644
--- a/apps/web/src/features/email-message/views/email-message.test.tsx
+++ b/apps/web/src/features/email-message/views/email-message.test.tsx
@@ -131,3 +131,78 @@ it('hands a calendar file without a readable event to the host', () => {
expect(screen.queryByRole('dialog')).toBeNull();
expect(onOpenAttachment).toHaveBeenCalledWith(calendarFile);
});
+
+it('keeps the opened calendar file card mounted when the thread refreshes the message', () => {
+ const [current, setCurrent] = createSignal(message([invitationFixture]));
+ render(() => (
+ <EmailMessageView
+ message={current()}
+ renderInvitation={(_message, invitation, options) => (
+ <div data-testid={options ? 'dialog-card' : 'card'}>
+ {invitation.id}
+ </div>
+ )}
+ onOpenAttachment={vi.fn()}
+ isTouch={false}
+ isPersonal={false}
+ isSelected={false}
+ allowHover={false}
+ isExpanded
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ const card = screen.getByTestId('dialog-card');
+ setCurrent(message([structuredClone(invitationFixture)]));
+ expect(screen.getByTestId('dialog-card')).toBe(card);
+});
+
+it('closes the calendar file dialog when its card opens the calendar', () => {
+ let navigate: (() => void) | undefined;
+ render(() => (
+ <EmailMessageView
+ message={message([invitationFixture])}
+ renderInvitation={(_message, invitation, options) => {
+ if (options) navigate = options.onNavigate;
+ return <div>{invitation.id}</div>;
+ }}
+ onOpenAttachment={vi.fn()}
+ isTouch={false}
+ isPersonal={false}
+ isSelected={false}
+ allowHover={false}
+ isExpanded
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ expect(screen.getByRole('dialog')).toBeTruthy();
+ navigate?.();
+ expect(screen.queryByRole('dialog')).toBeNull();
+});
+
+it('opens a cloud-reference calendar file through the host', () => {
+ const reference = {
+ ...calendarFile,
+ reference_url: 'https://outlook.office.com/mail/item',
+ };
+ const onOpenAttachment = vi.fn();
+ render(() => (
+ <EmailMessageView
+ message={
+ {
+ ...message([invitationFixture]),
+ attachments: [reference],
+ } as unknown as EmailMessage
+ }
+ renderInvitation={(_message, invitation) => <div>{invitation.id}</div>}
+ onOpenAttachment={onOpenAttachment}
+ isTouch={false}
+ isPersonal={false}
+ isSelected={false}
+ allowHover={false}
+ isExpanded
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ expect(screen.queryByRole('dialog')).toBeNull();
+ expect(onOpenAttachment).toHaveBeenCalledWith(reference);
+});
diff --git a/apps/web/src/features/email-message/views/email-message.tsx b/apps/web/src/features/email-message/views/email-message.tsx
index 4cd9155b7a..c9b528c9b5 100644
--- a/apps/web/src/features/email-message/views/email-message.tsx
+++ b/apps/web/src/features/email-message/views/email-message.tsx
@@ -19,11 +19,17 @@ import {
} from '../core/calendar-invitation';
import { type EmailAttachment, isCalendarFile } from '../core/email-message';
import { inlineContentIds, normalizeContentId } from '../core/inline-images';
+export interface InvitationRenderOptions {
+ /** Called before a card action opens something else in the app. */
+ onNavigate?: () => void;
+}
+
export interface EmailMessageViewProps {
message: EmailMessage;
renderInvitation?: (
message: EmailMessage,
- invitation: CalendarInvitation
+ invitation: CalendarInvitation,
+ options?: InvitationRenderOptions
) => JSX.Element;
renderOperation?: (message: EmailMessage) => JSX.Element;
renderAvatar?: (message: EmailMessage) => JSX.Element;
@@ -58,21 +64,34 @@ export function EmailMessageView(props: EmailMessageViewProps) {
groupCalendarInvitations(props.message.calendar_invitations ?? [])
);
// A calendar file whose event the message already shows opens as that
- // event; any other file goes to the host.
+ // event; any other file, and a cloud reference with no bytes to download,
+ // goes to the host.
const [calendarFile, setCalendarFile] = createSignal<EmailAttachment>();
+ let navigatingAway = false;
const openAttachment = (attachment: EmailAttachment) => {
if (
invitationGroups().length > 0 &&
+ !attachment.reference_url &&
isCalendarFile(attachment.filename, attachment.mime_type)
) {
+ navigatingAway = false;
setCalendarFile(attachment);
return;
}
props.onOpenAttachment?.(attachment);
};
- const renderInvitation = (invitation: CalendarInvitation) =>
+ // A card action that opens the calendar closes the dialog first, so it
+ // neither covers the destination nor pulls focus back to the email.
+ const closeForNavigation = () => {
+ navigatingAway = true;
+ setCalendarFile(undefined);
+ };
+ const renderInvitation = (
+ invitation: CalendarInvitation,
+ options?: InvitationRenderOptions
+ ) =>
props.renderInvitation ? (
- props.renderInvitation(props.message, invitation)
+ props.renderInvitation(props.message, invitation, options)
) : (
<CalendarInviteCard invitation={invitation} />
);
@@ -288,15 +307,20 @@ export function EmailMessageView(props: EmailMessageViewProps) {
fileName={file().filename ?? ''}
open
onClose={() => setCalendarFile(undefined)}
+ restoreFocus={() => !navigatingAway}
onDownload={
props.onDownloadAttachment
? () => props.onDownloadAttachment?.(file())
: undefined
}
>
- <For each={invitationGroups()}>
- {(group) => renderInvitation(group.primary)}
- </For>
+ <Key each={invitationGroups()} by={(group) => group.primary.id}>
+ {(group) =>
+ renderInvitation(group().primary, {
+ onNavigate: closeForNavigation,
+ })
+ }
+ </Key>
</CalendarFilePreview>
)}
</Show>
diff --git a/apps/web/src/features/email-thread/calendar-invitation.test.tsx b/apps/web/src/features/email-thread/calendar-invitation.test.tsx
index cdc985626d..19817b7735 100644
--- a/apps/web/src/features/email-thread/calendar-invitation.test.tsx
+++ b/apps/web/src/features/email-thread/calendar-invitation.test.tsx
@@ -197,3 +197,24 @@ it('shows the saved invitation without calendar state when the calendar UI is of
expect(screen.getByText(/Saved invitation/)).toBeTruthy();
expect(screen.queryByRole('group', { name: 'Your response' })).toBeNull();
});
+
+it('leaves before opening the calendar so a dialog around the card can close first', () => {
+ queryState.failed = () => false;
+ queryState.data = { [`message:${invitationFixture.id}`]: wire };
+ const order: string[] = [];
+ render(() => (
+ <EmailCalendarInvitation
+ threadId="thread"
+ messageId="message"
+ invitation={invitationFixture}
+ hour12
+ openCalendar={(target) => order.push(`open ${target.eventId}`)}
+ onNavigate={() => order.push('leave')}
+ />
+ ));
+ // The mocked Button forwards `label` as an attribute, not an accessible name.
+ const open = document.querySelector('button[label="Open in calendar"]');
+ if (!open) throw new Error('Open in calendar is missing');
+ fireEvent.click(open);
+ expect(order).toEqual(['leave', 'open event']);
+});
diff --git a/apps/web/src/features/email-thread/calendar-invitation.tsx b/apps/web/src/features/email-thread/calendar-invitation.tsx
index 5fd901e980..506749ac92 100644
--- a/apps/web/src/features/email-thread/calendar-invitation.tsx
+++ b/apps/web/src/features/email-thread/calendar-invitation.tsx
@@ -31,6 +31,8 @@ export function EmailCalendarInvitation(props: {
invitation: CalendarInvitation;
hour12: boolean;
openCalendar?: (target: CalendarInvitationOpenTarget) => void;
+ /** Called before Open in calendar leaves the email. */
+ onNavigate?: () => void;
}) {
const calendarEnabled = useCalendarUiFlag();
const saved = () => (
@@ -135,8 +137,13 @@ function ConnectedInvitation(
},
get openCalendar() {
const target = openTarget();
- return target && props.openCalendar
- ? () => props.openCalendar?.(target)
+ const open = props.openCalendar;
+ const leave = props.onNavigate;
+ return target && open
+ ? () => {
+ leave?.();
+ open(target);
+ }
: undefined;
},
get showDay() {
diff --git a/apps/web/src/features/email-thread/context/email-thread-view-context.tsx b/apps/web/src/features/email-thread/context/email-thread-view-context.tsx
index eadb777f71..603463bfbe 100644
--- a/apps/web/src/features/email-thread/context/email-thread-view-context.tsx
+++ b/apps/web/src/features/email-thread/context/email-thread-view-context.tsx
@@ -8,6 +8,7 @@ import type {
EmailAttachment,
EmailMessage,
} from '../../email-message/core/email-message';
+import type { InvitationRenderOptions } from '../../email-message/views/email-message';
import type { EmailThreadContext } from './email-thread-context';
export interface EmailThreadOrganizationStatus {
@@ -27,7 +28,8 @@ export interface EmailThreadViewContext {
) => JSX.Element;
renderInvitation?: (
message: EmailMessage,
- invitation: CalendarInvitation
+ invitation: CalendarInvitation,
+ options?: InvitationRenderOptions
) => JSX.Element;
renderOperation?: (message: EmailMessage) => JSX.Element;
renderAvatar?: (message: EmailMessage) => JSX.Element;
diff --git a/apps/web/src/features/email-thread/email-thread.tsx b/apps/web/src/features/email-thread/email-thread.tsx
index 612380aba0..de8dcfc5c9 100644
--- a/apps/web/src/features/email-thread/email-thread.tsx
+++ b/apps/web/src/features/email-thread/email-thread.tsx
@@ -31,6 +31,7 @@ import { operationSettled } from '../email-message/core/message-operation';
import { EmailMessageOperation } from '../email-message/email-message-operation';
import { createEmailRenderingContext } from '../email-message/rendering-adapter';
import { EmailSenderIcon } from '../email-message/sender-icon-adapter';
+import type { InvitationRenderOptions } from '../email-message/views/email-message';
import {
type CalendarInvitationOpenTarget,
EmailCalendarInvitation,
@@ -121,7 +122,8 @@ export function EmailThread(props: EmailThreadProps) {
),
renderInvitation: (
message: EmailMessage,
- invitation: CalendarInvitation
+ invitation: CalendarInvitation,
+ options?: InvitationRenderOptions
) => (
<EmailCalendarInvitation
threadId={props.threadId()}
@@ -129,6 +131,7 @@ export function EmailThread(props: EmailThreadProps) {
invitation={invitation}
hour12={calendarPreferences.timeFormat !== '24-hour'}
openCalendar={props.openCalendar}
+ onNavigate={options?.onNavigate}
/>
),
openAttachment: createEmailAttachmentOpener(),
diff --git a/apps/web/src/features/email-thread/queries/thread-source.test.ts b/apps/web/src/features/email-thread/queries/thread-source.test.ts
index 58413a14a8..3000cfd13f 100644
--- a/apps/web/src/features/email-thread/queries/thread-source.test.ts
+++ b/apps/web/src/features/email-thread/queries/thread-source.test.ts
@@ -266,6 +266,12 @@ it('keeps rendering and attachment identities while excluding transport metadata
filename: 'image.png',
size_bytes: 123,
},
+ {
+ db_id: 'cloud',
+ filename: 'invite.ics',
+ mime_type: 'text/calendar',
+ reference_url: 'https://outlook.office.com/mail/item',
+ },
],
attachments_draft: [
{
@@ -302,7 +308,10 @@ it('keeps rendering and attachment identities while excluding transport metadata
scheduled_send_time: '2026-10-01T12:00:00Z',
scheduled_send_status: 'unconfirmed',
labels: [{ name: 'CATEGORY_PERSONAL', provider_label_id: 'UNREAD' }],
- attachments: [{ db_id: 'inline', content_id: 'image-cid', sfs_id: 'file' }],
+ attachments: [
+ { db_id: 'inline', content_id: 'image-cid', sfs_id: 'file' },
+ { db_id: 'cloud', reference_url: 'https://outlook.office.com/mail/item' },
+ ],
attachments_draft: [{ id: 'draft-file', s3_key: 'notes' }],
attachments_forwarded: [
{ attachment_id: 'forward-file', filename: 'forward.txt' },
diff --git a/apps/web/src/features/email-thread/queries/thread-source.ts b/apps/web/src/features/email-thread/queries/thread-source.ts
index e0aeb92b8b..ccfb1d52d8 100644
--- a/apps/web/src/features/email-thread/queries/thread-source.ts
+++ b/apps/web/src/features/email-thread/queries/thread-source.ts
@@ -25,6 +25,7 @@ export function toEmailThread(thread: ApiThread): EmailThread {
db_id: attachment.db_id,
filename: attachment.filename,
mime_type: attachment.mime_type,
+ reference_url: attachment.reference_url,
sfs_id: attachment.sfs_id,
size_bytes: attachment.size_bytes,
})),
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index b60b3bd73c..76d03fadf7 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -1235,8 +1235,11 @@ ICS attachments show a calendar icon in the attachment pill and file headers on
desktop and mobile, including when the email uses `application/ics` or a
parameterized `text/calendar` MIME type. Opening the attachment of a message that shows a
card opens a dialog (a drawer on phones) with the same card, so its RSVP or `Add to calendar`
-works there, and `Download .ics`, which saves the file without adding it to Drive. A calendar
-file with no card (nothing Macro could read) downloads directly.
+works there, and `Download .ics`, which saves the file without adding it to Drive. The card
+stays put while the thread refreshes, and `Open in calendar` closes the dialog before the
+calendar opens, including when Calendar is already open in another split. A calendar file with
+no card (nothing Macro could read) downloads directly, and an Outlook cloud-reference `.ics`
+opens its Outlook page like any other reference attachment.
Related recurring components are grouped behind their own disclosure. Only mail synced
after the feature shipped gets a card; older invitations render as plain email.
A newly arrived scheduling update shows RSVP and Join only once its calendar state has