Skip to content

Commit dc3642e

Browse files
authored
feat(annotation-activity): hide AnnotationActivityLink (#3089)
* feat(annotation-activity): hide link show AnnotationActivityLink based on hasVerions param
1 parent 29fc19c commit dc3642e

File tree

13 files changed

+187
-127
lines changed

13 files changed

+187
-127
lines changed

src/elements/content-sidebar/ActivitySidebar.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
957957
elementId,
958958
file,
959959
hasReplies,
960+
hasVersions,
960961
isDisabled = false,
961962
onVersionHistoryClick,
962963
getUserProfileUrl,
@@ -988,6 +989,7 @@ class ActivitySidebar extends React.PureComponent<Props, State> {
988989
getMentionWithQuery={this.getMention}
989990
getUserProfileUrl={getUserProfileUrl}
990991
hasReplies={hasReplies}
992+
hasVersions={hasVersions}
991993
isDisabled={isDisabled}
992994
mentionSelectorContacts={mentionSelectorContacts}
993995
contactsLoaded={contactsLoaded}

src/elements/content-sidebar/__tests__/__snapshots__/ActivitySidebar.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ exports[`elements/content-sidebar/ActivitySidebar render() should render the act
5151
getAvatarUrl={[Function]}
5252
getMentionWithQuery={[Function]}
5353
hasReplies={false}
54+
hasVersions={true}
5455
isDisabled={false}
5556
onAnnotationDelete={[Function]}
5657
onAnnotationEdit={[Function]}

src/elements/content-sidebar/activity-feed/activity-feed/ActiveState.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type Props = {
4646
getMentionWithQuery?: Function,
4747
getUserProfileUrl?: GetProfileUrlCallback,
4848
hasReplies?: boolean,
49+
hasVersions?: boolean,
4950
items: FeedItems,
5051
mentionSelectorContacts?: SelectorItems<>,
5152
onAnnotationDelete?: ({ id: string, permissions: AnnotationPermission }) => void,
@@ -91,6 +92,7 @@ const ActiveState = ({
9192
currentFileVersionId,
9293
currentUser,
9394
hasReplies = false,
95+
hasVersions,
9496
items,
9597
mentionSelectorContacts,
9698
getMentionWithQuery,
@@ -270,6 +272,7 @@ const ActiveState = ({
270272
getAvatarUrl={getAvatarUrl}
271273
getUserProfileUrl={getUserProfileUrl}
272274
getMentionWithQuery={getMentionWithQuery}
275+
hasVersions={hasVersions}
273276
isCurrentVersion={currentFileVersionId === itemFileVersionId}
274277
item={item}
275278
mentionSelectorContacts={mentionSelectorContacts}

src/elements/content-sidebar/activity-feed/activity-feed/ActivityFeed.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type Props = {
4545
getMentionWithQuery?: Function,
4646
getUserProfileUrl?: GetProfileUrlCallback,
4747
hasReplies?: boolean,
48+
hasVersions?: boolean,
4849
isDisabled?: boolean,
4950
mentionSelectorContacts?: SelectorItems<User>,
5051
onAnnotationDelete?: ({ id: string, permissions: AnnotationPermission }) => void,
@@ -236,6 +237,7 @@ class ActivityFeed extends React.Component<Props, State> {
236237
getMentionWithQuery,
237238
getUserProfileUrl,
238239
hasReplies,
240+
hasVersions,
239241
isDisabled,
240242
mentionSelectorContacts,
241243
contactsLoaded,
@@ -319,6 +321,7 @@ class ActivityFeed extends React.Component<Props, State> {
319321
getMentionWithQuery={getMentionWithQuery}
320322
getUserProfileUrl={getUserProfileUrl}
321323
hasReplies={hasReplies}
324+
hasVersions={hasVersions}
322325
isDisabled={isDisabled}
323326
items={collapseFeedState(feedItems)}
324327
mentionSelectorContacts={mentionSelectorContacts}

src/elements/content-sidebar/activity-feed/annotations/AnnotationActivity.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ type Props = {
3030
getAvatarUrl: GetAvatarUrlCallback,
3131
getMentionWithQuery?: (searchStr: string) => void,
3232
getUserProfileUrl?: GetProfileUrlCallback,
33-
isCurrentVersion: boolean,
33+
hasVersions?: boolean,
34+
isCurrentVersion?: boolean,
3435
item: Annotation,
3536
mentionSelectorContacts?: SelectorItems<User>,
3637
onDelete?: ({ id: string, permissions: AnnotationPermission }) => any,
@@ -45,6 +46,7 @@ const AnnotationActivity = ({
4546
getAvatarUrl,
4647
getMentionWithQuery,
4748
getUserProfileUrl,
49+
hasVersions,
4850
isCurrentVersion,
4951
mentionSelectorContacts,
5052
onDelete = noop,
@@ -102,12 +104,9 @@ const AnnotationActivity = ({
102104

103105
const createdAtTimestamp = new Date(created_at).getTime();
104106
const createdByUser = created_by || PLACEHOLDER_USER;
105-
const linkMessage = isCurrentVersion ? messages.annotationActivityPageItem : messages.annotationActivityVersionLink;
106-
const linkValue = isCurrentVersion ? target.location.value : getProp(file_version, 'version_number');
107+
107108
const message = (description && description.message) || '';
108-
const activityLinkMessage = isFileVersionUnavailable
109-
? messages.annotationActivityVersionUnavailable
110-
: { ...linkMessage, values: { number: linkValue } };
109+
111110
const tetherProps = {
112111
attachment: 'top right',
113112
className: 'bcs-AnnotationActivity-deleteConfirmationModal',
@@ -149,10 +148,12 @@ const AnnotationActivity = ({
149148
<AnnotationActivityLink
150149
className="bcs-AnnotationActivity-link"
151150
data-resin-target="annotationLink"
151+
fileVersion={getProp(file_version, 'version_number')}
152152
id={id}
153-
isDisabled={isFileVersionUnavailable}
154-
message={activityLinkMessage}
153+
isCurrentVersion={isCurrentVersion}
154+
locationValue={target.location.value}
155155
onClick={handleSelect}
156+
shouldHideLink={!hasVersions}
156157
/>
157158
</div>
158159
<ActivityStatus status={status} />

src/elements/content-sidebar/activity-feed/annotations/AnnotationActivity.scss

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,6 @@
4242
.bcs-AnnotationActivity-timestamp {
4343
display: flex;
4444
white-space: nowrap;
45-
46-
.bcs-ActivityTimestamp {
47-
&::after {
48-
margin-right: 8px;
49-
margin-left: 8px;
50-
color: $bdl-gray-50;
51-
content: '\2022';
52-
}
53-
}
5445
}
5546

5647
// override for activity feed defaults

src/elements/content-sidebar/activity-feed/annotations/AnnotationActivityLink.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
color: $bdl-box-blue;
77
font-weight: bold;
88

9+
&::before {
10+
margin-right: 2 * $bdl-grid-unit;
11+
margin-left: 2 * $bdl-grid-unit;
12+
color: $bdl-gray-50;
13+
content: '\2022';
14+
}
15+
916
&[aria-disabled='true'] {
1017
color: $bdl-gray-62;
1118
}

src/elements/content-sidebar/activity-feed/annotations/AnnotationActivityLink.tsx

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,48 @@ import noop from 'lodash/noop';
44
import { injectIntl, MessageDescriptor, WrappedComponentProps } from 'react-intl';
55
import PlainButton from '../../../../components/plain-button';
66
import { ButtonType } from '../../../../components/button';
7+
import messages from './messages';
78
import './AnnotationActivityLink.scss';
89

910
type MessageDescriptorWithValues = {
10-
values?: Record<string, number>;
11+
values?: { number: string };
1112
} & MessageDescriptor;
1213
export interface AnnotationActivityLinkProps extends WrappedComponentProps {
1314
className?: string;
15+
fileVersion: string;
1416
id: string;
15-
isDisabled: boolean;
16-
message: MessageDescriptorWithValues;
17+
isCurrentVersion?: boolean;
18+
locationValue: string;
1719
onClick: (id: string) => void;
20+
shouldHideLink: boolean;
1821
}
1922

20-
const AnnotationActivityLink = ({
23+
const AnnotationActivityLink: React.FC<AnnotationActivityLinkProps> = ({
2124
className,
2225
id,
26+
fileVersion,
2327
intl,
24-
isDisabled = false,
25-
message,
28+
isCurrentVersion,
29+
locationValue,
2630
onClick = noop,
31+
shouldHideLink,
2732
...rest
28-
}: AnnotationActivityLinkProps): JSX.Element => {
29-
const { values, ...messageDescriptor } = message;
33+
}: AnnotationActivityLinkProps) => {
34+
if (shouldHideLink) {
35+
return null;
36+
}
37+
38+
const getMessage = (): MessageDescriptorWithValues => {
39+
const linkMessage = isCurrentVersion
40+
? messages.annotationActivityPageItem
41+
: messages.annotationActivityVersionLink;
42+
const linkValue = isCurrentVersion ? locationValue : fileVersion;
43+
return !fileVersion
44+
? messages.annotationActivityVersionUnavailable
45+
: { ...linkMessage, values: { number: linkValue } };
46+
};
47+
48+
const { values, ...messageDescriptor } = getMessage();
3049
const translatedMessage = intl.formatMessage(messageDescriptor, values);
3150

3251
const handleClick = (event: React.SyntheticEvent<HTMLButtonElement>) => {
@@ -38,7 +57,7 @@ const AnnotationActivityLink = ({
3857
};
3958

4059
const handleMouseDown = (event: React.MouseEvent<HTMLButtonElement>) => {
41-
if (isDisabled) {
60+
if (!fileVersion) {
4261
return;
4362
}
4463

@@ -52,7 +71,7 @@ const AnnotationActivityLink = ({
5271
<PlainButton
5372
className={classNames('bcs-AnnotationActivityLink', className)}
5473
data-testid="bcs-AnnotationActivity-link"
55-
isDisabled={isDisabled}
74+
isDisabled={!fileVersion}
5675
onClick={handleClick}
5776
onMouseDown={handleMouseDown}
5877
title={translatedMessage}

src/elements/content-sidebar/activity-feed/annotations/__tests__/AnnotationActivity.test.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import AnnotationActivityMenu from '../AnnotationActivityMenu';
66
import CommentForm from '../../comment-form/CommentForm';
77
import DeleteConfirmation from '../../common/delete-confirmation';
88
import Media from '../../../../../components/media';
9-
import messages from '../messages';
109
import SelectableActivityCard from '../../SelectableActivityCard';
1110

1211
jest.mock('../../Avatar', () => () => 'Avatar');
@@ -39,6 +38,7 @@ describe('elements/content-sidebar/ActivityFeed/annotations/AnnotationActivity',
3938
const mockActivity = {
4039
currentUser,
4140
handlers: allHandlers,
41+
hasVersions: true,
4242
isCurrentVersion: true,
4343
item: mockAnnotation,
4444
mentionSelectorContacts,
@@ -84,10 +84,10 @@ describe('elements/content-sidebar/ActivityFeed/annotations/AnnotationActivity',
8484
expect(wrapper.find('ActivityTimestamp').prop('date')).toEqual(unixTime);
8585
expect(wrapper.find('AnnotationActivityLink').props()).toMatchObject({
8686
'data-resin-target': 'annotationLink',
87-
message: {
88-
...messages.annotationActivityPageItem,
89-
values: { number: 1 },
90-
},
87+
isCurrentVersion: true,
88+
fileVersion: mockAnnotation.file_version.version_number,
89+
locationValue: mockAnnotation.target.location.value,
90+
shouldHideLink: false,
9191
});
9292
expect(wrapper.exists(AnnotationActivityMenu)).toBe(true);
9393
expect(wrapper.find('ForwardRef(withFeatureConsumer(ActivityMessage))').prop('tagged_message')).toEqual(
@@ -127,28 +127,23 @@ describe('elements/content-sidebar/ActivityFeed/annotations/AnnotationActivity',
127127
expect(wrapper.exists('CommentForm')).toBe(false);
128128
});
129129

130-
test('should correctly render annotation activity of another file version', () => {
131-
const wrapper = getWrapper({ isCurrentVersion: false });
132-
133-
expect(wrapper.find('AnnotationActivityLink').prop('message')).toEqual({
134-
...messages.annotationActivityVersionLink,
135-
values: { number: '2' },
136-
});
130+
test('should render commenter as a link', () => {
131+
const wrapper = getWrapper();
132+
expect(wrapper.find('UserLink').prop('name')).toEqual(mockActivity.item.created_by.name);
137133
});
138134

139-
test('should render version unavailable if file version is null', () => {
140-
const wrapper = getWrapper({ item: { ...mockAnnotation, file_version: null } });
141-
const activityLink = wrapper.find('AnnotationActivityLink');
142-
143-
expect(activityLink.prop('message')).toEqual({
144-
...messages.annotationActivityVersionUnavailable,
135+
test('should hide AnnotationActivityLink if hasVersions is false', () => {
136+
const wrapper = getWrapper({ hasVersions: false });
137+
expect(wrapper.find('AnnotationActivityLink').props()).toMatchObject({
138+
shouldHideLink: true,
145139
});
146-
expect(activityLink.prop('isDisabled')).toBe(true);
147140
});
148141

149-
test('should render commenter as a link', () => {
150-
const wrapper = getWrapper();
151-
expect(wrapper.find('UserLink').prop('name')).toEqual(mockActivity.item.created_by.name);
142+
test('should show AnnotationActivityLink if hasVersions is true', () => {
143+
const wrapper = getWrapper({ hasVersions: true });
144+
expect(wrapper.find('AnnotationActivityLink').props()).toMatchObject({
145+
shouldHideLink: false,
146+
});
152147
});
153148

154149
test('should not show actions menu when annotation activity is pending', () => {

0 commit comments

Comments
 (0)