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(new-channels): reaction ordering + tooltip (#2192)

teo467f9cbaed8f
diff --git a/js/app/packages/channel/Message/ReactionChip.tsx b/js/app/packages/channel/Message/ReactionChip.tsx
index dd38ab3eb5..720f9f3698 100644
--- a/js/app/packages/channel/Message/ReactionChip.tsx
+++ b/js/app/packages/channel/Message/ReactionChip.tsx
@@ -1,37 +1,94 @@
+import { Tooltip } from '@core/component/Tooltip';
+import { idToDisplayName } from '@core/user';
import { cn } from '@ui/utils/classname';
-import { Show } from 'solid-js';
+import { type JSX, Show } from 'solid-js';
type ReactionChipProps = {
emoji: string;
count: number;
+ users: string[];
+ currentUserId: string | undefined;
selected?: boolean;
interactive?: boolean;
onClick?: (event: MouseEvent) => void;
};
+/**
+ * Format a list of user display names with Oxford comma style.
+ * Current user ("You") is always listed first regardless of input order.
+ * e.g. "You", "You and Alice", "You, Alice, and Bob"
+ */
+export function formatReactorNames(
+ userIds: string[],
+ currentUserId: string | undefined
+): string {
+ if (userIds.length === 0) return '';
+
+ const ordered = [
+ ...userIds.filter((id) => id === currentUserId),
+ ...userIds.filter((id) => id !== currentUserId),
+ ];
+
+ const names = ordered.map((id) =>
+ id === currentUserId ? 'You' : idToDisplayName(id)
+ );
+
+ if (names.length === 1) return names[0]!;
+ if (names.length === 2) return `${names[0]} and ${names[1]}`;
+
+ const allButLast = names.slice(0, -1);
+ const last = names[names.length - 1];
+ return `${allButLast.join(', ')}, and ${last}`;
+}
+
+function ReactionTooltipContent(props: {
+ users: string[];
+ currentUserId: string | undefined;
+ emoji: string;
+}): JSX.Element {
+ return (
+ <span>
+ {formatReactorNames(props.users, props.currentUserId)} reacted with{' '}
+ <span class="text-md">{props.emoji}</span>
+ </span>
+ );
+}
+
export function ReactionChip(props: ReactionChipProps) {
return (
- <button
- type="button"
- data-message-reaction-chip
- data-emoji={props.emoji}
- class={cn(
- 'flex flex-row items-center gap-2 py-1 px-2 bg-menu border h-8',
- {
- 'text-accent-ink border-accent': props.selected,
- 'border-edge-muted hover:bg-hover hover:scale-105 transition-none hover:transition':
- !props.selected && props.interactive,
- 'border-edge-muted': !props.selected && !props.interactive,
- 'cursor-default': !props.interactive,
- }
- )}
- disabled={!props.interactive}
- onClick={(event) => props.onClick?.(event)}
+ <Tooltip
+ tooltip={
+ <ReactionTooltipContent
+ users={props.users}
+ currentUserId={props.currentUserId}
+ emoji={props.emoji}
+ />
+ }
+ placement="top"
>
- <span class="text-md">{props.emoji}</span>
- <Show when={props.count > 1}>
- <span class="text-xs">{props.count}</span>
- </Show>
- </button>
+ <button
+ type="button"
+ data-message-reaction-chip
+ data-emoji={props.emoji}
+ class={cn(
+ 'flex flex-row items-center gap-2 py-1 px-2 bg-menu border h-8',
+ {
+ 'text-accent-ink border-accent': props.selected,
+ 'border-edge-muted hover:bg-hover hover:scale-105 transition-none hover:transition':
+ !props.selected && props.interactive,
+ 'border-edge-muted': !props.selected && !props.interactive,
+ 'cursor-default': !props.interactive,
+ 'pointer-events-auto': !props.interactive,
+ }
+ )}
+ disabled={!props.interactive}
+ onClick={(event) => props.onClick?.(event)}
+ >
+ <span class="text-md">{props.emoji}</span>
+ <Show when={props.count > 1}>
+ <span class="text-xs">{props.count}</span>
+ </Show>
+ </button>
+ </Tooltip>
);
}
diff --git a/js/app/packages/channel/Message/Reactions.tsx b/js/app/packages/channel/Message/Reactions.tsx
index f7c78204f0..079c3daf88 100644
--- a/js/app/packages/channel/Message/Reactions.tsx
+++ b/js/app/packages/channel/Message/Reactions.tsx
@@ -37,6 +37,8 @@ export function Reactions(props: ReactionsProps) {
<ReactionChip
emoji={reaction.emoji}
count={reaction.users.length}
+ users={reaction.users}
+ currentUserId={userId() ?? undefined}
selected={didCurrentUserReact()}
interactive={canReact()}
onClick={(event) => {
diff --git a/js/app/packages/channel/Message/tests/reactions.test.tsx b/js/app/packages/channel/Message/tests/reactions.test.tsx
index d492f1bc5d..e6ba4b00cb 100644
--- a/js/app/packages/channel/Message/tests/reactions.test.tsx
+++ b/js/app/packages/channel/Message/tests/reactions.test.tsx
@@ -7,12 +7,17 @@ import { render, screen } from '@solidjs/testing-library';
import { describe, expect, it, vi } from 'vitest';
import { Root } from '../Root';
import { Reactions } from '../Reactions';
+import { formatReactorNames } from '../ReactionChip';
import type { MessageData } from '../types';
vi.mock('@core/context/user', () => ({
useUserId: () => () => 'user-1',
}));
+vi.mock('@core/user', () => ({
+ idToDisplayName: (id: string) => id.replace('macro|', ''),
+}));
+
const baseMessage: MessageData = {
id: 'message-1',
content: 'hello',
@@ -61,7 +66,9 @@ describe('Reactions', () => {
</Root>
));
- const chip = screen.getByRole('button', { name: /😂/u });
+ const chip = screen
+ .getAllByRole('button', { name: /😂/u })
+ .find((el) => el.hasAttribute('data-message-reaction-chip'))!;
await user.click(chip);
expect(onReact).toHaveBeenCalledTimes(1);
@@ -69,3 +76,56 @@ describe('Reactions', () => {
expect(onReact.mock.calls[0]?.[0]?.emoji).toBe('😂');
});
});
+
+describe('formatReactorNames', () => {
+ it('returns empty string for empty input', () => {
+ expect(formatReactorNames([], 'user-1')).toBe('');
+ });
+
+ it('shows "You" when only the current user reacted', () => {
+ expect(formatReactorNames(['user-1'], 'user-1')).toBe('You');
+ });
+
+ it('shows the display name for a single other user', () => {
+ expect(formatReactorNames(['macro|[email protected]'], 'user-1')).toBe(
+ );
+ });
+
+ it('joins two users with "and"', () => {
+ expect(
+ formatReactorNames(['user-1', 'macro|[email protected]'], 'user-1')
+ ).toBe('You and [email protected]');
+ });
+
+ it('uses Oxford comma for three or more users', () => {
+ expect(
+ formatReactorNames(
+ ['user-1', 'macro|[email protected]', 'macro|[email protected]'],
+ 'user-1'
+ )
+ ).toBe('You, [email protected], and [email protected]');
+ });
+
+ it('handles no current user match', () => {
+ expect(
+ formatReactorNames(
+ 'other-user'
+ )
+ });
+
+ it('puts current user first regardless of input order', () => {
+ expect(
+ formatReactorNames(['macro|[email protected]', 'user-1'], 'user-1')
+ ).toBe('You and [email protected]');
+
+ expect(
+ formatReactorNames(
+ ['macro|[email protected]', 'macro|[email protected]', 'user-1'],
+ 'user-1'
+ )
+ ).toBe('You, [email protected], and [email protected]');
+ });
+});