Skip to content

Commit bcc909e

Browse files
authored
feat(preview): use uploader_display_name for sidebar uploader info (#2091)
1 parent aefef0b commit bcc909e

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const FIELD_APP: 'app' = 'app';
139139
export const FIELD_OCCURRED_AT: 'occurred_at' = 'occurred_at';
140140
export const FIELD_RENDERED_TEXT: 'rendered_text' = 'rendered_text';
141141
export const FIELD_RETENTION: 'retention' = 'retention';
142+
export const FIELD_UPLOADER_DISPLAY_NAME: 'uploader_display_name' = 'uploader_display_name';
142143

143144
/* ----------------------- Permissions --------------------------- */
144145
export const PERMISSION_CAN_PREVIEW = 'can_preview';

src/elements/content-sidebar/SidebarFileProperties.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { INTERACTION_TARGET, DETAILS_TARGETS } from '../common/interactionTarget
1515
import withErrorHandling from './withErrorHandling';
1616
import type { ClassificationInfo } from './flowTypes';
1717
import type { BoxItem } from '../../common/types/core';
18+
import { PLACEHOLDER_USER } from '../../constants';
1819

1920
type Props = {
2021
classification?: ClassificationInfo,
@@ -55,7 +56,12 @@ const SidebarFileProperties = ({
5556
: {}
5657
}
5758
size={getFileSize(file.size, intl.locale)}
58-
uploader={getProp(file, 'created_by.name')}
59+
// use uploader_display_name if uploaded anonymously
60+
uploader={
61+
getProp(file, 'created_by.id') === PLACEHOLDER_USER.id
62+
? getProp(file, 'uploader_display_name')
63+
: getProp(file, 'created_by.name')
64+
}
5965
/>
6066
</LoadingIndicatorWrapper>
6167
);

src/elements/content-sidebar/__tests__/SidebarFileProperties.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import set from 'lodash/set';
12
import React from 'react';
23
import { shallow, mount } from 'enzyme';
34
import ItemProperties from '../../../features/item-details/ItemProperties';
45
import InlineError from '../../../components/inline-error/InlineError';
56
import SidebarFileProperties, { SidebarFilePropertiesComponent } from '../SidebarFileProperties';
7+
import { PLACEHOLDER_USER } from '../../../constants';
68

79
describe('elements/content-sidebar/SidebarFileProperties', () => {
810
const getWrapper = props => shallow(<SidebarFilePropertiesComponent {...props} />);
@@ -22,6 +24,7 @@ describe('elements/content-sidebar/SidebarFileProperties', () => {
2224
permissions: {
2325
can_rename: true,
2426
},
27+
uploader_display_name: 'File Request',
2528
},
2629
onDescriptionChange: jest.fn(),
2730
intl: {
@@ -54,6 +57,14 @@ describe('elements/content-sidebar/SidebarFileProperties', () => {
5457
expect(wrapper).toMatchSnapshot();
5558
});
5659

60+
test('should render ItemProperties for anonymous uploaders', () => {
61+
const propsHere = set({ ...props }, 'file.created_by.id', PLACEHOLDER_USER.id);
62+
const wrapper = getWrapper(propsHere);
63+
64+
expect(wrapper.find(ItemProperties)).toHaveLength(1);
65+
expect(wrapper).toMatchSnapshot();
66+
});
67+
5768
test('should render an error', () => {
5869
const fakeError = {
5970
id: 'foo',

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,26 @@ exports[`elements/content-sidebar/SidebarFileProperties render() should render I
2020
</LoadingIndicatorWrapper>
2121
`;
2222

23+
exports[`elements/content-sidebar/SidebarFileProperties render() should render ItemProperties for anonymous uploaders 1`] = `
24+
<LoadingIndicatorWrapper>
25+
<ItemProperties
26+
createdAt="2018-04-18T16:56:05.352Z"
27+
description="foo"
28+
descriptionTextareaProps={
29+
Object {
30+
"data-resin-target": "description",
31+
}
32+
}
33+
modifiedAt="2018-04-18T16:56:05.352Z"
34+
onDescriptionChange={[MockFunction]}
35+
owner="foo"
36+
retentionPolicyProps={Object {}}
37+
size="1 B"
38+
uploader="File Request"
39+
/>
40+
</LoadingIndicatorWrapper>
41+
`;
42+
2343
exports[`elements/content-sidebar/SidebarFileProperties render() should render an error 1`] = `
2444
<Fragment>
2545
<InlineError

src/utils/__tests__/fields.test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ import {
5555
FIELD_RESTORED_FROM,
5656
FIELD_RETENTION,
5757
FIELD_URL,
58+
FIELD_UPLOADER_DISPLAY_NAME,
5859
PLACEHOLDER_USER,
5960
} from '../../constants';
6061

@@ -124,6 +125,7 @@ describe('util/fields', () => {
124125
FIELD_RESTORED_FROM,
125126
FIELD_AUTHENTICATED_DOWNLOAD_URL,
126127
FIELD_IS_DOWNLOAD_AVAILABLE,
128+
FIELD_UPLOADER_DISPLAY_NAME,
127129
]);
128130
});
129131

src/utils/fields.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import {
3333
FIELD_DESCRIPTION,
3434
FIELD_REPRESENTATIONS,
3535
FIELD_SHA1,
36+
FIELD_UPLOADER_DISPLAY_NAME,
3637
FIELD_WATERMARK_INFO,
3738
FIELD_AUTHENTICATED_DOWNLOAD_URL,
3839
FIELD_FILE_VERSION,
@@ -106,6 +107,7 @@ const SIDEBAR_FIELDS_TO_FETCH = [
106107
FIELD_RESTORED_FROM,
107108
FIELD_AUTHENTICATED_DOWNLOAD_URL,
108109
FIELD_IS_DOWNLOAD_AVAILABLE,
110+
FIELD_UPLOADER_DISPLAY_NAME,
109111
];
110112

111113
// Fields needed for preview

0 commit comments

Comments
 (0)