Skip to content

Commit 52b0b59

Browse files
fix: extended reactions button visibility adjustments in MessageReactionsDetail (#3186)
### 🎯 Goal Ref: #3172 Ref: https://getstream.slack.com/archives/C0A4UPTFNJU/p1778568564498769?thread_ts=1778176423.200169&cid=C0A4UPTFNJU
1 parent e120e42 commit 52b0b59

4 files changed

Lines changed: 63 additions & 22 deletions

File tree

src/components/Reactions/MessageReactionsDetail.tsx

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
useTranslationContext,
1313
} from '../../context';
1414
import type { ReactionSort } from 'stream-chat';
15-
import { defaultReactionOptions } from './reactionOptions';
15+
import { defaultReactionOptions, getHasExtendedReactions } from './reactionOptions';
1616
import type { useProcessReactions } from './hooks/useProcessReactions';
1717
import { IconEmojiAdd } from '../Icons';
1818
import { ReactionSelector, type ReactionSelectorProps } from './ReactionSelector';
@@ -81,6 +81,8 @@ export const MessageReactionsDetail: MessageReactionsDetailInterface = ({
8181
const reactionDetailsSort =
8282
propReactionDetailsSort ?? contextReactionDetailsSort ?? defaultReactionDetailsSort;
8383

84+
const hasExtendedReactions = getHasExtendedReactions(reactionOptions);
85+
8486
const {
8587
isLoading: areReactionsLoading,
8688
reactions: reactionDetails,
@@ -137,19 +139,21 @@ export const MessageReactionsDetail: MessageReactionsDetailInterface = ({
137139
className='str-chat__message-reactions-detail__reaction-type-list'
138140
data-testid='reaction-type-list'
139141
>
140-
<li className='str-chat__message-reactions-detail__reaction-type-list-item'>
141-
<button
142-
aria-label={t('Add reaction')}
143-
className='str-chat__message-reactions-detail__reaction-type-list-item-button'
144-
data-testid='add-reaction-button'
145-
onClick={() => setExtendedReactionListOpen(true)}
146-
type='button'
147-
>
148-
<span className='str-chat__message-reactions-detail__reaction-type-list-item-icon'>
149-
<IconEmojiAdd />
150-
</span>
151-
</button>
152-
</li>
142+
{hasExtendedReactions && (
143+
<li className='str-chat__message-reactions-detail__reaction-type-list-item'>
144+
<button
145+
aria-label={t('Add reaction')}
146+
className='str-chat__message-reactions-detail__reaction-type-list-item-button'
147+
data-testid='add-reaction-button'
148+
onClick={() => setExtendedReactionListOpen(true)}
149+
type='button'
150+
>
151+
<span className='str-chat__message-reactions-detail__reaction-type-list-item-icon'>
152+
<IconEmojiAdd />
153+
</span>
154+
</button>
155+
</li>
156+
)}
153157

154158
{reactions.map(
155159
({ EmojiComponent, reactionCount, reactionType }) =>

src/components/Reactions/ReactionSelector.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { type ReactNode, useMemo, useState } from 'react';
22
import clsx from 'clsx';
33

44
import { useDialogOnNearestManager } from '../Dialog';
5-
import { defaultReactionOptions } from './reactionOptions';
5+
import { defaultReactionOptions, getHasExtendedReactions } from './reactionOptions';
66
import { useComponentContext } from '../../context/ComponentContext';
77
import { useMessageContext } from '../../context/MessageContext';
88
import { useTranslationContext } from '../../context/TranslationContext';
@@ -86,10 +86,7 @@ export const ReactionSelector: ReactionSelectorInterface = (props) => {
8686
);
8787
}, [reactionOptions]);
8888

89-
const hasExtendedReactions =
90-
!Array.isArray(reactionOptions) &&
91-
reactionOptions.extended &&
92-
Object.keys(reactionOptions.extended).length > 0;
89+
const hasExtendedReactions = getHasExtendedReactions(reactionOptions);
9390

9491
return (
9592
<div

src/components/Reactions/__tests__/MessageReactionsDetail.test.tsx

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -315,20 +315,55 @@ describe('MessageReactionsDetail', () => {
315315
expect(counts[1]).toHaveTextContent('3');
316316
});
317317

318-
it('should render add emoji button in the reaction type list', () => {
318+
it('should render add emoji button when extended reactions are available', () => {
319319
const reactionGroups = {
320320
love: { count: 2 },
321321
};
322322
const reactions = generateReactionsFromReactionGroups(reactionGroups);
323323
const fetchReactions = vi.fn(() => Promise.resolve([]));
324324

325-
const { getByTestId } = renderComponent({
325+
const extendedReactionOptions: ReactionOptions = {
326+
extended: {
327+
rocket: { Component: () => <>🚀</>, name: 'Rocket' },
328+
},
329+
quick: {
330+
love: { Component: () => <>❤️</>, name: 'Heart' },
331+
},
332+
};
333+
334+
const { getByTestId } = render(
335+
<ChatProvider value={mockChatContext({ client: chatClient })}>
336+
<DialogManagerProvider>
337+
<WithComponents overrides={{ reactionOptions: extendedReactionOptions }}>
338+
<MessageProvider value={mockMessageContext()}>
339+
<MessageReactionsDetailWrapper
340+
handleFetchReactions={fetchReactions}
341+
reaction_groups={reactionGroups}
342+
reactions={reactions}
343+
/>
344+
</MessageProvider>
345+
</WithComponents>
346+
</DialogManagerProvider>
347+
</ChatProvider>,
348+
);
349+
350+
expect(getByTestId('add-reaction-button')).toBeInTheDocument();
351+
});
352+
353+
it('should not render add emoji button when no extended reactions are available', () => {
354+
const reactionGroups = {
355+
love: { count: 2 },
356+
};
357+
const reactions = generateReactionsFromReactionGroups(reactionGroups);
358+
const fetchReactions = vi.fn(() => Promise.resolve([]));
359+
360+
const { queryByTestId } = renderComponent({
326361
handleFetchReactions: fetchReactions,
327362
reaction_groups: reactionGroups,
328363
reactions,
329364
});
330365

331-
expect(getByTestId('add-reaction-button')).toBeInTheDocument();
366+
expect(queryByTestId('add-reaction-button')).not.toBeInTheDocument();
332367
});
333368

334369
it('should show extended reaction list when add emoji button is clicked', () => {

src/components/Reactions/reactionOptions.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,8 @@ export const defaultReactionOptions: ReactionOptions = {
106106
},
107107
},
108108
};
109+
110+
export const getHasExtendedReactions = (reactionOptions: ReactionOptions) =>
111+
!Array.isArray(reactionOptions) &&
112+
typeof reactionOptions.extended !== 'undefined' &&
113+
Object.keys(reactionOptions.extended).length > 0;

0 commit comments

Comments
 (0)