Skip to content

Commit a626ee4

Browse files
doublefacedoubleface
authored andcommitted
fix(cozy-sharing): Accumulate recipients in federated folder sharing
When the drive.federated-shared-folder.enable flag is active, each recipient added via onShare was overwriting the previous ones. Use mergeAndDeduplicateRecipients to properly accumulate recipients, matching the behavior of SharedDriveModal.
1 parent 25f9864 commit a626ee4

File tree

2 files changed

+49
-8
lines changed

2 files changed

+49
-8
lines changed

packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import withLocales from '../../hoc/withLocales'
1010
import { useSharingContext } from '../../hooks/useSharingContext'
1111
import {
1212
formatRecipients,
13+
mergeAndDeduplicateRecipients,
1314
moveRecipientToReadWrite,
1415
moveRecipientToReadOnly,
1516
RECIPIENT_INDEX_PREFIX
@@ -66,10 +67,16 @@ export const FederatedFolderModal = withLocales(
6667
const [folderName] = useState(existingDocument?.name || '')
6768

6869
const onShare = params => {
69-
setFederatedRecipients({
70-
recipients: params.recipients || [],
71-
readOnlyRecipients: params.readOnlyRecipients || []
72-
})
70+
setFederatedRecipients(prev => ({
71+
recipients: mergeAndDeduplicateRecipients([
72+
prev.recipients,
73+
params.recipients || []
74+
]),
75+
readOnlyRecipients: mergeAndDeduplicateRecipients([
76+
prev.readOnlyRecipients,
77+
params.readOnlyRecipients || []
78+
])
79+
}))
7380
}
7481

7582
const onSend = async () => {

packages/cozy-sharing/src/components/FederatedFolder/FederatedFolderModal.spec.jsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,27 @@ jest.mock('./DumbFederatedFolderModal', () => ({
5555
data-testid="btn-share"
5656
onClick={() =>
5757
onShare({
58-
recipients: [{ _id: 'r1', displayName: 'Alice' }],
59-
readOnlyRecipients: [{ _id: 'r2', displayName: 'Bob' }]
58+
recipients: [{ _id: 'r1', id: 'r1', displayName: 'Alice' }],
59+
readOnlyRecipients: [{ _id: 'r2', id: 'r2', displayName: 'Bob' }]
6060
})
6161
}
6262
>
6363
Share
6464
</button>
65+
<button
66+
data-testid="btn-share-other"
67+
onClick={() =>
68+
onShare({
69+
recipients: [
70+
{ _id: 'r1', id: 'r1', displayName: 'Alice' },
71+
{ _id: 'r3', id: 'r3', displayName: 'Charlie' }
72+
],
73+
readOnlyRecipients: []
74+
})
75+
}
76+
>
77+
Share Other
78+
</button>
6579
<button data-testid="btn-send" onClick={onSend}>
6680
Send
6781
</button>
@@ -213,6 +227,26 @@ describe('FederatedFolderModal', () => {
213227
expect(getByTestId('recipients-count').textContent).toBe('2')
214228
})
215229
})
230+
231+
it('should accumulate recipients when onShare is called multiple times', async () => {
232+
const { getByTestId } = setup()
233+
234+
await waitFor(() => {
235+
expect(getByTestId('recipients-count').textContent).toBe('0')
236+
})
237+
238+
fireEvent.click(getByTestId('btn-share'))
239+
240+
await waitFor(() => {
241+
expect(getByTestId('recipients-count').textContent).toBe('2')
242+
})
243+
244+
fireEvent.click(getByTestId('btn-share-other'))
245+
246+
await waitFor(() => {
247+
expect(getByTestId('recipients-count').textContent).toBe('3')
248+
})
249+
})
216250
})
217251

218252
describe('onSend callback', () => {
@@ -231,8 +265,8 @@ describe('FederatedFolderModal', () => {
231265
expect(mockShare).toHaveBeenCalledWith({
232266
description: 'My Test Folder',
233267
document: mockDocument,
234-
recipients: [{ _id: 'r1', displayName: 'Alice' }],
235-
readOnlyRecipients: [{ _id: 'r2', displayName: 'Bob' }],
268+
recipients: [{ _id: 'r1', id: 'r1', displayName: 'Alice' }],
269+
readOnlyRecipients: [{ _id: 'r2', id: 'r2', displayName: 'Bob' }],
236270
sharedDrive: true,
237271
openSharing: false
238272
})

0 commit comments

Comments
 (0)