mirror of
https://github.com/IliesAllali/parenthese.git
synced 2026-11-19 00:52:11 +00:00
feat(personnes): saisir le sexe et nommer les liens de parenté en conséquence (#114)
- Champ Sexe (femme, homme, non précisé) dans la fiche en modification, à l'ajout d'une personne et dans une proposition de la famille ; relu « Sexe » dans les propositions à relire. - Valeurs ramenées à male / female / null à l'écriture et à la lecture (anciennes valeurs M/F relues sans migration), valeur inconnue refusée (400). Export GEDCOM inchangé dans sa forme. - Lien au survol genré quand le sexe est connu (Père, Tante, Cousine germaine, Belle-mère…), forme double sinon. Nommage déplacé dans utils/kinship : une fonction par langue reçoit le chemin complet (pas, personnes, sexe, année de naissance), pour brancher d'autres langues. - Anglais : beau-parent distingué de parent par alliance selon l'ordre du chemin (Stepmother / Mother-in-law). - Propositions à relire : le nom de la personne modifiée vient de l'avant lu en base quand la modification ne porte que le champ changé. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
4dd0db9699
commit
eaecac8fa5
24 files changed
+521
-117
No files matched your search
@@ -5,6 +5,7 @@ import './AddPersonPanel.css'
|
||||
import PzBusy from './PzBusy.jsx'
|
||||
import { t } from '../i18n/index.js'
|
||||
import { firstNameLabel } from '../utils/personName.js'
|
||||
import { SEX_CHOICES } from '../utils/personSex.js'
|
||||
|
||||
// Titre traduit d'un bloc : le passage entre <em> et </em> garde son italique
|
||||
function withEmphasis(text) {
|
||||
@@ -38,6 +39,7 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
const [lastName, setLastName] = useState('')
|
||||
const [birthName, setBirthName] = useState('')
|
||||
const [nickname, setNickname] = useState('')
|
||||
const [sex, setSex] = useState(null)
|
||||
const [birthDate, setBirthDate] = useState('')
|
||||
const [deathDate, setDeathDate] = useState('')
|
||||
// Décédé(e) sans date connue (issue #77)
|
||||
@@ -101,6 +103,7 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
setLastName('')
|
||||
setBirthName('')
|
||||
setNickname('')
|
||||
setSex(null)
|
||||
setBirthDate('')
|
||||
setDeathDate('')
|
||||
setIsDeceased(false)
|
||||
@@ -156,6 +159,7 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
lastName: lastName.trim(),
|
||||
birthName: birthName.trim() || null,
|
||||
nickname: nickname.trim() || null,
|
||||
sex,
|
||||
birthDate: birthDate || null,
|
||||
deathDate: deathDate || null,
|
||||
isDeceased: !deathDate && isDeceased,
|
||||
@@ -271,6 +275,24 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="pz-field">
|
||||
<span className="pz-label" id="ap-sex-label">{t('Sexe')} <span className="apn-optional">{t('facultatif')}</span></span>
|
||||
<div className="pz-tabs apn-types" role="radiogroup" aria-labelledby="ap-sex-label">
|
||||
{SEX_CHOICES.map(({ value, label }) => (
|
||||
<button
|
||||
key={label}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={sex === value}
|
||||
className={`pz-tab ${sex === value ? 'is-active' : ''}`}
|
||||
onClick={() => setSex(value)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="pz-row2 apn-row">
|
||||
<div className="pz-field">
|
||||
<label htmlFor="ap-birthDate">{t('Naissance')}</label>
|
||||
@@ -282,7 +304,7 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
{!deathDate && (
|
||||
<label className="apn-deceased">
|
||||
<input type="checkbox" checked={isDeceased} onChange={(e) => setIsDeceased(e.target.checked)} />
|
||||
{t('Décédé(e), date inconnue')}
|
||||
{sex === 'male' ? t('Décédé, date inconnue') : sex === 'female' ? t('Décédée, date inconnue') : t('Décédé(e), date inconnue')}
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
@@ -347,7 +369,7 @@ function AddPersonPanel({ visible, persons = [], loading = false, error = '', on
|
||||
{(selectedRelationType === 'child' || selectedRelationType === 'parent') && (
|
||||
<label className="apn-deceased">
|
||||
<input type="checkbox" checked={adopted} onChange={(e) => setAdopted(e.target.checked)} />
|
||||
{t('Adopté(e)')}
|
||||
{sex === 'male' ? t('Adopté') : sex === 'female' ? t('Adoptée') : t('Adopté(e)')}
|
||||
</label>
|
||||
)}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import './SettingsPanels.css'
|
||||
import PzBusy from './PzBusy.jsx'
|
||||
import { HELP_URL } from '../utils/siteLinks.js'
|
||||
import { t, dateLocale } from '../i18n/index.js'
|
||||
import { normalizeSex, SEX_CHOICES } from '../utils/personSex.js'
|
||||
|
||||
// ─── helpers ────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -74,6 +75,7 @@ const PERSON_FIELD_LABELS = {
|
||||
lastName: t('Nom'),
|
||||
birthName: t('Nom de naissance'),
|
||||
nickname: t('Surnom'),
|
||||
sex: t('Sexe'),
|
||||
birthDate: t('Date de naissance'),
|
||||
deathDate: t('Date de décès'),
|
||||
deathPlace: t('Lieu de décès'),
|
||||
@@ -84,7 +86,9 @@ const PERSON_FIELD_LABELS = {
|
||||
notes: t('Notes'),
|
||||
}
|
||||
|
||||
function displayVal(v) {
|
||||
function displayVal(v, key) {
|
||||
// Sexe : « Non précisé » plutôt que « vide »
|
||||
if (key === 'sex') return SEX_CHOICES.find((choice) => choice.value === normalizeSex(v))?.label ?? null
|
||||
if (v === null || v === undefined || v === '') return null
|
||||
return String(v)
|
||||
}
|
||||
@@ -134,10 +138,11 @@ function getPersonDisplayName(change, sessionChanges = []) {
|
||||
const data = change.afterJson || {}
|
||||
return data.title || t('Moment')
|
||||
}
|
||||
const data = (change.afterJson && typeof change.afterJson === 'object')
|
||||
? change.afterJson
|
||||
: (change.beforeJson && typeof change.beforeJson === 'object' ? change.beforeJson : null)
|
||||
if (!data) return null
|
||||
// Une modification ne porte que les champs changés : le nom vient alors de l'« avant » (lu en base)
|
||||
const after = change.afterJson && typeof change.afterJson === 'object' ? change.afterJson : null
|
||||
const before = change.beforeJson && typeof change.beforeJson === 'object' ? change.beforeJson : null
|
||||
if (!after && !before) return null
|
||||
const data = { ...before, ...after }
|
||||
const name = `${data.firstName || ''} ${data.lastName || ''}`.trim()
|
||||
return name || null
|
||||
}
|
||||
@@ -614,12 +619,12 @@ const ContributionPanel = ({
|
||||
<span className="contrib-field-label">{label}</span>
|
||||
{oldVal !== undefined ? (
|
||||
<span className="contrib-field-diff">
|
||||
<span className="contrib-field-old">{displayVal(oldVal) ?? t('vide')}</span>
|
||||
<span className="contrib-field-old">{displayVal(oldVal, key) ?? t('vide')}</span>
|
||||
<span className="contrib-field-arrow">→</span>
|
||||
<span className="contrib-field-new">{displayVal(newVal) ?? t('vide')}</span>
|
||||
<span className="contrib-field-new">{displayVal(newVal, key) ?? t('vide')}</span>
|
||||
</span>
|
||||
) : (
|
||||
<span className="contrib-field-new">{displayVal(newVal) ?? t('vide')}</span>
|
||||
<span className="contrib-field-new">{displayVal(newVal, key) ?? t('vide')}</span>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
|
||||
@@ -798,7 +798,7 @@ const Galaxy = ({ onPersonSelect, onMediaSelect, selectedPersonId, searchHighlig
|
||||
dirty = true
|
||||
lastPathInputRef.current = { selected: selectedElkId, hovered: currentHovered }
|
||||
if (selectedElkId && currentHovered && currentHovered !== selectedElkId && currentHovered.startsWith('p-')) {
|
||||
const result = findPathBFS(selectedElkId, currentHovered, layoutData)
|
||||
const result = findPathBFS(selectedElkId, currentHovered, layoutData, graphPersons)
|
||||
pathNodesRef.current = result ? result.nodePath : []
|
||||
pathEdgesRef.current = result ? result.edgePath : []
|
||||
pathLabelRef.current = result ? result.label : ''
|
||||
|
||||
@@ -292,6 +292,9 @@
|
||||
.pc-parentage { display: grid; gap: 6px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--pz-line-soft); }
|
||||
.pc-seg { width: 100%; }
|
||||
.pc-seg .pz-tab { flex: 1; }
|
||||
/* Sexe (issue #114) : étiquette au-dessus, trois choix sur toute la largeur, chacun sur une ligne */
|
||||
.pc-row--seg { flex-direction: column; align-items: stretch; gap: 6px; }
|
||||
.pc-row--seg .pz-tab { white-space: nowrap; padding: 0 8px; }
|
||||
|
||||
/* Titres de section de l'onglet Infos et Liens : casse normale, Newsreader 15 px, comme la maquette (.sec) */
|
||||
.pc-infos .pz-eyebrow { text-transform: none; letter-spacing: 0; font: 400 15px/1.3 var(--pz-serif); color: var(--pz-ink); }
|
||||
@@ -19,6 +19,7 @@ import { firstNameLabel, fullNameLabel, isFirstNameUnknown } from '../utils/pers
|
||||
import { isYearOnly } from '../utils/dateInput.js'
|
||||
import DateField from './DateField.jsx'
|
||||
import { runOnce } from '../utils/saveOnLeave.js'
|
||||
import { normalizeSex, SEX_CHOICES } from '../utils/personSex.js'
|
||||
|
||||
// Aucune modification en cours (référence stable)
|
||||
const NO_EDITS = Object.freeze({})
|
||||
@@ -319,6 +320,7 @@ const PersonCard = ({
|
||||
const birthFilled = isFilled(getEditValue('birthYear', person.birthDate || person.birthYear))
|
||||
const deathFilled = isFilled(getEditValue('deathYear', person.deathDate || person.deathYear))
|
||||
const deceasedNow = editMode ? !getEditValue('isAlive', person.isAlive) : !person.isAlive
|
||||
const editSex = normalizeSex(getEditValue('sex', person.sex))
|
||||
const notesShown = editMode && (isFilled(getEditValue('note', person.note)) || openedHas('note'))
|
||||
// En lecture : toujours visible si demandé (naissance, décès d'une personne décédée), sinon si rempli
|
||||
const infoRow = (field, label, filled, content, always = false) => {
|
||||
@@ -921,6 +923,25 @@ const PersonCard = ({
|
||||
{infoRow('birthPlace', t('Lieu'), isFilled(getEditValue('birthPlace', person.birthPlace)), renderEditableValue({ field: 'birthPlace', value: person.birthPlace || '', placeholder: t('Lieu de naissance'), format: formatPlace }))}
|
||||
{infoRow('birthName', t('Nom de naissance'), isFilled(getEditValue('birthName', person.birthName)), renderEditableValue({ field: 'birthName', value: person.birthName || '', placeholder: t('Nom de naissance') }))}
|
||||
{infoRow('nickname', t('Surnom'), isFilled(getEditValue('nickname', person.nickname)), renderEditableValue({ field: 'nickname', value: person.nickname || '', placeholder: t('Surnom') }))}
|
||||
{editMode && (
|
||||
<div className="pc-row pc-row--seg" data-pc-field="sex">
|
||||
<span className="pc-label" id="pc-sex-label">{t('Sexe')}</span>
|
||||
<div className="pz-tabs pc-seg" role="radiogroup" aria-labelledby="pc-sex-label">
|
||||
{SEX_CHOICES.map(({ value, label }) => (
|
||||
<button
|
||||
key={label}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={editSex === value}
|
||||
className={`pz-tab ${editSex === value ? 'is-active' : ''}`}
|
||||
onClick={() => handleFieldChange('sex', value)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
{editMode && (
|
||||
<div className="pc-row">
|
||||
<span className="pc-label">{t('Statut')}</span>
|
||||
@@ -930,7 +951,7 @@ const PersonCard = ({
|
||||
onClick={() => handleFieldChange('isAlive', !getEditValue('isAlive', person.isAlive))}
|
||||
>
|
||||
<span className="pc-alive-dot" />
|
||||
{getEditValue('isAlive', person.isAlive) ? t('En vie') : t('Décédé(e)')}
|
||||
{getEditValue('isAlive', person.isAlive) ? t('En vie') : editSex === 'male' ? t('Décédé') : editSex === 'female' ? t('Décédée') : t('Décédé(e)')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { coupleBarMeta } from './elkLayout'
|
||||
import { t } from '../../i18n/index.js'
|
||||
import { nameKinship, normalizeSex } from '../../utils/kinship/index.js'
|
||||
|
||||
// ============================================================
|
||||
// BFS — chemin le plus court entre deux personnes
|
||||
@@ -8,7 +8,8 @@ import { t } from '../../i18n/index.js'
|
||||
// noeuds intermédiaires invisibles ; seuls les noeuds personne
|
||||
// comptent comme "étapes".
|
||||
// ============================================================
|
||||
export function findPathBFS(fromElkId, toElkId, layoutData) {
|
||||
// persons : les personnes à jour (sexe modifié sans recalcul du placement) ; à défaut, celles du placement
|
||||
export function findPathBFS(fromElkId, toElkId, layoutData, persons = null) {
|
||||
if (!layoutData || fromElkId === toElkId) return null
|
||||
|
||||
// Construire l'adjacence
|
||||
@@ -63,78 +64,38 @@ export function findPathBFS(fromElkId, toElkId, layoutData) {
|
||||
}
|
||||
nodePath.unshift(fromElkId)
|
||||
|
||||
const label = computeRelationshipLabel(edgePath)
|
||||
return { nodePath, edgePath, label }
|
||||
const personById = persons
|
||||
? new Map(persons.map((person) => [`p-${person.id}`, person]))
|
||||
: new Map((layoutData.children || []).filter((node) => node._type === 'person').map((node) => [node.id, node._data]))
|
||||
const kinship = kinshipPath(edgePath, nodePath, (id) => personById.get(id))
|
||||
return { nodePath, edgePath, kinship, label: nameKinship(kinship) }
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Calcul du lien de parenté à partir du chemin BFS
|
||||
// On analyse la direction à chaque union traversée :
|
||||
// filiation→couple = UP (enfant → parent)
|
||||
// couple→filiation = DOWN (parent → enfant)
|
||||
// filiation→filiation = SIBLING (frères/sœurs, +1 up +1 down)
|
||||
// couple→couple = SPOUSE (conjoints)
|
||||
// Puis (ups, downs) donne le degré de parenté.
|
||||
// Chemin de parenté complet, à partir du chemin BFS
|
||||
// On lit la direction à chaque union traversée :
|
||||
// filiation→couple = 'up' (enfant → parent)
|
||||
// couple→filiation = 'down' (parent → enfant)
|
||||
// filiation→filiation = 'sibling' (frère ou sœur)
|
||||
// couple→couple = 'spouse' (conjoint)
|
||||
// Chaque pas garde la personne atteinte (sexe, année de naissance) :
|
||||
// le nommage, langue par langue, est dans utils/kinship.
|
||||
// ============================================================
|
||||
export function computeRelationshipLabel(edgePath) {
|
||||
if (edgePath.length < 2) return ''
|
||||
const MOVES = { 'filiation>couple': 'up', 'couple>filiation': 'down', 'filiation>filiation': 'sibling', 'couple>couple': 'spouse' }
|
||||
|
||||
let ups = 0, downs = 0, hasSpouse = false
|
||||
const personFacts = (data, id) => ({ id: data?.id ?? id, sex: normalizeSex(data?.sex), birthYear: data?.birthYear ?? null })
|
||||
|
||||
for (let i = 0; i < edgePath.length; i += 2) {
|
||||
if (i + 1 >= edgePath.length) break
|
||||
const entering = edgePath[i].type
|
||||
const leaving = edgePath[i + 1].type
|
||||
if (entering === 'couple' && leaving === 'couple') hasSpouse = true
|
||||
else if (entering === 'couple' && leaving === 'filiation') downs++
|
||||
else if (entering === 'filiation' && leaving === 'couple') ups++
|
||||
else if (entering === 'filiation' && leaving === 'filiation') { ups++; downs++ }
|
||||
export function kinshipPath(edgePath, nodePath = [], personOf = () => null) {
|
||||
if (edgePath.length < 2) return null
|
||||
const steps = []
|
||||
for (let i = 0; i + 1 < edgePath.length; i += 2) {
|
||||
const move = MOVES[`${edgePath[i].type}>${edgePath[i + 1].type}`]
|
||||
const id = nodePath[i + 2]
|
||||
steps.push({ move, person: personFacts(personOf(id), id) })
|
||||
}
|
||||
return { from: personFacts(personOf(nodePath[0]), nodePath[0]), steps }
|
||||
}
|
||||
|
||||
// Conjoint direct
|
||||
if (hasSpouse && ups === 0 && downs === 0) return t('Conjoint(e)')
|
||||
|
||||
// In-laws courants
|
||||
if (hasSpouse) {
|
||||
if (ups === 1 && downs === 0) return t('Beau-parent')
|
||||
if (ups === 0 && downs === 1) return t('Bel-enfant')
|
||||
if (ups === 1 && downs === 1) return t('Beau-frère/sœur')
|
||||
}
|
||||
|
||||
// Ascendants directs
|
||||
let label
|
||||
if (downs === 0 && ups > 0) {
|
||||
if (ups === 1) label = t('Parent')
|
||||
else if (ups === 2) label = t('Grand-parent')
|
||||
else if (ups === 3) label = t('Arrière-grand-parent')
|
||||
else label = t('Aïeul(e) {n}e gén.', { n: ups })
|
||||
}
|
||||
// Descendants directs
|
||||
else if (ups === 0 && downs > 0) {
|
||||
if (downs === 1) label = t('Enfant')
|
||||
else if (downs === 2) label = t('Petit-enfant')
|
||||
else if (downs === 3) label = t('Arrière-petit-enfant')
|
||||
else label = t('Descendant(e) {n}e gén.', { n: downs })
|
||||
}
|
||||
// Fratrie
|
||||
else if (ups === 1 && downs === 1) { label = t('Frère/Sœur') }
|
||||
// Oncle / Tante
|
||||
else if (ups === 2 && downs === 1) { label = t('Oncle/Tante') }
|
||||
else if (ups === 3 && downs === 1) { label = t('Grand-oncle/tante') }
|
||||
// Neveu / Nièce
|
||||
else if (ups === 1 && downs === 2) { label = t('Neveu/Nièce') }
|
||||
else if (ups === 1 && downs === 3) { label = t('Petit-neveu/nièce') }
|
||||
// Cousins
|
||||
else if (ups >= 2 && downs >= 2) {
|
||||
const degree = Math.min(ups, downs) - 1
|
||||
const removed = Math.abs(ups - downs)
|
||||
if (degree === 1 && removed === 0) label = t('Cousin(e) germain(e)')
|
||||
else if (degree === 1) label = t('Petit-cousin(e)')
|
||||
else if (removed === 0) label = t('Cousin(e) {n}e degré', { n: degree })
|
||||
else label = t('Cousin(e) éloigné(e)')
|
||||
}
|
||||
else { label = t('{n} liens', { n: ups + downs }) }
|
||||
|
||||
if (hasSpouse && label) label = t('{label} par alliance', { label })
|
||||
return label
|
||||
export function computeRelationshipLabel(edgePath, nodePath, personOf) {
|
||||
return nameKinship(kinshipPath(edgePath, nodePath, personOf))
|
||||
}
|
||||
Reference in new issue
Block a user