Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ import { build } from 'esbuild';
import { resolve } from 'path';
import { reactOnFeedCard } from '../utils/activityFeed';

const PILL_ALIASES = [
'+1',
'-1',
'smile',
'tada',
'thinking_face',
'heart',
'eyes',
'rocket',
];

const bundle = build({
stdin: {
contents: `import React, { useState } from 'react';
Expand Down Expand Up @@ -69,7 +80,7 @@ const bundle = build({
],
}).then((result) => result.outputFiles[0].text);

test('every reaction can be selected and removed through the animated product popover', async ({
test('every reaction can be selected through the animated popover and taken back through its pill', async ({
page,
}) => {
test.setTimeout(60_000);
Expand Down Expand Up @@ -102,9 +113,17 @@ test('every reaction can be selected and removed through the animated product po
await page.addScriptTag({ content: await bundle });
const card = page.getByTestId('card');
await reactOnFeedCard(page, card);
await expect(card.getByTestId('emoji-button')).toHaveCount(8);
await reactOnFeedCard(page, card);
await expect(card.getByTestId('emoji-button')).toHaveCount(0);
const pills = card.getByTestId('emoji-button');
await expect(pills).toHaveCount(8);
await expect(card.getByTestId('add-reactions')).toBeHidden();
for (const alias of PILL_ALIASES) {
const pill = pills.filter({
has: page.locator(`g-emoji[alias="${alias}"]`),
});
await pill.click();
await expect(pill).toBeHidden();
}
await expect(pills).toHaveCount(0);
expect(operations).toEqual([
...[
'thumbsUp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ import classNames from 'classnames';
import { lazy, useCallback, useEffect, useMemo, useRef, useState } from 'react';
import { Link } from 'react-router-dom';
import withSuspenseFallback from '../../../components/AppRouter/withSuspenseFallback';
import {
ReactionOperation,
ReactionsVariant,
} from '../../../enums/reactions.enum';
import { ReactionOperation } from '../../../enums/reactions.enum';
import { EntityReference } from '../../../generated/entity/type';
import { Reaction, ReactionType } from '../../../generated/type/reaction';
import { useUserProfile } from '../../../hooks/user-profile/useUserProfile';
Expand Down Expand Up @@ -276,7 +273,6 @@ const CommentCard = ({
<div className="d-flex items-center gap-2 w-full">
<Reactions
reactions={reactions ?? []}
variant={ReactionsVariant.Pill}
onReactionSelect={onReaction}
/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import { noop } from 'lodash';
import { useCallback } from 'react';
import { PressEvent } from 'react-aria-components';
import { useTranslation } from 'react-i18next';
import {
ReactionOperation,
ReactionsVariant,
} from '../../../../enums/reactions.enum';
import { ReactionOperation } from '../../../../enums/reactions.enum';
import { ActivityEvent } from '../../../../generated/entity/activity/activityEvent';
import { ReactionType } from '../../../../generated/type/reaction';
import { useActivityFeedProvider } from '../../ActivityFeedProvider/ActivityFeedProvider';
Expand Down Expand Up @@ -86,7 +83,6 @@ function ActivityEventFooter({
/>
<Reactions
reactions={activity.reactions ?? []}
variant={ReactionsVariant.Pill}
onReactionSelect={onReactionUpdate ?? noop}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ import {
} from 'react-aria-components';
import { useTranslation } from 'react-i18next';
import { FEED_FOOTER_AVATAR_SIZE } from '../../../../constants/Feeds.constants';
import {
ReactionOperation,
ReactionsVariant,
} from '../../../../enums/reactions.enum';
import { ReactionOperation } from '../../../../enums/reactions.enum';
import { ReactionType } from '../../../../generated/type/reaction';
import UserPopOverCard from '../../../common/PopOverCard/UserPopOverCard';
import ProfilePicture from '../../../common/ProfilePicture/ProfilePicture';
Expand Down Expand Up @@ -157,7 +154,6 @@ function FeedCardFooterNew({
)}
<Reactions
reactions={conversation?.reactions ?? []}
variant={ReactionsVariant.Pill}
onReactionSelect={onReactionUpdate ?? noop}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
*/

import { fireEvent, render, waitFor } from '@testing-library/react';
import { ReactionsVariant } from '../../../enums/reactions.enum';
import { User } from '../../../generated/entity/teams/user';
import { ReactionType } from '../../../generated/type/reaction';
import Emoji from './Emoji';
Expand Down Expand Up @@ -105,9 +104,7 @@ describe('Test Emoji Component', () => {

// The Inbox's pill marks the viewer's own reaction with the brand tint.
it('Should tint the pill the viewer reacted with, and not another', async () => {
const { findByTestId, rerender } = render(
<Emoji {...mockProps} variant={ReactionsVariant.Pill} />
);
const { findByTestId, rerender } = render(<Emoji {...mockProps} />);

expect(await findByTestId('emoji-button')).toHaveClass(
'tw:rounded-full!',
Expand All @@ -123,7 +120,6 @@ describe('Test Emoji Component', () => {
user: { ...mockProps.reactionList[0].user, id: 'someone-else' },
},
]}
variant={ReactionsVariant.Pill}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,28 @@ import classNames from 'classnames';
import { createElement, FC, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { REACTION_LIST } from '../../../constants/reactions.constant';
import {
ReactionOperation,
ReactionsVariant,
} from '../../../enums/reactions.enum';
import { ReactionOperation } from '../../../enums/reactions.enum';
import { Reaction, ReactionType } from '../../../generated/type/reaction';
import { useApplicationStore } from '../../../hooks/useApplicationStore';
import useImage from '../../../hooks/useImage';
import { getEntityName } from '../../../utils/EntityNameUtils';

// How a chip is drawn in each variant: its shape, its colors once the viewer
// has reacted with it, its colors otherwise, and its count.
interface ChipClasses {
shape: string;
reacted: string;
idle: string;
count: string;
}

const CHIP_CLASSES: Record<ReactionsVariant, ChipClasses> = {
[ReactionsVariant.Default]: {
shape: 'tw:h-[22px] tw:rounded-md! tw:px-2! tw:py-0!',
reacted: 'tw:text-brand-secondary tw:after:outline-brand',
idle: 'tw:text-secondary',
count: 'tw:ml-1 tw:text-xs',
},
[ReactionsVariant.Pill]: {
shape:
'tw:h-6.5 tw:rounded-full! tw:px-2! tw:py-0! tw:shadow-none tw:font-semibold tw:hover:after:outline-primary tw:[&_g-emoji]:text-sm',
reacted:
'tw:bg-utility-brand-50 tw:hover:bg-utility-brand-50 tw:text-utility-brand-700 tw:hover:text-utility-brand-700 tw:after:outline-utility-brand-300',
idle: 'tw:bg-primary tw:text-tertiary tw:hover:text-tertiary tw:after:outline-secondary',
// The chip wraps emoji and count in one text span, so its gap never
// reaches between them.
count: 'tw:ml-1.25 tw:text-xs',
},
// How a chip is drawn: its shape, its colors once the viewer has reacted with
// it, its colors otherwise, and its count.
const CHIP_CLASSES = {
shape:
'tw:h-6.5 tw:rounded-full! tw:px-2! tw:py-0! tw:shadow-none tw:font-semibold tw:hover:after:outline-primary tw:[&_g-emoji]:text-sm',
reacted:
'tw:bg-utility-brand-50 tw:hover:bg-utility-brand-50 tw:text-utility-brand-700 tw:hover:text-utility-brand-700 tw:after:outline-utility-brand-300',
idle: 'tw:bg-primary tw:text-tertiary tw:hover:text-tertiary tw:after:outline-secondary',
// The chip wraps emoji and count in one text span, so its gap never
// reaches between them.
count: 'tw:ml-1.25 tw:text-xs',
};

interface EmojiProps {
reaction: ReactionType;
reactionList: Reaction[];
variant?: ReactionsVariant;
onReactionSelect: (
reaction: ReactionType,
operation: ReactionOperation
Expand All @@ -67,7 +48,6 @@ interface EmojiProps {
const Emoji: FC<EmojiProps> = ({
reaction,
reactionList,
variant = ReactionsVariant.Default,
onReactionSelect,
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -143,16 +123,16 @@ const Emoji: FC<EmojiProps> = ({
<Button
className={classNames(
'tw:gap-1',
CHIP_CLASSES[variant].shape,
isReacted ? CHIP_CLASSES[variant].reacted : CHIP_CLASSES[variant].idle
CHIP_CLASSES.shape,
isReacted ? CHIP_CLASSES.reacted : CHIP_CLASSES.idle
)}
color="secondary"
data-testid="emoji-button"
isDisabled={isUpdating}
size="xs"
onClick={handleEmojiOnClick}>
{element}
<span className={CHIP_CLASSES[variant].count} data-testid="emoji-count">
<span className={CHIP_CLASSES.count} data-testid="emoji-count">
{reactionList.length.toLocaleString('en-US', {
useGrouping: false,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import { fireEvent, render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { ReactionsVariant } from '../../../enums/reactions.enum';
import { ReactionType } from '../../../generated/type/reaction';
import Reactions from './Reactions';

Expand Down Expand Up @@ -129,20 +128,11 @@ describe('Text Reactions component', () => {

it('drops the pills tray once the viewer has picked every reaction', () => {
mockCurrentUserId = REACTOR_ID;
const { queryByTestId } = render(
<Reactions {...mockProps} variant={ReactionsVariant.Pill} />
);
const { queryByTestId } = render(<Reactions {...mockProps} />);

expect(queryByTestId('add-reactions')).not.toBeInTheDocument();
});

it('keeps the classic tray, to take a reaction back', () => {
mockCurrentUserId = REACTOR_ID;
const { getByTestId } = render(<Reactions {...mockProps} />);

expect(getByTestId('add-reactions')).toBeInTheDocument();
});

// The Inbox shows the thumbs up as its Like, outside the pills.
it('marks a reaction picked outside the pills, and takes it back', async () => {
const { findByTestId, getByRole, queryAllByTestId } = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ import {
Popover,
PopoverTrigger,
} from '@openmetadata/ui-core-components';
import {
FaceSmile,
Reactions as AddReactionIcon,
} from '@openmetadata/ui-core-components/icons';
import classNames from 'classnames';
import { FaceSmile } from '@openmetadata/ui-core-components/icons';
import { groupBy } from 'lodash';
import { FC, MouseEvent, useState } from 'react';
import { useTranslation } from 'react-i18next';
import {
REACTION_LIST,
REACTION_TYPE_LIST,
} from '../../../constants/reactions.constant';
import {
ReactionOperation,
ReactionsVariant,
} from '../../../enums/reactions.enum';
import { ReactionOperation } from '../../../enums/reactions.enum';
import {
Reaction as ReactionProp,
ReactionType,
Expand All @@ -41,8 +34,6 @@ import { useApplicationStore } from '../../../hooks/useApplicationStore';
import Emoji from './Emoji';
import Reaction from './Reaction';

const isPill = (variant: ReactionsVariant) => variant === ReactionsVariant.Pill;

interface ReactionsProps {
reactions: ReactionProp[];
/**
Expand All @@ -51,7 +42,6 @@ interface ReactionsProps {
* read as picked, and be taken back, in the tray.
*/
pickedReactions?: ReactionProp[];
variant?: ReactionsVariant;
onReactionSelect: (
reaction: ReactionType,
operation: ReactionOperation
Expand All @@ -61,7 +51,6 @@ interface ReactionsProps {
const Reactions: FC<ReactionsProps> = ({
reactions,
pickedReactions = reactions,
variant = ReactionsVariant.Default,
onReactionSelect,
}) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -98,12 +87,11 @@ const Reactions: FC<ReactionsProps> = ({
);
});

// The Inbox's pills drop the tray once every reaction is picked: there is
// nothing left to add, and each pill takes its own back. The classic feed
// keeps it, as the way it takes a reaction back.
const canAddReaction =
!isPill(variant) ||
REACTION_LIST.some(({ reaction }) => !isReacted(reaction));
// The tray goes once every reaction is picked: there is nothing left to add,
// and each pill takes its own back.
const canAddReaction = REACTION_LIST.some(
({ reaction }) => !isReacted(reaction)
);

// prepare dictionary for each emojis and corresponding users list
const modifiedReactionObject = groupBy(reactions, 'reactionType');
Expand All @@ -118,7 +106,6 @@ const Reactions: FC<ReactionsProps> = ({
key={reaction}
reaction={reaction}
reactionList={reactionListValue}
variant={variant}
onReactionSelect={onReactionSelect}
/>
)
Expand All @@ -131,23 +118,17 @@ const Reactions: FC<ReactionsProps> = ({

return (
<div
className={classNames(
'tw:inline-flex tw:items-center',
// Many reactions wrap onto a second row rather than past the card.
isPill(variant) ? 'tw:flex-wrap tw:gap-1.5' : 'tw:gap-2'
)}
// Many reactions wrap onto a second row rather than past the card.
className="tw:inline-flex tw:flex-wrap tw:items-center tw:gap-1.5"
data-testid="feed-reaction-container">
{emojis}
{canAddReaction && (
<PopoverTrigger isOpen={visible} onOpenChange={setVisible}>
<ButtonUtility
// The pill matches the reaction chips beside it.
className={classNames({
'tw:h-6.5 tw:w-7 tw:rounded-full! tw:p-1! tw:*:data-icon:size-4 tw:*:data-icon:text-fg-secondary tw:hover:*:data-icon:text-fg-secondary_hover':
isPill(variant),
})}
className="tw:h-6.5 tw:w-7 tw:rounded-full! tw:p-1! tw:*:data-icon:size-4 tw:*:data-icon:text-fg-secondary tw:hover:*:data-icon:text-fg-secondary_hover"
data-testid="add-reactions"
icon={isPill(variant) ? FaceSmile : AddReactionIcon}
icon={FaceSmile}
size="sm"
tooltip={addReactionLabel}
onClick={(e: MouseEvent) => e.stopPropagation()}
Expand Down
Loading
Loading