From d88f2f4c61943f8fa63446faec98dd08fde7772e Mon Sep 17 00:00:00 2001 From: Alexis G Date: Wed, 30 Aug 2023 16:26:27 +0200 Subject: [PATCH 1/2] feat: If the currently selected group is deleted, default filter is set --- src/components/ContentResult.jsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/components/ContentResult.jsx b/src/components/ContentResult.jsx index a5b106ef9..7a86d5649 100644 --- a/src/components/ContentResult.jsx +++ b/src/components/ContentResult.jsx @@ -18,6 +18,7 @@ import SearchInput from './Search/SearchInput' import Toolbar from './Toolbar' import { filterContactsByGroup, + hasSelectedGroup, translatedDefaultSelectedGroup } from '../helpers/groups' import { filterContactsBySearch, delayedSetThreshold } from '../helpers/search' @@ -64,6 +65,13 @@ export const ContentResult = ({ contacts, allGroups }) => { delayedSetThreshold(thresholdValue) } + // If the currently selected group is deleted, the default filter is set. + useEffect(() => { + if (hasSelectedGroup(selectedGroup) && !allGroups.includes(selectedGroup)) { + setSelectedGroup(translatedDefaultSelectedGroup(t)) + } + }, [allGroups, selectedGroup, setSelectedGroup, t]) + useEffect(() => { const filteredContactsByGroup = filterContactsByGroup( contacts, From 30c0493e3b6bbd1b18c390f339c2737449957577 Mon Sep 17 00:00:00 2001 From: Alexis G Date: Fri, 1 Sep 2023 14:24:03 +0200 Subject: [PATCH 2/2] feat: Improved wording when deleting group --- .../Modals/GroupDeleteConfirmationModal.jsx | 21 ++++++++++++++++--- src/connections/allContacts.js | 13 ++++++------ src/connections/allGroups.js | 18 +++++++++++++--- src/locales/en.json | 5 ++++- src/locales/fr.json | 5 ++++- 5 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/components/Modals/GroupDeleteConfirmationModal.jsx b/src/components/Modals/GroupDeleteConfirmationModal.jsx index 9652189b9..24e2eaa4f 100644 --- a/src/components/Modals/GroupDeleteConfirmationModal.jsx +++ b/src/components/Modals/GroupDeleteConfirmationModal.jsx @@ -37,17 +37,32 @@ const GroupDeleteConfirmationModal = () => { cleanTrashedGroupsAndATrashedContacts(client) }, alertDuration) + let contactsTrashCount = 0 if (deleteAssociatedContacts) { - await trashedAllContactsByGroupId(client, groupId) + const contacts = await trashedAllContactsByGroupId(client, groupId) + contactsTrashCount = contacts.length } await trashedGroupById(client, groupId) - Alerter.info('groups.removed', { + const translationKey = deleteAssociatedContacts + ? contactsTrashCount > 0 + ? 'groups.removed_with_contacts' + : 'groups.removed_without_contacts' + : 'groups.removed' + + Alerter.info(translationKey, { name: groupName, + smart_count: contactsTrashCount, buttonText: t('cancel'), buttonAction: () => { clearTimeout(timeout) - cancelTrashGroupById(client, groupId) + + cancelTrashGroupById( + client, + groupId, + deleteAssociatedContacts, + contactsTrashCount + ) if (deleteAssociatedContacts) { cancelTrashContactsByGroupId(client, groupId) } diff --git a/src/connections/allContacts.js b/src/connections/allContacts.js index 6818305f2..5fe75e62f 100644 --- a/src/connections/allContacts.js +++ b/src/connections/allContacts.js @@ -189,12 +189,13 @@ export const trashedAllContactsByGroupId = async (client, groupId) => { }) try { - await client.saveAll(contactsTrashed) - } catch (error) { - if (contactsTrashed.length === 0) { - log('info', 'No contacts to trash') - } else { - log('error', `Error saving contact to trash: ${error}`) + if (contactsTrashed.length > 0) { + const result = await client.saveAll(contactsTrashed) + return result.data } + log('info', 'No contacts to trash') + return [] + } catch (error) { + log('error', `Error saving contact to trash: ${error}`) } } diff --git a/src/connections/allGroups.js b/src/connections/allGroups.js index 9745fe743..7d4e97c28 100644 --- a/src/connections/allGroups.js +++ b/src/connections/allGroups.js @@ -57,7 +57,12 @@ export const trashedGroupById = async (client, groupId) => { * @param {Object} client - CozyClient * @param {String} groupId - Group id */ -export const cancelTrashGroupById = async (client, groupId) => { +export const cancelTrashGroupById = async ( + client, + groupId, + deleteAssociatedContacts, + contactsTrashCount +) => { const groupQueryById = buildGroupQueryById(groupId) const { data: group } = await client.query( groupQueryById.definition(), @@ -69,7 +74,14 @@ export const cancelTrashGroupById = async (client, groupId) => { trashed: false }) - Alerter.info('groups.remove_canceled', { - name: group.name + const translationKey = deleteAssociatedContacts + ? contactsTrashCount > 0 + ? 'groups.remove_cancel_with_contacts' + : 'groups.remove_cancel_without_contacts' + : 'groups.remove_canceled' + + Alerter.info(translationKey, { + name: group.name, + smart_count: contactsTrashCount }) } diff --git a/src/locales/en.json b/src/locales/en.json index 40c1ea337..1391b4c1a 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -112,7 +112,10 @@ }, "name": "Name of the group", "removed": "The group %{name} has been removed.", - "remove_canceled": "The group %{name} has been restored. Contacts are still linked.", + "remove_canceled": "The group %{name} has been restored.", + "remove_cancel_with_contacts": "The group %{name} has been restored. Contact are still linked. |||| The group %{name} has been restored. Contacts are still linked.", + "removed_without_contacts": "The group %{name} has been removed. It had no associated contacts.", + "removed_with_contacts": "The group %{name} and its associated contact have been successfully removed. |||| The group %{name} and its associated contacts have been successfully removed.", "already_exists": "The group %{name} already exists.", "renamed": { "success": "The group has been renamed correctly.", diff --git a/src/locales/fr.json b/src/locales/fr.json index 5188cb38c..595d54ace 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -112,7 +112,10 @@ }, "name": "Nom du groupe", "removed": "Le groupe %{name} a bien été supprimé.", - "remove_canceled": "Le groupe %{name} n'a pas été supprimé. Vous n'avez pas perdu la liaison avec ses contacts.", + "remove_canceled": "Le groupe %{name} n'a pas été supprimé", + "remove_cancel_with_contacts": "Le groupe %{name} n'a pas été supprimé. Vous n'avez pas perdu la liaison avec son contact. |||| Le groupe %{name} n'a pas été supprimé. Vous n'avez pas perdu la liaison avec ses contacts.", + "removed_without_contacts": "Le groupe %{name} a bien été supprimé. Il n'avait aucun contact associé.", + "removed_with_contacts": "Le groupe %{name} et son contact associé ont bien été supprimés. |||| Le groupe %{name} et ses contacts associés ont bien été supprimés.", "already_exists": "Le groupe %{name} existe déjà.", "renamed": { "success": "Le groupe a bien été renommé.",