From 4020a8b78e82eff64d4631418c1b0d976e692df8 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Mon, 21 Sep 2026 23:37:30 -0400 Subject: [PATCH] Recount the ledger after an undo, and after every operation The effect that recounts the selection is keyed on `slices`, and neither an undo nor an operation changes the selection -- so the panel went on showing totals that included rows it had just removed, or excluded rows it had just written. Only scale refreshed, and only for itself. Undo now re-reads the log as well, since the walk lines come from there: an undone entry has to leave the ledger and not just the table. It runs after the remove resolves, because fetchCurrentTotals counts through the table's own views and would otherwise count what was being deleted. It reads slicesRef rather than slices, being inside a handler registered once. Co-Authored-By: Claude Opus 5 (1M context) --- ui/src/views/Forecast.jsx | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ui/src/views/Forecast.jsx b/ui/src/views/Forecast.jsx index 45cbb7a..ee42df7 100644 --- a/ui/src/views/Forecast.jsx +++ b/ui/src/views/Forecast.jsx @@ -1622,7 +1622,13 @@ export default function Forecast({ sources = [], sourceId, versions = [], versio window.dispatchEvent(new CustomEvent('pf-data-changed')) refreshLogMeta(versionId) if (opTag.trim()) refreshTags(versionId) - if (op === 'scale') { setScaleInputs({}); setScaleNote(''); fetchCurrentTotals(slices) } + // Every operation changes what the selection holds, so every operation + // has to re-count it. This used to fire for scale alone, and a recode or + // clone left the ledger showing the totals from before it ran -- the + // effect that normally recounts is keyed on `slices`, and none of these + // change the selection. + fetchCurrentTotals(slices) + if (op === 'scale') { setScaleInputs({}); setScaleNote('') } if (op === 'recode') { setRecodeNote('') } if (op === 'clone') { setCloneNote(''); setCloneScale('1') } } catch (err) { @@ -1821,6 +1827,15 @@ export default function Forecast({ sources = [], sourceId, versions = [], versio if (removed?.length && tableRef.current) { await tableRef.current.remove(removed) } + // Recount the selection, now the rows are actually gone. Undone after the + // remove, not beside it: fetchCurrentTotals reads the table through its + // own views, so running it first would count what was just deleted. + // + // The walk lines come from the log, so that is re-read too -- an undone + // entry has to leave the ledger as well as the table. + window.dispatchEvent(new CustomEvent('pf-data-changed')) + refreshLogMeta(versionId) + if (slicesRef.current.length) fetchCurrentTotals(slicesRef.current) flash(`Undone — ${data.rows_deleted} rows removed`) } catch (err) { flash(err.message, 'error')