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]: condense long recipient list (#1088)

Peter Chinman52bcc0d6120d
diff --git a/js/app/packages/block-email/component/BaseInput.tsx b/js/app/packages/block-email/component/BaseInput.tsx
index 2f5d53fd4c..320257326c 100644
--- a/js/app/packages/block-email/component/BaseInput.tsx
+++ b/js/app/packages/block-email/component/BaseInput.tsx
@@ -19,6 +19,7 @@ import { RecipientSelector } from '@core/component/RecipientSelector';
import { toast } from '@core/component/Toast/Toast';
import { Tooltip } from '@core/component/Tooltip';
import { fileFolderDrop } from '@core/directive/fileFolderDrop';
+import { observedSize } from '@core/directive/observedSize';
import { TOKENS } from '@core/hotkey/tokens';
import { isMobileWidth } from '@core/mobile/mobileWidth';
import { trackMention } from '@core/signal/mention';
@@ -104,6 +105,7 @@ import { plural } from '@core/util/string';
false && fileFolderDrop;
false && fileSelector;
+false && observedSize;
const getRecipientDisplayName = (item: EmailRecipient): string => {
switch (item.kind) {
@@ -115,31 +117,169 @@ const getRecipientDisplayName = (item: EmailRecipient): string => {
}
};
-function RecipientList(props: {
- recipients: EmailRecipient[];
- showTrailingComma: boolean;
+// Shared constants for recipient display - used in both measurement and rendering
+const RECIPIENT_SEPARATOR = ',\u00A0'; // comma + non-breaking space
+const MORE_SUFFIX_TEMPLATE = '+99 more'; // worst-case for measurement
+
+// Build the display text for a recipient (used for measurement)
+const buildRecipientText = (
+ prefix: string,
+ displayName: string,
+ showSeparator: boolean
+): string => {
+ return prefix + displayName + (showSeparator ? RECIPIENT_SEPARATOR : '');
+};
+
+function TruncatedRecipientList(props: {
+ toRecipients: EmailRecipient[];
+ ccRecipients: EmailRecipient[];
+ bccRecipients: EmailRecipient[];
+ onClick: () => void;
}) {
+ let measureRef: HTMLSpanElement | undefined;
+
+ const [visibleCount, setVisibleCount] = createSignal<number>(0);
+ const [containerRect, setContainerRect] = createSignal<DOMRect | undefined>();
+
+ // Combine all recipients into a flat list with group info for display
+ const allRecipients = createMemo(() => {
+ const result: { recipient: EmailRecipient; prefix: string }[] = [];
+
+ // Add "to" recipients
+ props.toRecipients.forEach((r, i) => {
+ const prefix = i === 0 ? 'to ' : '';
+ result.push({ recipient: r, prefix });
+ });
+
+ // Add "cc" recipients (show "cc" prefix only if no "to" recipients)
+ props.ccRecipients.forEach((r, i) => {
+ const prefix = i === 0 && props.toRecipients.length === 0 ? 'cc ' : '';
+ result.push({ recipient: r, prefix });
+ });
+
+ // Add "bcc" recipients with label
+ props.bccRecipients.forEach((r, i) => {
+ const prefix = i === 0 ? 'bcc ' : '';
+ result.push({ recipient: r, prefix });
+ });
+
+ return result;
+ });
+
+ const totalCount = createMemo(() => allRecipients().length);
+
+ // Measure text width using hidden element
+ const measureText = (text: string): number => {
+ if (!measureRef) return 0;
+ measureRef.textContent = text;
+ return measureRef.offsetWidth;
+ };
+
+ // Calculate how many recipients fit in the container
+ const calculateVisibleCount = () => {
+ const width = containerRect()?.width ?? 0;
+ if (width <= 0 || !measureRef) return;
+
+ const recipients = allRecipients();
+ if (recipients.length === 0) {
+ setVisibleCount(0);
+ return;
+ }
+
+ // Reserve space for "+N more" suffix
+ const moreTextWidth = measureText(MORE_SUFFIX_TEMPLATE);
+ const availableWidth = width - moreTextWidth;
+
+ let usedWidth = 0;
+ let count = 0;
+
+ for (let i = 0; i < recipients.length; i++) {
+ const { recipient, prefix } = recipients[i];
+ const displayName = getRecipientDisplayName(recipient);
+ // Show separator if not the last recipient OR if there will be hidden recipients
+ const showSeparator = i < recipients.length - 1;
+ const text = buildRecipientText(prefix, displayName, showSeparator);
+ const textWidth = measureText(text);
+
+ // Check if this recipient fits (always show at least one)
+ if (usedWidth + textWidth <= availableWidth || i === 0) {
+ usedWidth += textWidth;
+ count++;
+ } else {
+ break;
+ }
+ }
+
+ setVisibleCount(count);
+ };
+
+ // Recalculate visible count when size or recipients change
+ createEffect(() => {
+ // Track dependencies
+ containerRect();
+ allRecipients();
+ // Use requestAnimationFrame to ensure measurement element is ready
+ requestAnimationFrame(() => {
+ calculateVisibleCount();
+ });
+ });
+
+ const visibleRecipients = createMemo(() => {
+ return allRecipients().slice(0, visibleCount());
+ });
+
+ const hiddenCount = createMemo(() => {
+ return totalCount() - visibleCount();
+ });
+
return (
- <For each={props.recipients}>
- {(recipient, index) => (
- <Tooltip
- tooltip={
- <div class="text-xs select-text cursor-text">
- {recipient.data.email}
- </div>
- }
- class="inline"
- >
- <span>
- {getRecipientDisplayName(recipient) +
- (index() < props.recipients.length - 1 || props.showTrailingComma
- ? ', '
- : '')}
- &emsp;
- </span>
- </Tooltip>
- )}
- </For>
+ <div
+ use:observedSize={{ setSize: setContainerRect }}
+ class="flex items-center text-sm font-mono overflow-hidden whitespace-nowrap mt-1 min-w-0 flex-1 cursor-pointer"
+ onclick={props.onClick}
+ >
+ {/* Hidden measurement element - must have same font styles */}
+ <span
+ ref={measureRef}
+ class="absolute invisible whitespace-nowrap text-sm font-mono"
+ aria-hidden="true"
+ />
+
+ <Show
+ when={totalCount() > 0}
+ fallback={<span class="text-failure-ink">Recipients required</span>}
+ >
+ <For each={visibleRecipients()}>
+ {(item, index) => (
+ <>
+ <Tooltip
+ tooltip={
+ <div class="text-xs select-text cursor-text">
+ {item.recipient.data.email}
+ </div>
+ }
+ class="inline shrink-0"
+ >
+ <span class="shrink-0">
+ {item.prefix}
+ {getRecipientDisplayName(item.recipient)}
+ </span>
+ </Tooltip>
+ <Show
+ when={
+ index() < visibleRecipients().length - 1 || hiddenCount() > 0
+ }
+ >
+ <span>{RECIPIENT_SEPARATOR}</span>
+ </Show>
+ </>
+ )}
+ </For>
+ <Show when={hiddenCount() > 0}>
+ <span class="text-ink-muted shrink-0">+{hiddenCount()} more</span>
+ </Show>
+ </Show>
+ </div>
);
}
@@ -809,45 +949,12 @@ export function BaseInput(props: {
<Show
when={showExpandedRecipients()}
fallback={
- <div
- class="flex flex-wrap items-center text-sm font-mono truncate overflow-hidden mt-1"
- onclick={() => setShowExpandedRecipients(true)}
- >
- <Show
- when={
- form().recipients().to.length +
- form().recipients().cc.length +
- form().recipients().bcc.length >
- 0
- }
- fallback={
- <span class="text-failure-ink">Recipients required</span>
- }
- >
- <Show
- when={
- form().recipients().to.length +
- form().recipients().cc.length >
- 0
- }
- >
- <span>to&nbsp;</span>
- </Show>
- <RecipientList
- recipients={form().recipients().to}
- showTrailingComma={form().recipients().cc.length > 0}
- />
- <RecipientList
- recipients={form().recipients().cc}
- showTrailingComma={false}
- />
- <Show when={form().recipients().bcc.length > 0}>, bcc: </Show>
- <RecipientList
- recipients={form().recipients().bcc}
- showTrailingComma={false}
- />
- </Show>
- </div>
+ <TruncatedRecipientList
+ toRecipients={form().recipients().to}
+ ccRecipients={form().recipients().cc}
+ bccRecipients={form().recipients().bcc}
+ onClick={() => setShowExpandedRecipients(true)}
+ />
}
>
<div ref={setExpandedRecipientsRef} class="w-full">