fix(export): default group-by to None when unset/stale; polish
Final code review of the configurable-data-export feature: ExperimentDetail was forwarding its on-page groupField state (defaults to '__name__') into ExportDataModal, leaking a clustering default into the default (untouched) export. Now passes the raw saved localStorage value, defaulting to '__none__'. The modal also now validates the incoming groupField against '__none__'/'__name__'/'__id__'/active subjectTemplate fields and coerces to '__none__' otherwise, guarding against stale/deleted subject_info fields. Plus a stale module comment fix and optional-chaining consistency fix in listSubjectMembers. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -31,7 +31,11 @@ export default function ExportDataModal({
|
||||
const [rowDim, setRowDim] = useState('date');
|
||||
const [colDim, setColDim] = useState('subject');
|
||||
const [pinnedId, setPinnedId] = useState(null);
|
||||
const [groupBy, setGroupBy] = useState(groupField ?? '__none__');
|
||||
const [groupBy, setGroupBy] = useState(() => {
|
||||
const valid = groupField === '__none__' || groupField === '__name__' || groupField === '__id__'
|
||||
|| subjectTemplate.some((f) => f.active && f.fieldId === groupField);
|
||||
return valid ? groupField : '__none__';
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
// Pure helpers for exporting daily-parameter data as a date×subject CSV matrix.
|
||||
// Pure helpers for exporting daily-parameter data as a CSV matrix. buildMatrix is
|
||||
// dimension-agnostic: rows and columns are assignable to Date/Subject/Parameter,
|
||||
// with the leftover dimension pinned to a single value.
|
||||
// No React, no I/O — mirrors the crossSubjectChart.js pure-helper pattern.
|
||||
|
||||
// Read a single parameter's raw value from one daily status.
|
||||
@@ -112,7 +114,7 @@ export function listSubjectMembers(animals, groupField) {
|
||||
const members = list.map((a) => {
|
||||
const name = a?.animal_name ?? '';
|
||||
const label = nameCounts.get(name) > 1 ? `${name} (${a?.animal_id_string ?? ''})` : name;
|
||||
return { id: a.id, label, animalId: a.id, group: subjectGroupValue(a, groupField) };
|
||||
return { id: a?.id, label, animalId: a?.id, group: subjectGroupValue(a, groupField) };
|
||||
});
|
||||
const grouped = !!groupField && groupField !== '__none__';
|
||||
members.sort((x, y) => {
|
||||
|
||||
@@ -417,7 +417,7 @@ export default function ExperimentDetail() {
|
||||
dailyTemplate={dailyTemplate}
|
||||
animals={animals}
|
||||
subjectTemplate={subjectTemplate}
|
||||
groupField={groupField}
|
||||
groupField={localStorage.getItem(`exp-subject-group-${id}`) ?? '__none__'}
|
||||
onClose={() => setShowExport(false)}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
Reference in New Issue
Block a user