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(email): download attachments from the chip (#8881)

Jacob Beckermancb947251830d
diff --git a/apps/web/src/features/email-message/components/attachment-pill.test.tsx b/apps/web/src/features/email-message/components/attachment-pill.test.tsx
index be62ca062a..704544ecac 100644
--- a/apps/web/src/features/email-message/components/attachment-pill.test.tsx
+++ b/apps/web/src/features/email-message/components/attachment-pill.test.tsx
@@ -40,3 +40,38 @@ it('opens attachments with Enter and Space, while removal stays a separate keybo
view.unmount();
}
});
+
+it('downloads from the split button without opening the attachment', async () => {
+ const open = vi.fn();
+ const download = vi.fn();
+ const user = userEvent.setup();
+ const view = render(() => (
+ <EmailAttachmentPill
+ attachment={{ fileName: 'agenda.pdf', mimeType: 'application/pdf' }}
+ onClick={open}
+ onDownload={download}
+ />
+ ));
+ try {
+ await user.tab();
+ expect(document.activeElement).toBe(
+ view.getByRole('button', { name: 'agenda.pdf' })
+ );
+ await user.keyboard('{Enter}');
+ expect(open).toHaveBeenCalledOnce();
+ expect(download).not.toHaveBeenCalled();
+ await user.tab();
+ const downloadButton = view.getByRole('button', {
+ name: 'Download agenda.pdf',
+ });
+ expect(document.activeElement).toBe(downloadButton);
+ await user.keyboard('{Enter}');
+ expect(download).toHaveBeenCalledOnce();
+ expect(open).toHaveBeenCalledOnce();
+ await user.click(downloadButton);
+ expect(download).toHaveBeenCalledTimes(2);
+ expect(open).toHaveBeenCalledOnce();
+ } finally {
+ view.unmount();
+ }
+});
diff --git a/apps/web/src/features/email-message/components/attachment-pill.tsx b/apps/web/src/features/email-message/components/attachment-pill.tsx
index 067d91ecca..ed91cb0157 100644
--- a/apps/web/src/features/email-message/components/attachment-pill.tsx
+++ b/apps/web/src/features/email-message/components/attachment-pill.tsx
@@ -1,6 +1,8 @@
import { EntityIcon } from '@core/component/EntityIcon';
+import DownloadSimple from '@icon/system/regular/download-simple.svg';
import X from '@icon/system/regular/x.svg';
import { FileTypeMap } from '@service-storage/fileTypeMap';
+import { Tooltip } from '@ui';
import { Show } from 'solid-js';
import { Dynamic } from 'solid-js/web';
import { isCalendarFile } from '../core/email-message';
@@ -15,6 +17,8 @@ type EmailAttachmentPillProps = {
onRemove?: () => void;
/** Receives the chip, so a dialog it opens can return focus to it. */
onClick?: (chip: HTMLElement) => void;
+ /** Saves the file without opening it. Renders as the chip's split segment. */
+ onDownload?: () => void;
};
export function EmailAttachmentPill(props: EmailAttachmentPillProps) {
@@ -31,18 +35,32 @@ export function EmailAttachmentPill(props: EmailAttachmentPillProps) {
return mimeType ? mimeToFileExtTypeMap.get(mimeType) : undefined;
};
+ const downloadLabel = () => `Download ${props.attachment.fileName}`;
+
return (
<div
ref={parentDiv}
- class="items-center text-xs flex flex-row p-2 w-36 rounded-lg border border-ink-muted/8 bg-ink-muted/2.5 hover:bg-ink-muted/6"
+ class="text-xs flex flex-row rounded-lg border border-ink-muted/8 bg-ink-muted/2.5"
classList={{
- 'pl-2': props.removable,
+ 'items-center': !props.onDownload,
+ 'p-2': !props.onDownload,
+ 'w-36': !props.onDownload,
+ 'hover:bg-ink-muted/6': !props.onDownload,
+ 'pl-2': props.removable && !props.onDownload,
+ 'items-stretch': !!props.onDownload,
+ 'overflow-hidden': !!props.onDownload,
}}
>
<Dynamic
component={props.onClick ? 'button' : 'div'}
type={props.onClick ? 'button' : undefined}
- class="flex min-w-0 flex-1 items-center text-left"
+ data-button=""
+ class="flex min-w-0 flex-1 items-center text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-edge-focus"
+ classList={{
+ 'w-36': !!props.onDownload,
+ 'p-2': !!props.onDownload,
+ 'hover:bg-ink-muted/6': !!props.onDownload,
+ }}
onClick={(event: MouseEvent) => {
if (event.currentTarget instanceof HTMLElement) {
props.onClick?.(event.currentTarget);
@@ -59,9 +77,34 @@ export function EmailAttachmentPill(props: EmailAttachmentPillProps) {
{props.attachment.fileName}
</span>
</Dynamic>
+ <Show when={props.onDownload}>
+ <div class="w-px self-stretch bg-edge-divider" />
+ <Tooltip
+ label={downloadLabel()}
+ class="flex items-stretch self-stretch"
+ >
+ <button
+ type="button"
+ data-button=""
+ aria-label={downloadLabel()}
+ class="flex w-8 shrink-0 items-center justify-center hover:bg-ink-muted/6 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-edge-focus"
+ onClick={(e) => {
+ e.preventDefault();
+ e.stopPropagation();
+ props.onDownload?.();
+ }}
+ onKeyDown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') e.stopPropagation();
+ }}
+ >
+ <DownloadSimple width="16" height="16" />
+ </button>
+ </Tooltip>
+ </Show>
<Show when={props.removable}>
<button
type="button"
+ data-button=""
aria-label={`Remove ${props.attachment.fileName}`}
class="ml-auto p-2 hover:text-failure"
onPointerDown={(e) => {
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 30f3c6d7a4..a952e3c86c 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
@@ -5,7 +5,7 @@ import {
screen,
waitFor,
} from '@solidjs/testing-library';
-import { createSignal, type JSX } from 'solid-js';
+import { createSignal, type JSX, Show } from 'solid-js';
import { afterEach, expect, it, vi } from 'vitest';
import type { CalendarInvitation } from '../core/calendar-invitation';
import { invitationFixture } from '../core/calendar-invitation-fixtures';
@@ -30,13 +30,21 @@ vi.mock('@app/features/email-message/components/attachment-pill', () => ({
EmailAttachmentPill: (props: {
attachment: { fileName: string };
onClick?: (chip: HTMLElement) => void;
+ onDownload?: () => void;
}) => (
- <button
- type="button"
- onClick={(event) => props.onClick?.(event.currentTarget)}
- >
- {props.attachment.fileName}
- </button>
+ <>
+ <button
+ type="button"
+ onClick={(event) => props.onClick?.(event.currentTarget)}
+ >
+ {props.attachment.fileName}
+ </button>
+ <Show when={props.onDownload}>
+ <button type="button" onClick={() => props.onDownload?.()}>
+ Download {props.attachment.fileName}
+ </button>
+ </Show>
+ </>
),
}));
vi.mock('@core/component/ImageGalleryPreview', () => ({
@@ -111,7 +119,7 @@ it('opens a calendar file as the event it holds and other files through the host
isExpanded
/>
));
- fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ fireEvent.click(screen.getByRole('button', { name: /^Planning\.ics$/ }));
const preview = screen.getByRole('dialog');
expect(preview.textContent).toContain(invitationFixture.id);
fireEvent.click(screen.getByRole('button', { name: 'Download .ics' }));
@@ -119,7 +127,7 @@ it('opens a calendar file as the event it holds and other files through the host
expect(onOpenAttachment).not.toHaveBeenCalled();
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
expect(screen.queryByRole('dialog')).toBeNull();
- fireEvent.click(screen.getByRole('button', { name: 'Agenda.pdf' }));
+ fireEvent.click(screen.getByRole('button', { name: /^Agenda\.pdf$/ }));
expect(onOpenAttachment).toHaveBeenCalledWith(pdfFile);
});
@@ -142,7 +150,7 @@ it('tells the card when it is shown inside its calendar file', () => {
/>
));
expect(screen.getByTestId('card').textContent).toContain('inline');
- fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ fireEvent.click(screen.getByRole('button', { name: /^Planning\.ics$/ }));
expect(screen.getByRole('dialog').textContent).toContain('in file');
});
@@ -159,7 +167,7 @@ it('hands a calendar file without a readable event to the host', () => {
isExpanded
/>
));
- fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ fireEvent.click(screen.getByRole('button', { name: /^Planning\.ics$/ }));
expect(screen.queryByRole('dialog')).toBeNull();
expect(onOpenAttachment).toHaveBeenCalledWith(calendarFile);
});
@@ -182,7 +190,7 @@ it('keeps the opened calendar file card mounted when the thread refreshes the me
isExpanded
/>
));
- fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ 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);
@@ -201,7 +209,7 @@ it('returns focus to the calendar file chip when its dialog closes', async () =>
isExpanded
/>
));
- const chip = screen.getByRole('button', { name: 'Planning.ics' });
+ const chip = screen.getByRole('button', { name: /^Planning\.ics$/ });
fireEvent.click(chip);
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
expect(screen.queryByRole('dialog')).toBeNull();
@@ -228,7 +236,7 @@ it('keeps the chip to return focus to when the thread refreshes its attachments'
isExpanded
/>
));
- const chip = screen.getByRole('button', { name: 'Planning.ics' });
+ const chip = screen.getByRole('button', { name: /^Planning\.ics$/ });
fireEvent.click(chip);
setCurrent({
...message([invitationFixture]),
@@ -236,7 +244,7 @@ it('keeps the chip to return focus to when the thread refreshes its attachments'
});
// The open dialog hides the page behind it from the accessibility tree.
expect(
- screen.getByRole('button', { name: 'Planning.ics', hidden: true })
+ screen.getByRole('button', { name: /^Planning\.ics$/, hidden: true })
).toBe(chip);
fireEvent.click(screen.getByRole('button', { name: 'Close' }));
await waitFor(() => expect(document.activeElement).toBe(chip));
@@ -259,7 +267,7 @@ it('closes the calendar file dialog when its card opens the calendar', async ()
isExpanded
/>
));
- const chip = screen.getByRole('button', { name: 'Planning.ics' });
+ const chip = screen.getByRole('button', { name: /^Planning\.ics$/ });
fireEvent.click(chip);
expect(screen.getByRole('dialog')).toBeTruthy();
navigate?.();
@@ -291,7 +299,57 @@ it('opens a cloud-reference calendar file through the host', () => {
isExpanded
/>
));
- fireEvent.click(screen.getByRole('button', { name: 'Planning.ics' }));
+ fireEvent.click(screen.getByRole('button', { name: /^Planning\.ics$/ }));
expect(screen.queryByRole('dialog')).toBeNull();
expect(onOpenAttachment).toHaveBeenCalledWith(reference);
});
+
+it('downloads every attachment type from its chip and skips cloud references', () => {
+ const onOpenAttachment = vi.fn();
+ const onDownloadAttachment = vi.fn();
+ const image = {
+ db_id: 'img',
+ filename: 'photo.png',
+ mime_type: 'image/png',
+ sfs_id: 'sfs-photo',
+ };
+ const video = {
+ db_id: 'vid',
+ filename: 'clip.mp4',
+ mime_type: 'video/mp4',
+ sfs_id: 'sfs-clip',
+ };
+ const reference = {
+ ...calendarFile,
+ reference_url: 'https://outlook.office.com/mail/item',
+ };
+ render(() => (
+ <EmailMessageView
+ message={
+ {
+ ...message([]),
+ attachments: [pdfFile, image, video, reference],
+ } as unknown as EmailMessage
+ }
+ onOpenAttachment={onOpenAttachment}
+ onDownloadAttachment={onDownloadAttachment}
+ isTouch={false}
+ isPersonal={false}
+ isSelected={false}
+ allowHover={false}
+ isExpanded
+ />
+ ));
+ fireEvent.click(screen.getByRole('button', { name: 'Download Agenda.pdf' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Download photo.png' }));
+ fireEvent.click(screen.getByRole('button', { name: 'Download clip.mp4' }));
+ expect(
+ screen.queryByRole('button', { name: 'Download Planning.ics' })
+ ).toBeNull();
+ expect(onDownloadAttachment.mock.calls).toEqual([
+ [pdfFile],
+ [image],
+ [video],
+ ]);
+ expect(onOpenAttachment).not.toHaveBeenCalled();
+});
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 db35fcedfe..54807a1343 100644
--- a/apps/web/src/features/email-message/views/email-message.tsx
+++ b/apps/web/src/features/email-message/views/email-message.tsx
@@ -146,15 +146,6 @@ export function EmailMessageView(props: EmailMessageViewProps) {
);
});
- const otherAttachments = createMemo(() => {
- return visibleAttachments().filter(
- (a) =>
- !a.sfs_id ||
- (!a.mime_type?.startsWith('image/') &&
- !a.mime_type?.startsWith('video/'))
- );
- });
-
return (
<MessageCard
messageId={props.message.db_id}
@@ -259,13 +250,13 @@ export function EmailMessageView(props: EmailMessageViewProps) {
</For>
</Show>
- {/* Other attachments (non-media or without sfs_id) */}
- <Show when={otherAttachments().length > 0}>
+ {/* One chip per received file, of any type. Previews stay above. */}
+ <Show when={visibleAttachments().length > 0}>
<div class="flex flex-row overflow-x-scroll mt-2 gap-2">
{/* Keyed so a thread refresh keeps each chip, and with it the
calendar file dialog's focus target. */}
<Key
- each={otherAttachments()}
+ each={visibleAttachments()}
by={(attachment) => attachment.db_id}
>
{(attachment) => (
@@ -279,6 +270,11 @@ export function EmailMessageView(props: EmailMessageViewProps) {
? (chip) => openAttachment(attachment(), chip)
: undefined
}
+ onDownload={
+ props.onDownloadAttachment && !attachment().reference_url
+ ? () => props.onDownloadAttachment?.(attachment())
+ : undefined
+ }
/>
)}
</Key>
diff --git a/docs/agent-guide/calendar.md b/docs/agent-guide/calendar.md
index 0214a2c3b5..6d0b929083 100644
--- a/docs/agent-guide/calendar.md
+++ b/docs/agent-guide/calendar.md
@@ -1349,9 +1349,10 @@ is an accessible disclosure that starts closed and stays open across unchanged
permission refreshes and window refocus on desktop and mobile; attachments remain below it.
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
+parameterized `text/calendar` MIME type. The pill's download button saves the
+file without opening it and without adding it to Drive. 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. When an
+works there, and `Download .ics`, which saves the file the same way. When an
invitation's card falls back to the saved invitation (the event matches nothing on your
calendars), its status line reads `Saved invitation.` in the dialog; the card in the email
adds that the original email or invitation attachment has more options. A shared event shown
diff --git a/docs/agent-guide/email.md b/docs/agent-guide/email.md
index 4b6b084d90..20574be545 100644
--- a/docs/agent-guide/email.md
+++ b/docs/agent-guide/email.md
@@ -131,7 +131,10 @@ further reloads, even while an offline edit is still queued.
Opening an attachment opens it in a split from its Drive copy, except a
calendar file: it opens its event (see the calendar invitations section of the
calendar guide), or downloads when Macro could not read one, and creates no
-Drive file.
+Drive file. Every received attachment chip, of any file type, has a download
+button joined to the filename that saves the file without opening it. Images
+and videos keep their previews and get the same chip. Cloud-reference chips
+stay open-only.
Imported Outlook attachments keep their provider identity, including inline
images. Cloud-reference attachment chips open the original Outlook message.