Skip to content

Commit 2e9dd6a

Browse files
fix(content-sharing): Collaborator current user (#4328)
* fix: Collaborator current user * fix: nits --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent bd0dd5f commit 2e9dd6a

File tree

7 files changed

+171
-122
lines changed

7 files changed

+171
-122
lines changed

src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export const PERMISSION_CAN_VIEW_ANNOTATIONS = 'can_view_annotations';
200200

201201
/* --------------------- Invitee roles --------------------------- */
202202
export const INVITEE_ROLE_EDITOR: 'editor' = 'editor';
203+
export const INVITEE_ROLE_OWNER: 'owner' = 'owner';
203204

204205
/* ------------- Delimiters for bread crumbs ---------------- */
205206
export const DELIMITER_SLASH: 'slash' = 'slash';

src/elements/content-sharing/ContentSharingV2.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,21 @@ function ContentSharingV2({
4646
const [collaborationRoles, setCollaborationRoles] = React.useState<CollaborationRole[] | null>(null);
4747
const [collaborators, setCollaborators] = React.useState<Collaborator[] | null>(null);
4848
const [collaboratorsData, setCollaboratorsData] = React.useState<Collaborations | null>(null);
49+
const [owner, setOwner] = React.useState({ id: '', email: '', name: '' });
4950

5051
// Handle successful GET requests to /files or /folders
5152
const handleGetItemSuccess = React.useCallback(itemData => {
5253
const {
5354
collaborationRoles: collaborationRolesFromAPI,
5455
item: itemFromAPI,
56+
ownedBy,
5557
sharedLink: sharedLinkFromAPI,
5658
} = convertItemResponse(itemData);
59+
5760
setItem(itemFromAPI);
5861
setSharedLink(sharedLinkFromAPI);
5962
setCollaborationRoles(collaborationRolesFromAPI);
63+
setOwner({ id: ownedBy.id, email: ownedBy.login, name: ownedBy.name });
6064
}, []);
6165

6266
// Reset state if the API has changed
@@ -122,13 +126,17 @@ function ContentSharingV2({
122126
})();
123127
}, [api, avatarURLMap, collaboratorsData, itemID]);
124128

125-
// Return processed data when both are ready
126129
React.useEffect(() => {
127-
if (collaboratorsData && avatarURLMap) {
128-
const collaboratorsWithAvatars = convertCollabsResponse(collaboratorsData, avatarURLMap);
130+
if (avatarURLMap && collaboratorsData && currentUser && owner) {
131+
const collaboratorsWithAvatars = convertCollabsResponse(
132+
collaboratorsData,
133+
currentUser.id,
134+
owner,
135+
avatarURLMap,
136+
);
129137
setCollaborators(collaboratorsWithAvatars);
130138
}
131-
}, [collaboratorsData, avatarURLMap]);
139+
}, [avatarURLMap, collaboratorsData, currentUser, owner]);
132140

133141
const config = { sharedLinkEmail: false };
134142

src/elements/content-sharing/utils/__mocks__/ContentSharingV2Mocks.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const mockAvatarURLMap = {
3232
};
3333

3434
export const mockOwnerEmail = 'aotter@example.com';
35-
36-
export const mockCurrentUserID = 789;
35+
export const mockOwnerName = 'Astronaut Otter';
36+
export const mockOwnerId = 789;
3737

3838
export const collabUser1 = {
3939
id: 456,
@@ -44,7 +44,7 @@ export const collabUser1 = {
4444

4545
export const collabUser2 = {
4646
id: 457,
47-
login: 'rqueen@example.com',
47+
login: 'rqueen@external.example.com',
4848
name: 'Raccoon Queen',
4949
};
5050

@@ -54,26 +54,26 @@ export const collabUser3 = {
5454
name: 'Dancing Penguin',
5555
};
5656

57-
export const collabUser4 = {
58-
id: mockCurrentUserID,
57+
export const mockOwner = {
58+
id: mockOwnerId,
5959
login: mockOwnerEmail,
60-
name: 'Astronaut Otter',
60+
name: mockOwnerName,
6161
};
6262

63-
export const MOCK_COLLABORATORS = [collabUser4, collabUser1, collabUser2, collabUser3];
63+
export const MOCK_COLLABORATORS = [collabUser1, collabUser2, collabUser3];
6464

6565
export const MOCK_COLLABORATIONS_RESPONSE = {
6666
entries: MOCK_COLLABORATORS.map(user => ({
6767
id: `record_${user.id}`,
6868
accessible_by: user,
6969
expires_at: user.expires_at,
7070
created_by: {
71-
id: mockCurrentUserID,
71+
id: mockOwnerId,
7272
login: mockOwnerEmail,
73-
name: 'Astronaut Otter',
73+
name: mockOwnerName,
7474
type: 'user',
7575
},
76-
role: user.id === mockCurrentUserID ? 'owner' : 'editor',
76+
role: user.id === mockOwnerId ? 'owner' : 'editor',
7777
status: 'accepted',
7878
type: user.type,
7979
})),
@@ -99,6 +99,7 @@ export const DEFAULT_ITEM_API_RESPONSE = {
9999
classification: null,
100100
id: MOCK_ITEM.id,
101101
name: MOCK_ITEM.name,
102+
owned_by: mockOwner,
102103
permissions: MOCK_PERMISSIONS,
103104
shared_link: null,
104105
shared_link_features: { password: true },

0 commit comments

Comments
 (0)