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:
Experiments DB Dev
2026-07-19 13:59:48 -04:00
parent e65de8892a
commit 9b3d52d89b
5 changed files with 101 additions and 4 deletions
+19
View File
@@ -136,6 +136,25 @@ describe('buildMatrix', () => {
{ statuses: gStatuses, animals: gAnimals, dailyTemplate });
expect(m.columns.map((c) => c.label)).not.toContain('X');
});
it('neither axis is Subject: drops a blank date row and a blank parameter column together', () => {
// Subject is pinned (rowDim=date, colDim=parameter). Both drop-blank filters engage:
// 07-02 has no data at all (row dropped), and the custom field X never has data (column dropped).
const dailyTemplate = [{ fieldId: 'c-x', key: 'x', label: 'X', builtin: false, active: true }];
const statuses = [
{ animal_id: 'a1', date: '2026-07-01T00:00:00.000Z', analysis_summary: { total: 5, success_rate: 0.5 } },
{ animal_id: 'a1', date: '2026-07-02T00:00:00.000Z', analysis_summary: null },
];
const subjectMember = { id: 'a1', label: 'Alpha', animalId: 'a1' };
const m = buildMatrix(
{ rowDim: 'date', colDim: 'parameter', pinnedMember: subjectMember, groupField: '__none__' },
{ statuses, animals: gAnimals, dailyTemplate },
);
expect(m.groupAxis).toBeNull();
expect(m.rows.map((r) => r.member.label)).toEqual(['2026-07-01']);
expect(m.columns.map((c) => c.label)).not.toContain('X');
expect(m.columns.map((c) => c.label)).toEqual(['Total attempts', 'Success rate']);
});
});
import { toCSV, csvFilename } from '../src/lib/dataExport';