Skip to content

Commit

Permalink
feat: Hide groups when they are already shared
Browse files Browse the repository at this point in the history
This prevents the user from adding the same group several times and the stack returning an error.
  • Loading branch information
cballevre committed Apr 9, 2024
1 parent 786b1a0 commit f64ee06
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/cozy-sharing/src/components/ShareByEmail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const ShareByEmail = ({
}
onPick={recipient => onRecipientPick(recipient)}
onRemove={recipient => onRecipientRemove(recipient)}
currentRecipients={currentRecipients}
recipients={recipients}
/>
</div>
Expand Down
18 changes: 14 additions & 4 deletions packages/cozy-sharing/src/components/ShareRecipientsInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
* In order to display the total number of members in each group, we also retrieve the contacts that are not reachable.
*/
const ShareRecipientsInput = ({
currentRecipients,
recipients,
placeholder,
onPick,
Expand Down Expand Up @@ -62,8 +63,16 @@ const ShareRecipientsInput = ({
(isQueryLoading(unreachableContactsWithGroupsResult) ||
unreachableContactsWithGroupsResult.hasMore))

const contactGroups = (contactGroupsByIdsResult.data || []).map(
contactGroup => {
const currentRecipientGroups = currentRecipients
.map(({ id }) => id)
.filter(Boolean)
const contactGroups = (contactGroupsByIdsResult.data || [])
.filter(
({ _id }) =>
!flag('sharing.show-recipient-groups') ||
!currentRecipientGroups.includes(_id)
)
.map(contactGroup => {
const reachableMembers = getContactsFromGroupId(
reachableContactsResult.data,
contactGroup.id
Expand Down Expand Up @@ -91,8 +100,7 @@ const ShareRecipientsInput = ({
...contactGroup,
members: [...reachableMembers, ...unreachableMembers]
}
}
)
})

const contactsAndGroups = [
...(reachableContactsResult.data || []),
Expand All @@ -112,13 +120,15 @@ const ShareRecipientsInput = ({
}

ShareRecipientsInput.propTypes = {
currentRecipients: PropTypes.array,
recipients: PropTypes.array,
placeholder: PropTypes.string,
onPick: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired
}

ShareRecipientsInput.defaultProps = {
currentRecipients: [],
recipients: []
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AppLike from './SharingBanner/test/AppLike'

jest.mock('cozy-flags', () => ({
__esModule: true,
default: jest.fn()
default: jest.fn(() => null)
}))

jest.mock('./ShareAutosuggest', () => ({
Expand Down

0 comments on commit f64ee06

Please sign in to comment.