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.

fea: add user icon tool tip to email participant in soup (#1728)

gbirman030ef3f28523
diff --git a/js/app/packages/entity/src/extractors/entity-email-participants.tsx b/js/app/packages/entity/src/extractors/entity-email-participants.tsx
index cf4c5d590a..d4c97aee49 100644
--- a/js/app/packages/entity/src/extractors/entity-email-participants.tsx
+++ b/js/app/packages/entity/src/extractors/entity-email-participants.tsx
@@ -2,13 +2,17 @@ import { useEmail } from '@core/context/user';
import { emailToMacroId, useDisplayName } from '@core/user';
import { StaticMarkdown } from '@core/component/LexicalMarkdown/component/core/StaticMarkdown';
import { unifiedListMarkdownTheme } from '@core/component/LexicalMarkdown/theme';
+import { toast } from '@core/component/Toast/Toast';
+import { Tooltip } from '@core/component/Tooltip';
+import { UserTooltip } from '@core/component/UserTooltip';
import {
mergeAdjacentMacroEmTags,
highlightTermsInText,
} from '@core/util/searchHighlight';
+import WideCopy from '@macro-icons/wide/copy.svg';
import type { EmailEntity, EmailThreadParticipants } from '../types/entity';
import { isSearchEntity } from '../types/search';
-import { Show } from 'solid-js';
+import { For, Show } from 'solid-js';
/** Checks if a value is likely an email address */
export function isLikelyEmail(value?: string): boolean {
@@ -38,62 +42,132 @@ export function resolveParticipantName(
return getEmailLocalPart(participant.email);
}
+type ResolvedParticipant = {
+ participant: EmailThreadParticipants[number];
+ displayName: string;
+};
+
+function ParticipantWithTooltip(props: {
+ participant: EmailThreadParticipants[number];
+ displayName: string;
+ highlighted?: string;
+}) {
+ const macroId = () => emailToMacroId(props.participant.email);
+ const [macroDisplayName] = useDisplayName(macroId());
+ const tooltipName = () =>
+ resolveParticipantName(props.participant, macroDisplayName());
+
+ return (
+ <Tooltip
+ unstyled
+ spanMode
+ tooltip={
+ <UserTooltip
+ displayName={tooltipName()}
+ email={props.participant.email}
+ id={macroId()}
+ />
+ }
+ >
+ <Show
+ when={props.highlighted}
+ fallback={<span>{props.displayName}</span>}
+ >
+ {(md) => (
+ <StaticMarkdown
+ markdown={md()}
+ theme={unifiedListMarkdownTheme}
+ singleLine
+ />
+ )}
+ </Show>
+ </Tooltip>
+ );
+}
+
/**
- * Combines participant names into a list, handling the "me" case
- * Returns an array of display names (possibly ["me"] if single participant is userEmail)
+ * Resolves participants into display-ready objects, handling the "me" case
+ * and filtering out the current user.
*/
-export function combineParticipantNames(
+function resolveParticipants(
participants: EmailThreadParticipants | undefined,
userEmail: string | undefined,
getMacroDisplayName: (email: string) => string | undefined
-): string[] {
- if (!participants || participants.length === 0) {
- return [];
- }
+): ResolvedParticipant[] {
+ if (!participants || participants.length === 0) return [];
if (
participants.length === 1 &&
userEmail &&
participants[0].email === userEmail
) {
- return ['me'];
+ return [{ participant: participants[0], displayName: 'me' }];
}
- const namesSet = new Set<string>();
+ const seen = new Set<string>();
+ const result: ResolvedParticipant[] = [];
for (const participant of participants) {
if (!participant.email) continue;
-
if (userEmail && participant.email === userEmail) continue;
const macroDisplayName = getMacroDisplayName(participant.email);
const displayName = resolveParticipantName(participant, macroDisplayName);
- namesSet.add(displayName);
+ if (seen.has(displayName)) continue;
+ seen.add(displayName);
+
+ result.push({ participant, displayName });
}
- return Array.from(namesSet);
+ return result;
}
-/**
- * Formats display names into a string suitable for UI display
- * - Single name: returns as-is
- * - 2-3 names: comma-separated with first names only
- * - 4+ names: "First .. SecondLast, Last" format with first names
- */
-export function formatDisplayNames(names: string[]): string | undefined {
- if (!names || names.length === 0) return undefined;
- if (names.length === 1) return names[0];
+function abbreviateParticipants(
+ resolved: ResolvedParticipant[]
+): ResolvedParticipant[] {
+ if (resolved.length <= 1) return resolved;
- // For multiple participants, use first names only
- const firstNames = names.map((name) => name.split(' ')[0]);
+ const abbreviated = resolved.map((r) => ({
+ ...r,
+ displayName: r.displayName.split(' ')[0],
+ }));
- if (firstNames.length <= 3) {
- return firstNames.join(', ');
- }
+ if (abbreviated.length <= 3) return abbreviated;
- // For 4+ participants: "First .. SecondLast, Last"
- return `${firstNames[0]} .. ${firstNames[firstNames.length - 2]}, ${firstNames[firstNames.length - 1]}`;
+ return [abbreviated[0], abbreviated[1]];
+}
+
+function copyEmail(email: string, e: MouseEvent) {
+ e.stopPropagation();
+ navigator.clipboard.writeText(email);
+ toast.success('Email copied');
+}
+
+function HiddenParticipantsTooltip(props: { hidden: ResolvedParticipant[] }) {
+ return (
+ <Tooltip
+ spanMode
+ unstyled
+ tooltip={
+ <div class="bg-panel text-ink border border-edge/20 py-1">
+ <For each={props.hidden}>
+ {(r) => (
+ <div
+ class="flex items-center gap-2 px-2 py-1 text-xs hover:bg-hover"
+ onClick={[copyEmail, r.participant.email]}
+ >
+ <span class="truncate">{r.participant.email}</span>
+ <WideCopy class="w-3 h-3 shrink-0 opacity-60" />
+ </div>
+ )}
+ </For>
+ </div>
+ }
+ >
+ <span class="opacity-60">+{props.hidden.length}</span>
+ </Tooltip>
+ );
}
/** Get a nicely formatted list of participants from an email entity. */
@@ -102,35 +176,57 @@ export function EntityEmailParticipants(props: { entity: EmailEntity }) {
const fetchDisplayName = (email: string) =>
useDisplayName(emailToMacroId(email))[0]();
- const displayNames = () => {
- return formatDisplayNames(
- combineParticipantNames(
+ const participants = () =>
+ abbreviateParticipants(
+ resolveParticipants(
props.entity.participants,
userEmail(),
fetchDisplayName
)
);
+
+ const allResolved = () =>
+ resolveParticipants(
+ props.entity.participants,
+ userEmail(),
+ fetchDisplayName
+ );
+
+ const hiddenParticipants = () => {
+ const all = allResolved();
+ return all.length > 3 ? all.slice(2) : [];
};
- const highlighted = () => {
+ const searchTerms = () => {
if (!isSearchEntity(props.entity)) return undefined;
- const terms = props.entity.search.senderHighlightTerms;
+ return props.entity.search.senderHighlightTerms;
+ };
+
+ const highlightName = (name: string) => {
+ const terms = searchTerms();
if (!terms?.length) return undefined;
- const names = displayNames();
- if (!names) return undefined;
- const result = mergeAdjacentMacroEmTags(highlightTermsInText(names, terms));
- return result !== names ? result : undefined;
+ const result = mergeAdjacentMacroEmTags(highlightTermsInText(name, terms));
+ return result !== name ? result : undefined;
};
return (
- <Show when={highlighted()} fallback={displayNames()}>
- {(md) => (
- <StaticMarkdown
- markdown={md()}
- theme={unifiedListMarkdownTheme}
- singleLine
- />
- )}
- </Show>
+ <>
+ <For each={participants()}>
+ {(resolved, index) => (
+ <>
+ <Show when={index() > 0}>, </Show>
+ <ParticipantWithTooltip
+ participant={resolved.participant}
+ displayName={resolved.displayName}
+ highlighted={highlightName(resolved.displayName)}
+ />
+ </>
+ )}
+ </For>
+ <Show when={hiddenParticipants().length > 0}>
+ {''}
+ <HiddenParticipantsTooltip hidden={hiddenParticipants()} />
+ </Show>
+ </>
);
}