Skip to content

Commit

Permalink
fix: fixed deletion of pseudo criterias in a request - Ref gestion-de…
Browse files Browse the repository at this point in the history
…-projet#2684 (#1025)
  • Loading branch information
ManelleG authored Jul 25, 2024
1 parent f796dd4 commit 12b2cf5
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/utils/cohortCreation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,27 @@ export const cleanNominativeCriterias = (
})

const cleanedCriteriasIds = cleanedSelectedCriteria.map((criterion) => criterion.id)
const cleanedGroups = criteriaGroups.map((group) => {
return {
...group,
criteriaIds: group.criteriaIds.filter((id) => cleanedCriteriasIds.includes(id))
}
})
const groupsIdsToDelete = criteriaGroups
.filter((group) => !group.criteriaIds.filter((id) => id > 0).some((id) => cleanedCriteriasIds.includes(id)))
.map((group) => group.id)
const cleanedGroups = criteriaGroups
.map((group) => {
const cleanIds = group.criteriaIds.filter((id) => {
// id < 0 would be a group, and id > 0 a criteria
if (id > 0) {
return cleanedCriteriasIds.includes(id)
} else {
const nestedGroup = criteriaGroups.find((nestedGroup) => nestedGroup.id === id)
return nestedGroup?.criteriaIds.some((id) => cleanedCriteriasIds.includes(id))
}
})

return {
...group,
criteriaIds: cleanIds
}
})
.filter((group) => !groupsIdsToDelete.includes(group.id))
dispatch(editAllCriteriaGroup(cleanedGroups))
dispatch(editAllCriteria(cleanedSelectedCriteria))
dispatch(pseudonimizeCriteria())
Expand Down

0 comments on commit 12b2cf5

Please sign in to comment.