mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-06 23:32:08 +00:00
Enfant ajouté à une personne qui n'a qu'un conjoint : enfant du couple (#200)
Avant, « + Enfant » sur la fiche d'Isabelle (un seul conjoint, Robert) rattachait l'enfant à Isabelle seule : il pendait sous elle et un parent « Inconnu », loin de ses frères et sœurs. Il passe maintenant par les liens du couple (getCoupleParentLinks), comme un frère ou une sœur, pour la démo, la famille qui propose et le propriétaire. Sans conjoint, avec plusieurs conjoints, ou en adoption : l'enfant reste au seul parent choisi. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f595af581a
commit
cd6dfc6955
3 files changed
+54
-4
No files matched your search
+16
-3
@@ -73,7 +73,7 @@ import { readGedcomBundle, zipErrorMessage } from './utils/gedcomBundle.js'
|
||||
import { materializeFile } from './utils/zipReader.js'
|
||||
import { loadMediaRefs, loadPhotoRefs, pickFirstFaces, prepareImageForUpload, saveMediaRefs, savePhotoRefs, sizeBucket } from './utils/photoImport'
|
||||
import { fileToBase64, getAccountErrorMessage } from './utils/errorMessages'
|
||||
import { getSiblingParentLinks } from './utils/familyLinks'
|
||||
import { getCoupleParentLinks, getSiblingParentLinks } from './utils/familyLinks'
|
||||
import { getUploadMimeType, inferMediaTypeFromMimeType, validateMediaFile } from './utils/mediaUpload'
|
||||
import {
|
||||
getSource,
|
||||
@@ -1225,6 +1225,19 @@ function App() {
|
||||
siblingParentLinks.push(...links)
|
||||
}
|
||||
}
|
||||
// Un enfant ajouté à une personne qui n'a qu'un conjoint est l'enfant du couple : il passe par les liens
|
||||
// du couple, comme un frère ou une sœur. Une adoption reste au seul parent choisi.
|
||||
const relationCount = (formData.relations || []).length
|
||||
formData = {
|
||||
...formData,
|
||||
relations: (formData.relations || []).filter((rel) => {
|
||||
if (rel.type !== 'child' || rel.adopted) return true
|
||||
const coupleLinks = getCoupleParentLinks(rel.personId, unions)
|
||||
if (!coupleLinks.length) return true
|
||||
siblingParentLinks.push(...coupleLinks)
|
||||
return false
|
||||
}),
|
||||
}
|
||||
|
||||
if (!tree.canEditCurrentTree) {
|
||||
if (isDemoMode) {
|
||||
@@ -1331,7 +1344,7 @@ function App() {
|
||||
},
|
||||
]
|
||||
editMode.updateDraft({ addedPersons })
|
||||
trackAppEvent('person_added', { via: addPersonViaRef.current, role: 'family', relations: (formData.relations || []).length, tree_id: opaqueTreeId })
|
||||
trackAppEvent('person_added', { via: addPersonViaRef.current, role: 'family', relations: relationCount, tree_id: opaqueTreeId })
|
||||
// La personne apparaît en fantôme « Brouillon » : la famille peut en ajouter d'autres, puis envoyer une
|
||||
// fois avec le bouton « Envoyer » de la barre (Patch, 25/10). Avant, la fenêtre d'envoi s'ouvrait d'office,
|
||||
// seule façon de montrer qu'un ajout invisible comptait.
|
||||
@@ -1409,7 +1422,7 @@ function App() {
|
||||
})
|
||||
|
||||
await tree.refreshCurrentTreeGraph()
|
||||
trackAppEvent('person_added', { via: addPersonViaRef.current, role: 'manager', relations: (formData.relations || []).length, tree_id: opaqueTreeId })
|
||||
trackAppEvent('person_added', { via: addPersonViaRef.current, role: 'manager', relations: relationCount, tree_id: opaqueTreeId })
|
||||
return newPerson
|
||||
} catch (err) {
|
||||
setAddPersonError(err.message || t("Erreur lors de l'ajout de la personne"))
|
||||
|
||||
@@ -36,3 +36,20 @@ export function getSiblingParentLinks(personId, filiations, unions) {
|
||||
|
||||
return links
|
||||
}
|
||||
|
||||
/**
|
||||
* Parents à rattacher à un nouvel enfant de `parentId` : quand cette personne n'a qu'une union,
|
||||
* l'enfant est celui du couple (les deux partenaires, avec l'identifiant de l'union).
|
||||
* Aucune union, ou plusieurs (on ne devine pas l'autre parent) : liste vide, l'enfant reste au seul parent.
|
||||
*
|
||||
* @param {string} parentId - Personne à qui l'on ajoute un enfant
|
||||
* @param {Array} unions - Unions du graphe courant ({ id, partner1Id, partner2Id })
|
||||
* @returns {Array<{ parentId: string, unionId: string }>}
|
||||
*/
|
||||
export function getCoupleParentLinks(parentId, unions) {
|
||||
const key = String(parentId)
|
||||
const own = (unions || []).filter((union) => String(union.partner1Id) === key || String(union.partner2Id) === key)
|
||||
if (own.length !== 1 || !own[0].partner1Id || !own[0].partner2Id) return []
|
||||
const unionId = String(own[0].id)
|
||||
return [{ parentId: String(own[0].partner1Id), unionId }, { parentId: String(own[0].partner2Id), unionId }]
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { getSiblingParentLinks } from './familyLinks'
|
||||
import { getCoupleParentLinks, getSiblingParentLinks } from './familyLinks'
|
||||
|
||||
describe('getSiblingParentLinks', () => {
|
||||
const unions = [{ id: 'u1', partner1Id: 'p1', partner2Id: 'p2' }]
|
||||
@@ -31,3 +31,23 @@ describe('getSiblingParentLinks', () => {
|
||||
expect(getSiblingParentLinks('c1', undefined, undefined)).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('getCoupleParentLinks', () => {
|
||||
it('gives both partners when the parent has a single union', () => {
|
||||
const unions = [{ id: 'u1', partner1Id: 'p1', partner2Id: 'p2' }]
|
||||
expect(getCoupleParentLinks('p2', unions)).toEqual([
|
||||
{ parentId: 'p1', unionId: 'u1' },
|
||||
{ parentId: 'p2', unionId: 'u1' },
|
||||
])
|
||||
})
|
||||
|
||||
it('keeps the child with the parent alone when there is no union or several', () => {
|
||||
expect(getCoupleParentLinks('p1', [])).toEqual([])
|
||||
expect(getCoupleParentLinks('p1', undefined)).toEqual([])
|
||||
const unions = [
|
||||
{ id: 'u1', partner1Id: 'p1', partner2Id: 'p2' },
|
||||
{ id: 'u2', partner1Id: 'p3', partner2Id: 'p1' },
|
||||
]
|
||||
expect(getCoupleParentLinks('p1', unions)).toEqual([])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user