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
feat(email): copy subject and recipient name (#5929)
teo27d93134877a
diff --git a/apps/web/src/features/block-email/component/CopySubjectButton.tsx b/apps/web/src/features/block-email/component/CopySubjectButton.tsxnew file mode 100644index 0000000000..adc0007447--- /dev/null+++ b/apps/web/src/features/block-email/component/CopySubjectButton.tsx@@ -0,0 +1,46 @@+import { toast } from '@core/component/Toast/Toast';+import WideCopy from '@icon/wide-copy.svg';+import IconCheck from '@phosphor/check.svg';+import { debounce } from '@solid-primitives/scheduled';+import { cn } from '@ui/utils/classname';+import { createSignal, Show } from 'solid-js';+import { isPlaceholderSubject } from '../util/subjectText';++function copyableSubject(title: string): string | undefined {+ const subject = title.trim();+ if (!subject || isPlaceholderSubject(subject)) return undefined;+ return subject;+}++export function CopySubjectButton(props: { subject: string; class?: string }) {+ const [copied, setCopied] = createSignal(false);+ const resetCopied = debounce(() => setCopied(false), 800);++ function handleCopy(e: MouseEvent) {+ e.stopPropagation();+ const subject = copyableSubject(props.subject);+ if (!subject) return;+ navigator.clipboard.writeText(subject);+ toast.success('Subject copied');+ setCopied(true);+ resetCopied();+ }++ return (+ <Show when={copyableSubject(props.subject)}>+ <button+ type="button"+ aria-label="Copy subject"+ class={cn(+ 'inline-flex align-middle size-6 items-center justify-center rounded-md select-none text-inherit hover:bg-ink/10',+ props.class+ )}+ onClick={handleCopy}+ >+ <Show when={copied()} fallback={<WideCopy class="size-3.5" />}>+ <IconCheck class="size-3.5" />+ </Show>+ </button>+ </Show>+ );+}diff --git a/apps/web/src/features/block-email/component/Email.tsx b/apps/web/src/features/block-email/component/Email.tsxindex 3b54758ed0..75aa607910 100644--- a/apps/web/src/features/block-email/component/Email.tsx+++ b/apps/web/src/features/block-email/component/Email.tsx@@ -43,6 +43,7 @@ import { scrollToMessage } from '../util/scrollToMessage';import { BottomReplyButtons } from './BottomReplyButtons';import { EmailFormContextProvider } from './EmailFormContext';import { EmailParticipants } from './EmailParticipants';+import { EmailThreadTitle } from './EmailThreadTitle';import { openEmailReplyComposerForMessage } from './emailReplyActions';import { MessageList } from './MessageList';import { MobileEmailComposeDrawer } from './MobileEmailComposeDrawer';@@ -752,9 +753,11 @@ function EmailContent(props: EmailViewProps) {}}><div class="h-12" />- <h1 class="ph-no-capture text-2xl font-semibold text-ink pb-1.5 tracking-tight text-balance">- {props.title}- </h1>+ <EmailThreadTitle+ title={props.title}+ copyReveal="hover"+ class="text-2xl pb-1.5"+ /><div class="pb-2.5"><EmailParticipants /></div>diff --git a/apps/web/src/features/block-email/component/EmailThreadTitle.tsx b/apps/web/src/features/block-email/component/EmailThreadTitle.tsxnew file mode 100644index 0000000000..6929bcf233--- /dev/null+++ b/apps/web/src/features/block-email/component/EmailThreadTitle.tsx@@ -0,0 +1,42 @@+import { cn } from '@ui/utils/classname';+import { createSignal } from 'solid-js';+import { CopySubjectButton } from './CopySubjectButton';++function lastWordCluster(title: string): { lead: string; last: string } {+ const i = title.lastIndexOf(' ');+ if (i === -1) return { lead: '', last: title };+ return { lead: title.slice(0, i + 1), last: title.slice(i + 1) };+}++export function EmailThreadTitle(props: {+ title: string;+ copyReveal?: 'hover' | 'always';+ class?: string;+}) {+ const [titleHovered, setTitleHovered] = createSignal(false);+ const cluster = () => lastWordCluster(props.title);+ const copyHidden = () => props.copyReveal === 'hover' && !titleHovered();++ return (+ <h1+ class={cn(+ 'ph-no-capture block w-full max-w-full min-w-0 text-pretty font-semibold tracking-tight text-ink select-text cursor-text wrap-break-word leading-snug',+ props.class+ )}+ onMouseEnter={() => setTitleHovered(true)}+ onMouseLeave={() => setTitleHovered(false)}+ >+ {cluster().lead}+ <span class={cluster().lead ? 'whitespace-nowrap' : undefined}>+ {cluster().last}+ <CopySubjectButton+ subject={props.title}+ class={cn(+ 'ml-1.5 select-none text-inherit transition-opacity',+ copyHidden() ? 'opacity-0' : 'opacity-100'+ )}+ />+ </span>+ </h1>+ );+}diff --git a/apps/web/src/features/block-email/component/MessageList.tsx b/apps/web/src/features/block-email/component/MessageList.tsxindex 65280c685c..9e28bfb803 100644--- a/apps/web/src/features/block-email/component/MessageList.tsx+++ b/apps/web/src/features/block-email/component/MessageList.tsx@@ -11,6 +11,7 @@ import {onCleanup,Show,} from 'solid-js';+import { EmailThreadTitle } from './EmailThreadTitle';import { MessageContainer } from './MessageContainer';// Fraction of the list height reserved below the newest message so it rests@@ -177,9 +178,11 @@ export function MessageList(props: MessageListProps) {<Show when={isTouchDevice() && props.title}><div class="shrink-0 w-full flex justify-center pb-3"><div class="macro-message-width macro-message-padding w-full">- <h1 class="text-xl font-semibold text-ink pt-1 pb-0 tracking-tight text-balance">- {props.title}- </h1>+ <EmailThreadTitle+ title={props.title ?? ''}+ copyReveal="always"+ class="text-xl pt-1 pb-0"+ /></div></div></Show>diff --git a/apps/web/src/features/block-email/util/subjectText.ts b/apps/web/src/features/block-email/util/subjectText.tsindex 59c4b1148d..57047a549a 100644--- a/apps/web/src/features/block-email/util/subjectText.ts+++ b/apps/web/src/features/block-email/util/subjectText.ts@@ -1,6 +1,8 @@import type { ApiMessage } from '@service-email/generated/schemas';import type { ReplyType } from './replyType';+const NO_SUBJECT = '[No subject]';+/*** A thread subject as it should be shown: accumulated "re:" prefixes stripped,* and a name for the blank case so callers never have to render an empty string.@@ -9,9 +11,12 @@ export const displaySubject = (subject: string | null | undefined): string => {// Strip before testing for blank: a subject of just "Re:" is empty once the// prefix is gone, and callers rely on this never returning an empty string.const stripped = subject?.replace(/^(\s*re:\s*)+/i, '').trim();- return stripped || '[No subject]';+ return stripped || NO_SUBJECT;};+export const isPlaceholderSubject = (title: string): boolean =>+ title === NO_SUBJECT;+export const getSubjectText = (replyingTo: ApiMessage | undefined,replyType: ReplyType | undefineddiff --git a/apps/web/src/lib/core/component/UserTooltip.test.tsx b/apps/web/src/lib/core/component/UserTooltip.test.tsxindex a768d72a94..ae082b8578 100644--- a/apps/web/src/lib/core/component/UserTooltip.test.tsx+++ b/apps/web/src/lib/core/component/UserTooltip.test.tsx@@ -88,9 +88,9 @@ describe('UserTooltip CRM contact action', () => {const user = userEvent.setup({ skipHover: true });render(() => (<UserTooltip- displayName="Panat Taranat"- email="[email protected]"- id="macro|[email protected]"+ displayName="Jane Doe"+ email="[email protected]"+ id="macro|[email protected]"onClose={mocks.onClose}/>));@@ -110,7 +110,7 @@ describe('UserTooltip CRM contact action', () => {mocks.crmFlagEnabled = false;render(() => (- <UserTooltip displayName="Panat Taranat" email="[email protected]" />+ <UserTooltip displayName="Jane Doe" email="[email protected]" />));expect(screen.queryByRole('button', { name: 'Open contact' })).toBeNull();@@ -120,7 +120,7 @@ describe('UserTooltip CRM contact action', () => {mocks.teamCrmEnabled = false;render(() => (- <UserTooltip displayName="Panat Taranat" email="[email protected]" />+ <UserTooltip displayName="Jane Doe" email="[email protected]" />));expect(screen.queryByRole('button', { name: 'Open contact' })).toBeNull();@@ -130,7 +130,7 @@ describe('UserTooltip CRM contact action', () => {mocks.teamCrmEnabled = null;render(() => (- <UserTooltip displayName="Panat Taranat" email="[email protected]" />+ <UserTooltip displayName="Jane Doe" email="[email protected]" />));expect(screen.queryByRole('button', { name: 'Open contact' })).toBeNull();@@ -140,7 +140,7 @@ describe('UserTooltip CRM contact action', () => {mocks.contact = null;render(() => (- <UserTooltip displayName="Panat Taranat" email="[email protected]" />+ <UserTooltip displayName="Jane Doe" email="[email protected]" />));expect(screen.queryByRole('button', { name: 'Open contact' })).toBeNull();@@ -151,13 +151,13 @@ describe('UserTooltip CRM contact action', () => {render(() => (<UserTooltip- displayName="Panat Taranat"- email="[email protected]"- id="macro|[email protected]"+ displayName="Jane Doe"+ email="[email protected]"+ id="macro|[email protected]"/>));- expect(screen.getByText('Panat Taranat')).toBeTruthy();+ expect(screen.getByText('Jane Doe')).toBeTruthy();expect(screen.getByRole('button', { name: 'Copy email' })).toBeTruthy();expect(screen.queryByRole('button', { name: 'Open contact' })).toBeNull();});diff --git a/apps/web/src/lib/core/component/UserTooltip.tsx b/apps/web/src/lib/core/component/UserTooltip.tsxindex 35ca344c53..15f2ef7f98 100644--- a/apps/web/src/lib/core/component/UserTooltip.tsx+++ b/apps/web/src/lib/core/component/UserTooltip.tsx@@ -29,20 +29,22 @@ type UserTooltipProps = {photoUrl?: string;};-export function UserTooltip(props: UserTooltipProps) {- const [copied, setCopied] = createSignal(false);- const resetCopied = debounce(() => setCopied(false), 800);-- function handleCopyEmail(e: MouseEvent) {- e.stopPropagation();- const email = props.email;- if (!email) return;- setCopied(true);- navigator.clipboard.writeText(email);- toast.success('Email copied');- resetCopied();- props.onClose?.();+function copyableName(+ displayName: string,+ email: string | undefined+): string | undefined {+ const name = displayName.trim();+ if (!name) return undefined;+ if (name.toLowerCase() === 'me') return undefined;+ if (email && name.toLowerCase() === email.toLowerCase()) return undefined;+ const localPart = email?.split('@')[0];+ if (localPart && name.toLowerCase() === localPart.toLowerCase()) {+ return undefined;}+ return name;+}++export function UserTooltip(props: UserTooltipProps) {const currentUserId = useUserId();const isConnectedSecondaryInbox = useIsConnectedSecondaryInbox();const canTreatAsUser = () =>@@ -121,18 +123,28 @@ export function UserTooltip(props: UserTooltipProps) {</div></div>- <Show when={props.email || props.id}>+ <Show+ when={+ props.email ||+ props.id ||+ copyableName(props.displayName, props.email)+ }+ ><div class="border-t border-edge"></div><div class="p-1.5 flex flex-col gap-0.5"><Show when={props.email}>- <ActionItem onClick={handleCopyEmail}>- {copied() ? (- <IconCheck class="size-3.5" />- ) : (- <WideCopy class="size-3.5" />- )}- Copy email- </ActionItem>+ {(email) => (+ <CopyActionItem value={email()} toastMessage="Email copied">+ Copy email+ </CopyActionItem>+ )}+ </Show>+ <Show when={copyableName(props.displayName, props.email)}>+ {(name) => (+ <CopyActionItem value={name()} toastMessage="Name copied">+ Copy name+ </CopyActionItem>+ )}</Show><Show when={crmFlag().enabled ? props.email : undefined}>{(email) => (@@ -197,6 +209,34 @@ function OpenContactAction(props: { email: string; onClose?: () => void }) {);}+function CopyActionItem(props: {+ value: string;+ toastMessage: string;+ children: JSX.Element;+}) {+ const [copied, setCopied] = createSignal(false);+ const resetCopied = debounce(() => setCopied(false), 800);++ function handleCopy(e: MouseEvent) {+ e.stopPropagation();+ setCopied(true);+ navigator.clipboard.writeText(props.value);+ toast.success(props.toastMessage);+ resetCopied();+ }++ return (+ <ActionItem onClick={handleCopy}>+ {copied() ? (+ <IconCheck class="size-3.5" />+ ) : (+ <WideCopy class="size-3.5" />+ )}+ {props.children}+ </ActionItem>+ );+}+function ActionItem(props: {children: JSX.Element;onClick: JSX.EventHandler<HTMLButtonElement, MouseEvent>;