Cleanup tool: "mark deceased by a child's birth year" rule
Adds a preview/apply rule to the Cleanup tool for parents who have NO birth date
of their own (so the existing born-on-or-before rule can't reach them) but who
have a child born long ago — they're necessarily deceased. This is the gap that
left ~56 parents in the Paul tree as "unknown".
- cleanup_service.preview_deceased_by_child(year): parents of any child born
on/before the cutoff, excluding already-deceased; returns child_birth_year.
- GET /trees/{id}/cleanup/deceased-by-child?born_on_or_before=1900. Apply reuses
the existing POST .../cleanup/deceased (same audited mark-deceased path).
- Frontend: a new card in the Cleanup tool (year input → preview → select →
apply), preview-first like the rest of the tool.
Test covers preview (finds the no-birthdate parent of a pre-cutoff child,
excludes modern-child parents), child_birth_year, apply, and re-preview drop.
Suite 106 passing.
Signed-off-by: Justin Paul <justin@jpaul.me>
This commit is contained in:
@@ -10,6 +10,7 @@ import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Input } from "@/components/ui/input";
|
||||
|
||||
type Deceased = components["schemas"]["DeceasedCandidate"];
|
||||
type DeceasedByChild = components["schemas"]["DeceasedByChildCandidate"];
|
||||
type GenderProp = components["schemas"]["GenderProposal"];
|
||||
type NameIssue = components["schemas"]["NameIssue"];
|
||||
type Person = components["schemas"]["PersonRead"];
|
||||
@@ -31,6 +32,12 @@ export default function CleanupPage() {
|
||||
const [decSel, setDecSel] = useState<Set<string>>(new Set());
|
||||
const [decMsg, setDecMsg] = useState<string | null>(null);
|
||||
|
||||
// 1b) Deceased by a child's birth year (for parents with no birth date)
|
||||
const [childYear, setChildYear] = useState(1900);
|
||||
const [decByChild, setDecByChild] = useState<DeceasedByChild[] | null>(null);
|
||||
const [dbcSel, setDbcSel] = useState<Set<string>>(new Set());
|
||||
const [dbcMsg, setDbcMsg] = useState<string | null>(null);
|
||||
|
||||
// 2) Gender from source GEDCOM
|
||||
const [gender, setGender] = useState<GenderProp[] | null>(null);
|
||||
const [genSel, setGenSel] = useState<Set<string>>(new Set());
|
||||
@@ -63,6 +70,23 @@ export default function CleanupPage() {
|
||||
setDeceased(null);
|
||||
}
|
||||
|
||||
async function previewDeceasedByChild() {
|
||||
setDbcMsg(null);
|
||||
const { data } = await api.GET("/api/v1/trees/{tree_id}/cleanup/deceased-by-child", {
|
||||
params: { path: { tree_id: treeId }, query: { born_on_or_before: childYear } },
|
||||
});
|
||||
setDecByChild(data ?? []);
|
||||
setDbcSel(new Set((data ?? []).map((d) => d.person_id)));
|
||||
}
|
||||
async function applyDeceasedByChild() {
|
||||
const { data } = await api.POST("/api/v1/trees/{tree_id}/cleanup/deceased", {
|
||||
params: { path: { tree_id: treeId } },
|
||||
body: { person_ids: [...dbcSel] },
|
||||
});
|
||||
setDbcMsg(`Marked ${data?.updated ?? 0} people deceased.`);
|
||||
setDecByChild(null);
|
||||
}
|
||||
|
||||
async function previewGender(e: React.ChangeEvent<HTMLInputElement>) {
|
||||
const file = e.target.files?.[0];
|
||||
if (genFile.current) genFile.current.value = "";
|
||||
@@ -231,6 +255,59 @@ export default function CleanupPage() {
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 1b) Deceased by a child's birth year */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="text-base">Mark deceased by a child’s birth year</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent className="space-y-3">
|
||||
<p className="text-sm text-[var(--muted)]">
|
||||
Catches parents who have <strong>no birth date of their own</strong> (so the rule
|
||||
above can’t reach them) but who have a child born long ago — they’re necessarily
|
||||
deceased.
|
||||
</p>
|
||||
<div className="flex flex-wrap items-end gap-2">
|
||||
<label className="flex flex-col gap-1 text-sm">
|
||||
<span className="text-xs text-[var(--muted)]">Has a child born on or before</span>
|
||||
<Input
|
||||
type="number"
|
||||
className="w-28"
|
||||
value={childYear}
|
||||
onChange={(e) => setChildYear(Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
<Button variant="outline" onClick={previewDeceasedByChild}>
|
||||
Preview
|
||||
</Button>
|
||||
</div>
|
||||
{dbcMsg && <p className="text-sm text-bronze">{dbcMsg}</p>}
|
||||
{decByChild && (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-[var(--muted)]">
|
||||
{decByChild.length} people with a child born ≤ {childYear} (not already marked
|
||||
deceased).
|
||||
</p>
|
||||
<ul className="max-h-64 divide-y divide-[var(--border)] overflow-auto rounded-lg border border-[var(--border)]">
|
||||
{decByChild.map((d) => (
|
||||
<li key={d.person_id} className="flex items-center gap-3 px-3 py-1.5 text-sm">
|
||||
<input
|
||||
type="checkbox"
|
||||
checked={dbcSel.has(d.person_id)}
|
||||
onChange={() => toggle(dbcSel, d.person_id, setDbcSel)}
|
||||
/>
|
||||
<span className="flex-1">{d.name}</span>
|
||||
<span className="text-xs text-[var(--muted)]">child b. {d.child_birth_year}</span>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
{decByChild.length > 0 && (
|
||||
<Button onClick={applyDeceasedByChild}>Mark {dbcSel.size} deceased</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 2) Gender from source */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
|
||||
Vendored
+66
@@ -718,6 +718,27 @@ export interface paths {
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/trees/{tree_id}/cleanup/deceased-by-child": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
header?: never;
|
||||
path?: never;
|
||||
cookie?: never;
|
||||
};
|
||||
/**
|
||||
* Preview Deceased By Child
|
||||
* @description People with a child born on/before the cutoff — necessarily deceased even
|
||||
* when their own birth date is missing. Apply via POST .../cleanup/deceased.
|
||||
*/
|
||||
get: operations["preview_deceased_by_child_api_v1_trees__tree_id__cleanup_deceased_by_child_get"];
|
||||
put?: never;
|
||||
post?: never;
|
||||
delete?: never;
|
||||
options?: never;
|
||||
head?: never;
|
||||
patch?: never;
|
||||
trace?: never;
|
||||
};
|
||||
"/api/v1/trees/{tree_id}/cleanup/gender/preview": {
|
||||
parameters: {
|
||||
query?: never;
|
||||
@@ -1286,6 +1307,18 @@ export interface components {
|
||||
/** Person Ids */
|
||||
person_ids: string[];
|
||||
};
|
||||
/** DeceasedByChildCandidate */
|
||||
DeceasedByChildCandidate: {
|
||||
/**
|
||||
* Person Id
|
||||
* Format: uuid
|
||||
*/
|
||||
person_id: string;
|
||||
/** Name */
|
||||
name: string;
|
||||
/** Child Birth Year */
|
||||
child_birth_year: number;
|
||||
};
|
||||
/** DeceasedCandidate */
|
||||
DeceasedCandidate: {
|
||||
/**
|
||||
@@ -4013,6 +4046,39 @@ export interface operations {
|
||||
};
|
||||
};
|
||||
};
|
||||
preview_deceased_by_child_api_v1_trees__tree_id__cleanup_deceased_by_child_get: {
|
||||
parameters: {
|
||||
query?: {
|
||||
born_on_or_before?: number;
|
||||
};
|
||||
header?: never;
|
||||
path: {
|
||||
tree_id: string;
|
||||
};
|
||||
cookie?: never;
|
||||
};
|
||||
requestBody?: never;
|
||||
responses: {
|
||||
/** @description Successful Response */
|
||||
200: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["DeceasedByChildCandidate"][];
|
||||
};
|
||||
};
|
||||
/** @description Validation Error */
|
||||
422: {
|
||||
headers: {
|
||||
[name: string]: unknown;
|
||||
};
|
||||
content: {
|
||||
"application/json": components["schemas"]["HTTPValidationError"];
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
preview_gender_api_v1_trees__tree_id__cleanup_gender_preview_post: {
|
||||
parameters: {
|
||||
query?: never;
|
||||
|
||||
@@ -2873,6 +2873,64 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/trees/{tree_id}/cleanup/deceased-by-child": {
|
||||
"get": {
|
||||
"tags": [
|
||||
"cleanup"
|
||||
],
|
||||
"summary": "Preview Deceased By Child",
|
||||
"description": "People with a child born on/before the cutoff \u2014 necessarily deceased even\nwhen their own birth date is missing. Apply via POST .../cleanup/deceased.",
|
||||
"operationId": "preview_deceased_by_child_api_v1_trees__tree_id__cleanup_deceased_by_child_get",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "tree_id",
|
||||
"in": "path",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"title": "Tree Id"
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "born_on_or_before",
|
||||
"in": "query",
|
||||
"required": false,
|
||||
"schema": {
|
||||
"type": "integer",
|
||||
"default": 1900,
|
||||
"title": "Born On Or Before"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Successful Response",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/components/schemas/DeceasedByChildCandidate"
|
||||
},
|
||||
"title": "Response Preview Deceased By Child Api V1 Trees Tree Id Cleanup Deceased By Child Get"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"422": {
|
||||
"description": "Validation Error",
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/components/schemas/HTTPValidationError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/v1/trees/{tree_id}/cleanup/gender/preview": {
|
||||
"post": {
|
||||
"tags": [
|
||||
@@ -4897,6 +4955,30 @@
|
||||
],
|
||||
"title": "DeceasedApply"
|
||||
},
|
||||
"DeceasedByChildCandidate": {
|
||||
"properties": {
|
||||
"person_id": {
|
||||
"type": "string",
|
||||
"format": "uuid",
|
||||
"title": "Person Id"
|
||||
},
|
||||
"name": {
|
||||
"type": "string",
|
||||
"title": "Name"
|
||||
},
|
||||
"child_birth_year": {
|
||||
"type": "integer",
|
||||
"title": "Child Birth Year"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"required": [
|
||||
"person_id",
|
||||
"name",
|
||||
"child_birth_year"
|
||||
],
|
||||
"title": "DeceasedByChildCandidate"
|
||||
},
|
||||
"DeceasedCandidate": {
|
||||
"properties": {
|
||||
"person_id": {
|
||||
|
||||
Reference in New Issue
Block a user