Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ConversationSource,
} from '../../../generated/entity/feed/conversation';
import { ReactionType } from '../../../generated/type/reaction';
import UserPopOverCard from '../../common/PopOverCard/UserPopOverCard';
import ActivityFeedCardNew from './ActivityFeedcardNew.component';

const mockProviderValue = {
Expand Down Expand Up @@ -216,6 +217,39 @@ describe('ActivityFeedCardNew', () => {
);
});

it.each([
['user', 'bob'],
['team', 'Data Platform'],
])(
'opens the linked %s profile, not the author, from a conversation about it',
(entityType, name) => {
render(
<MemoryRouter>
<ActivityFeedCardNew
feed={{
...conversation,
about: `<#E::${entityType}::${name}>`,
entityRef: {
id: `${entityType}-id`,
type: entityType,
name,
fullyQualifiedName: name,
},
}}
/>
</MemoryRouter>
);

const entityLinkPopover = (UserPopOverCard as jest.Mock).mock.calls
.map(([props]) => props)
.find((props) => props.showUserName && !props.showUserProfile);

expect(entityLinkPopover).toEqual(
expect.objectContaining({ type: entityType, userName: name })
);
}
);

it('names the field a conversation was started on after the entity', () => {
render(
<MemoryRouter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
import withSuspenseFallback from '../../../components/AppRouter/withSuspenseFallback';
import { EntityType } from '../../../enums/entity.enum';
import { OwnerType } from '../../../enums/user.enum';
import { ActivityEvent } from '../../../generated/entity/activity/activityEvent';
import {
Conversation,
Expand Down Expand Up @@ -112,6 +113,9 @@ const getFeedCardWrapperClassName = (
{ 'active-card is-active': isActive }
);

const getLinkedOwnerType = (entityType: EntityType): OwnerType =>
entityType === EntityType.TEAM ? OwnerType.TEAM : OwnerType.USER;

interface ThreadPanelEntityLinkProps {
about: string;
entityFQN: string;
Expand Down Expand Up @@ -302,7 +306,8 @@ const ActivityFeedCardNew = ({
<UserPopOverCard
showUserName
showUserProfile={false}
userName={createdBy}>
type={getLinkedOwnerType(entityType)}
userName={entityFQN}>
<Link
className="break-all text-body header-link"
data-testid="entity-link"
Expand Down Expand Up @@ -396,7 +401,6 @@ const ActivityFeedCardNew = ({
isActivityEvent,
isUserOrTeam,
entityRef,
createdBy,
isPanelLayout,
isThreadPanel,
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
* limitations under the License.
*/
import { fireEvent, render, screen } from '@testing-library/react';
import {
ActivityEvent,
ActivityEventType,
} from '../../../generated/entity/activity/activityEvent';
import {
Conversation,
ConversationSource,
Expand Down Expand Up @@ -40,7 +44,30 @@ const conversation: Conversation = {
updatedAt: 1,
};

const activity: ActivityEvent = {
entity: { id: 'table-id', type: 'table', name: 'table' },
eventType: ActivityEventType.DescriptionUpdated,
id: 'activity-1',
summary: 'Description updated',
timestamp: 1,
};

describe('FeedPanelBodyV1New', () => {
it.each([
['a conversation', { feed: conversation }],
['an activity', { activity }],
])(
'renders a plain card, not a focusable button, for %s nobody handles a press on',
(_, props) => {
render(<FeedPanelBodyV1New {...props} />);

const card = screen.getByTestId('message-container');

expect(card).not.toHaveAttribute('role');
expect(card).not.toHaveAttribute('tabindex');
}
);

it('opens the conversation from a click anywhere on the card', () => {
const onFeedClick = jest.fn();
render(
Expand All @@ -57,6 +84,27 @@ describe('FeedPanelBodyV1New', () => {
expect(onFeedClick).toHaveBeenCalledWith(conversation);
});

it('opens the activity from a click or Enter/Space on the card', () => {
const onActivityClick = jest.fn();
render(
<FeedPanelBodyV1New
activity={activity}
onActivityClick={onActivityClick}
/>
);
const card = screen.getByTestId('message-container');

expect(card).toHaveAttribute('role', 'button');
expect(card).toHaveAttribute('tabindex', '0');

fireEvent.click(screen.getByTestId('card-content'));
fireEvent.keyDown(card, { key: 'Enter' });
fireEvent.keyDown(card, { key: ' ' });

expect(onActivityClick).toHaveBeenCalledTimes(3);
expect(onActivityClick).toHaveBeenCalledWith(activity);
});

it('opens the conversation only from Reply in the thread panel', () => {
const onFeedClick = jest.fn();
render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*/

import { Card } from '@openmetadata/ui-core-components';
import classNames from 'classnames';
import { isUndefined } from 'lodash';
import { FC, useCallback } from 'react';
import ActivityFeedCardNew from '../ActivityFeedCardNew/ActivityFeedcardNew.component';
Expand All @@ -22,6 +23,21 @@ import {
import './feed-panel-body-v1.less';
import { FeedPanelBodyPropV1 } from './FeedPanelBodyV1.interface';

// The card is a button only when someone handles its press.
const getCardContainerProps = (onActivate?: () => void) => ({
className: classNames(
'activity-feed-card-container',
CARD_CONTAINER_CLASS_NAME,
{ 'tw:cursor-pointer': onActivate }
),
...(onActivate && {
role: 'button',
tabIndex: 0,
onClick: onActivate,
onKeyDown: handleCardContainerKeyDown(onActivate),
}),
});

const FeedPanelBodyV1: FC<FeedPanelBodyPropV1> = ({
feed,
activity,
Expand Down Expand Up @@ -51,13 +67,11 @@ const FeedPanelBodyV1: FC<FeedPanelBodyPropV1> = ({
if (isActivityEvent) {
return (
<Card
className={`activity-feed-card-container tw:cursor-pointer ${CARD_CONTAINER_CLASS_NAME}`}
data-testid="message-container"
role="button"
tabIndex={0}
variant="ghost"
onClick={handleActivityClick}
onKeyDown={handleCardContainerKeyDown(handleActivityClick)}>
{...getCardContainerProps(
onActivityClick ? handleActivityClick : undefined
)}>
Comment thread
harsh-vador marked this conversation as resolved.
Resolved
<ActivityFeedCardNew
activity={activity}
isActive={isActive}
Expand Down Expand Up @@ -96,13 +110,9 @@ const FeedPanelBodyV1: FC<FeedPanelBodyPropV1> = ({

return (
<Card
className={`activity-feed-card-container tw:cursor-pointer ${CARD_CONTAINER_CLASS_NAME}`}
data-testid="message-container"
role="button"
tabIndex={0}
variant="ghost"
onClick={handleFeedClick}
onKeyDown={handleCardContainerKeyDown(handleFeedClick)}>
{...getCardContainerProps(onFeedClick ? handleFeedClick : undefined)}>
<ActivityFeedCardNew
feed={feed}
isActive={isActive}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
isRecognizerFeedbackTask,
isTagsTaskType,
} from '../../../utils/TaskActionUtils';
import { showSuccessToast } from '../../../utils/ToastUtils';
import { useActivityFeedProvider } from '../ActivityFeedProvider/ActivityFeedProvider';
import TaskFeedCardFromTask from './TaskFeedCardFromTask.component';

Expand Down Expand Up @@ -176,6 +177,11 @@ jest.mock('../../../utils/TaskActionUtils', () => ({
isRecognizerFeedbackTask: jest.fn().mockReturnValue(false),
}));

jest.mock('../../../utils/ToastUtils', () => ({
showErrorToast: jest.fn(),
showSuccessToast: jest.fn(),
}));

jest.mock('../../../utils/TaskNavigationUtils', () => ({
...jest.requireActual('../../../utils/TaskNavigationUtils'),
getTaskDetailPathFromTask: jest.fn().mockReturnValue('/tasks/1'),
Expand Down Expand Up @@ -366,6 +372,34 @@ describe('TaskFeedCardFromTask', () => {
expect(screen.queryByTestId('approve-button')).not.toBeInTheDocument();
});

it('tells the voter their vote is recorded while the task waits for other approvers', async () => {
const assignedTask: Task = {
...MOCK_TASK,
assignees: [
{
id: 'current-user-id',
type: 'user',
name: 'current-user',
},
],
};
(resolveTask as jest.Mock).mockResolvedValueOnce(assignedTask);

await act(async () => {
render(<TaskFeedCardFromTask task={assignedTask} />, {
wrapper: MemoryRouter,
});
});

fireEvent.click(screen.getByTestId('approve-button'));

await waitFor(() =>
expect(showSuccessToast).toHaveBeenCalledWith(
'message.vote-recorded-waiting-for-other-approvers'
)
);
});

it('approves and rejects an assigned task through the Task V2 API', async () => {
const assignedTask: Task = {
...MOCK_TASK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
import { useAuth } from '../../../hooks/authHooks';
import { useApplicationStore } from '../../../hooks/useApplicationStore';
import { useUserProfile } from '../../../hooks/user-profile/useUserProfile';
import DescriptionTaskFromTask from '../../../pages/TasksPage/shared/DescriptionTaskFromTask';

Check warning on line 46 in openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/TaskFeedCard/TaskFeedCardFromTask.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import TagsTaskFromTask from '../../../pages/TasksPage/shared/TagsTaskFromTask';

Check warning on line 47 in openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/TaskFeedCard/TaskFeedCardFromTask.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import {
resolveTask as resolveTaskAPI,
Task,
Expand Down Expand Up @@ -201,7 +201,7 @@
return null;
}, [fieldPath, t]);

const handleTaskLinkClick = () => {

Check warning on line 204 in openmetadata-ui/src/main/resources/ui/src/components/ActivityFeed/TaskFeedCard/TaskFeedCardFromTask.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

The 'handleTaskLinkClick' function makes the dependencies of useMemo Hook (at line 244) change on every render. Move it inside the useMemo callback. Alternatively, wrap the definition of 'handleTaskLinkClick' in its own useCallback() Hook
navigate(getTaskDetailPathFromTask(task));
setActiveTask(task);
};
Expand Down Expand Up @@ -293,7 +293,7 @@
);
showSuccessToast(
isTaskPendingFurtherApproval(updatedTask)
? 'Vote recorded.'
? t('message.vote-recorded-waiting-for-other-approvers')
: t('server.task-resolved-successfully')
);
onAfterClose?.();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,11 @@ jest.mock(
);

const mockShowErrorToast = jest.fn();
const mockShowSuccessToast = jest.fn();
jest.mock('../../../../utils/ToastUtils', () => ({
...jest.requireActual('../../../../utils/ToastUtils'),
showErrorToast: (...args: unknown[]) => mockShowErrorToast(...args),
showSuccessToast: (...args: unknown[]) => mockShowSuccessToast(...args),
}));

jest.mock('../../../../rest/tasksAPI', () => ({
Expand Down Expand Up @@ -1544,6 +1546,10 @@ describe('TaskTabNew Component', () => {
},
});
});

expect(mockShowSuccessToast).toHaveBeenCalledWith(
'message.vote-recorded-waiting-for-other-approvers'
);
});

it('keeps workflow-driven tasks actionable outside the Open status', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@
import { AccessType } from '../../../../generated/type/dataAccessRequestPayload';
import { useAuth } from '../../../../hooks/authHooks';
import { useApplicationStore } from '../../../../hooks/useApplicationStore';
import Assignees from '../../../../pages/TasksPage/shared/Assignees';

Check warning on line 74 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
import {

Check warning on line 75 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

Pages are route-level composition modules. Move the shared implementation/type to a lower layer instead of importing a page from here
Option,
TaskAction,
TaskActionMode,
Expand Down Expand Up @@ -754,7 +754,7 @@
}
};

const updateTaskData = async (

Check warning on line 757 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

The 'updateTaskData' function makes the dependencies of useCallback Hook (at line 865) change on every render. To fix this, wrap the definition of 'updateTaskData' in its own useCallback() Hook
data: { newValue?: string; payload?: TaskPayload; comment?: string },
resolutionType?: TaskResolutionType,
transitionId?: string
Expand All @@ -776,7 +776,7 @@
const taskRemainsOpen = isTaskPendingFurtherApproval(updatedTask);
showSuccessToast(
taskRemainsOpen
? 'Vote recorded.'
? t('message.vote-recorded-waiting-for-other-approvers')
: t('server.task-resolved-successfully')
);

Expand Down Expand Up @@ -1350,7 +1350,7 @@
</Tooltip>
</Box>
);
}, [

Check warning on line 1353 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

React Hook useMemo has unnecessary dependencies: 'onTaskDropdownClick', 'taskHandler.approvedValue', and 'taskHandler.rejectedValue'. Either exclude them or remove the dependency array
taskAction,
isAssignee,
isCreator,
Expand Down Expand Up @@ -1385,7 +1385,7 @@
/>
</div>
);
}, [

Check warning on line 1388 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

React Hook useMemo has unnecessary dependencies: 'isPartOfAssigneeTeam' and 'task'. Either exclude them or remove the dependency array
task,
isAssignee,
isActionLoading,
Expand Down Expand Up @@ -1448,7 +1448,7 @@
)}
</Box>
);
}, [

Check warning on line 1451 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

React Hook useMemo has unnecessary dependencies: 'onTaskResolve' and 'task'. Either exclude them or remove the dependency array
onTaskClose,
task,
onTaskResolve,
Expand Down Expand Up @@ -1960,7 +1960,7 @@
</div>
</div>
);
}, [changeRequestId, proposedChanges, task, t]);

Check warning on line 1963 in openmetadata-ui/src/main/resources/ui/src/components/Entity/Task/TaskTab/TaskTabNew.component.tsx

View workflow job for this annotation

GitHub Actions / ui / lint

React Hook useMemo has a missing dependency: 'proposedChangesIncomplete'. Either include it or remove the dependency array

const renderFeedbackOrTaskPayload = () => {
if (isOntologyReviewTask(task) && ReviewPanel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1138,7 +1138,7 @@ const GlossaryTermTab = ({ isGlossary, className }: GlossaryTermTabProps) => {

showSuccessToast(
isPendingFurtherApproval
? 'Vote recorded.'
? t('message.vote-recorded')
: t('server.task-resolved-successfully')
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1279,7 +1279,9 @@ describe('Test GlossaryTermTab component', () => {
);
});

expect(mockShowSuccessToast).toHaveBeenCalledWith('Vote recorded.');
expect(mockShowSuccessToast).toHaveBeenCalledWith(
'message.vote-recorded'
);
expect(mockSetGlossaryChildTerms).not.toHaveBeenCalled();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,14 @@ describe('withDomainFilter', () => {
'/activity/entity/table/7f8baaa6-6bf2-4b57-9a16-dcc0a38746b6',
{ days: 30 },
],
[
'/activity/about',
{ entityLink: '<#E::table::svc.db.sch.orders>', days: 30, limit: 200 },
],
[
'/activity/mentions',
{ entityLink: '<#E::table::svc.db.sch.orders>', days: 30, limit: 200 },
],
])("should leave an asset's own activity unscoped (%s)", (url, params) => {
(getPathNameFromWindowLocation as jest.Mock).mockReturnValue(
'/table/svc.db.sch.orders'
Expand Down Expand Up @@ -246,20 +254,23 @@ describe('withDomainFilter', () => {
}
);

it('should scope the activity feed, which is a list across assets', () => {
(getPathNameFromWindowLocation as jest.Mock).mockReturnValue('/');
mockGetState.mockReturnValue({ activeDomain: 'engineering' });
it.each(['/activity', '/activity/mentions'])(
'should scope the activity feed, which is a list across assets (%s)',
(url) => {
(getPathNameFromWindowLocation as jest.Mock).mockReturnValue('/');
mockGetState.mockReturnValue({ activeDomain: 'engineering' });

const result = withDomainFilter(
createMockConfig('get', '/activity', { days: 30, limit: 200 })
);
const result = withDomainFilter(
createMockConfig('get', url, { days: 30, limit: 200 })
);

expect(result.params).toEqual({
days: 30,
limit: 200,
domain: 'engineering',
});
});
expect(result.params).toEqual({
days: 30,
limit: 200,
domain: 'engineering',
});
}
);

it.each([
['/tasks', { aboutEntity: 'svc.db.sch.orders' }],
Expand Down
Loading
Loading