Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fixed deletion of pseudo criterias in a request - Ref gestion-de-projet#2684 #1025

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading