feat(frontend): persist bucket config to animal on successful analysis
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -3,7 +3,7 @@ import { parseCSVHeaders, parseCSV, getUniqueNoteValues, runAnalysis, checkFrame
|
|||||||
import {
|
import {
|
||||||
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer,
|
LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer,
|
||||||
} from 'recharts';
|
} from 'recharts';
|
||||||
import { analysesApi, dailyStatusesApi } from '../api/client';
|
import { analysesApi, dailyStatusesApi, animalsApi } from '../api/client';
|
||||||
import Button from './ui/Button';
|
import Button from './ui/Button';
|
||||||
import RunSequenceView from './RunSequenceView';
|
import RunSequenceView from './RunSequenceView';
|
||||||
|
|
||||||
@@ -167,6 +167,7 @@ export default function CsvAnalysis({ dailyStatusId, animal, onSaved, onSummaryP
|
|||||||
const [summaryPushing, setSummaryPushing] = useState(false);
|
const [summaryPushing, setSummaryPushing] = useState(false);
|
||||||
const [summaryPushed, setSummaryPushed] = useState(false);
|
const [summaryPushed, setSummaryPushed] = useState(false);
|
||||||
const [summaryError, setSummaryError] = useState(null);
|
const [summaryError, setSummaryError] = useState(null);
|
||||||
|
const [configSaveError, setConfigSaveError] = useState(null);
|
||||||
|
|
||||||
// ── File reading ─────────────────────────────────────────────────────────────
|
// ── File reading ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
@@ -265,6 +266,14 @@ export default function CsvAnalysis({ dailyStatusId, animal, onSaved, onSummaryP
|
|||||||
setResults({ ...res, numericSeries });
|
setResults({ ...res, numericSeries });
|
||||||
setPhase('results');
|
setPhase('results');
|
||||||
|
|
||||||
|
// Persist bucket config to the animal so future uploads pre-classify.
|
||||||
|
// Independent of dailyStatusId — runs even for ad-hoc analyses.
|
||||||
|
if (animal?.id) {
|
||||||
|
setConfigSaveError(null);
|
||||||
|
animalsApi.updateCsvConfig(animal.id, { buckets })
|
||||||
|
.catch((err) => setConfigSaveError(err.message ?? 'Failed to save bucket config'));
|
||||||
|
}
|
||||||
|
|
||||||
if (!dailyStatusId) return;
|
if (!dailyStatusId) return;
|
||||||
setSaving(true);
|
setSaving(true);
|
||||||
setSaveError(null);
|
setSaveError(null);
|
||||||
@@ -719,6 +728,11 @@ export default function CsvAnalysis({ dailyStatusId, animal, onSaved, onSummaryP
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{configSaveError && (
|
||||||
|
<p className="text-xs text-amber-600 bg-amber-50 border border-amber-200 rounded px-3 py-1.5">
|
||||||
|
Bucket config didn't save: {configSaveError}. Analysis still ran. Try running again to retry.
|
||||||
|
</p>
|
||||||
|
)}
|
||||||
<div className="flex gap-3 pt-2 border-t border-gray-100">
|
<div className="flex gap-3 pt-2 border-t border-gray-100">
|
||||||
<Button variant="secondary" onClick={() => setPhase('classify')}>← Reclassify</Button>
|
<Button variant="secondary" onClick={() => setPhase('classify')}>← Reclassify</Button>
|
||||||
<Button variant="secondary" onClick={reset}>Start over</Button>
|
<Button variant="secondary" onClick={reset}>Start over</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user