Salud: reset one measurement, without losing the rest
Tests / test (push) Canceled after 0s
Publish Docker images / build (., ./web/Dockerfile, web) (push) Canceled after 0s
Publish Docker images / build (./api, ./api/Dockerfile, api) (push) Canceled after 0s

"Podemos reiniciar los números de esas mediciones para yo enviar el de hoy." The whole-file reset
already existed two taps away in the setup sheet, but it is the wrong size for the question: the
four metrics he suspects are not the profile. Throwing away a month of heart rate to start steps
over is not a reset, it is a tax.

So a metric can now be forgotten on its own: the detail sheet has **Reset this measurement**, which
deletes that metric's days (and hours) and nothing else — the other metrics, the workouts and the
ingest key stay. With any Date Range wider than a day the phone re-sends that metric on its next
sync, which is what makes this a reset rather than a loss: Apple Health still has the data, and a
day total replaces the day it names, so the stored past is rewritten rather than duplicated.

The two destructive rows are worded apart on purpose and the confirm names the metric ("¿Reiniciar
Pasos?"), because the neighbouring action in the setup sheet takes every metric there is.

`dropMetric()` is pure and returns how many days it took, and the route answers `metric: null` for
a metric the profile does not have (or a profile with no health file at all) instead of an error —
a screen that says "nothing stored" is more useful than a 404 answering a button press. Tested
from both ends: the helper's purity and arithmetic, the route against a real server (one metric
gone, the others and the workouts intact, the key still working, and a re-sync rebuilding it), and
the sheet's flow through the real confirm. Mutation-checked: pointing the row at the whole-file
delete fails it.
This commit is contained in:
dsantillan committed 2026-09-23 16:18:28 -04:00
1 parent d93861a73f
commit 5c69540f62
11 files changed
+209 -7

No files matched your search

+1
View File
@@ -34,6 +34,7 @@ const LABELS = {
'auth.health.key.create': 'Created a health ingest key',
'auth.health.key.rotate': 'Replaced the health ingest key',
'auth.health.clear': 'Deleted their health data',
'auth.health.metric.clear': 'Reset one health metric',
'admin.user.disable': 'Disabled an account',
'admin.user.enable': 'Re-enabled an account',
'admin.user.delete': 'Deleted an account',
+9
View File
@@ -1403,6 +1403,15 @@ export default {
'Replace the key': 'Reemplazar la clave',
'The old one stops working immediately': 'La anterior deja de funcionar al instante',
'Delete the health data': 'Borrar los datos de salud',
// resetting one measurement, from its own detail sheet
'Reset this measurement': 'Reiniciar esta medición',
'Your next sync from the iPhone rebuilds it': 'El próximo envío desde el iPhone la reconstruye',
'Resetting removes every day stored for this metric and nothing else: your other metrics, your workouts and your ingest key stay. With a Date Range of a week or more, the next sync sends it again from Apple Health.': 'Reiniciar borra todos los días guardados de esta métrica y nada más: tus otras métricas, tus entrenamientos y tu clave de ingesta se quedan. Con un rango de fechas de una semana o más, el próximo envío la manda otra vez desde Apple Health.',
'Reset {0}?': '¿Reiniciar {0}?',
'Every day stored for this metric is removed for this profile. Nothing else is touched, and your next sync from the iPhone sends it again.': 'Se borran todos los días guardados de esta métrica en este perfil. No se toca nada más, y tu próximo envío desde el iPhone la manda de nuevo.',
'Reset': 'Reiniciar',
'{0} reset': '{0} reiniciada',
'Nothing stored for {0}': 'No hay nada guardado de {0}',
'Keeps your workouts and your key': 'Conserva tus entrenamientos y tu clave',
'Replace the ingest key?': '¿Reemplazar la clave de ingesta?',
'Your iPhone stops syncing until you paste the new key into Health Auto Export. Nothing already stored is lost.': 'Tu iPhone deja de sincronizar hasta que pegues la nueva clave en Health Auto Export. No se pierde nada de lo ya guardado.',
+32 -2
View File
@@ -104,7 +104,7 @@ function MetricCard({ card, onOpen }) {
* automation groups by Day never pays for it — and the sheet says why the list is missing instead
* of leaving a gap where a chart should be.
*/
function MetricSheet({ card, metric, close }) {
function MetricSheet({ card, metric, close, onReset }) {
const rows = detailRows(card, undefined, metric)
const tr = trendOf(card)
const [day, setDay] = useState(card.day)
@@ -176,6 +176,19 @@ function MetricSheet({ card, metric, close }) {
{t('{0} days with data in this range', card.days)}
{card.sources.length ? ' · ' + card.sources.join(', ') : ''}
</div>
{/* Starting one measurement over, not the whole profile. The two rows that can delete health
data are worded so they cannot be confused: this one names the metric it resets, and the
one in the setup sheet says it takes everything. */}
<h4 className="sec">{t('Manage')}</h4>
<div className="list">
<Row icon="trash" iconTint="var(--red)" title={t('Reset this measurement')}
subtitle={t('Your next sync from the iPhone rebuilds it')} accessory="chevron"
onClick={() => onReset(card)} />
</div>
<div className="small dim" style={{ marginTop: 10, lineHeight: 1.5 }}>
{t('Resetting removes every day stored for this metric and nothing else: your other metrics, your workouts and your ingest key stay. With a Date Range of a week or more, the next sync sends it again from Apple Health.')}
</div>
<div style={{ height: 12 }} />
<Button onClick={close}>{t('Close')}</Button>
</>
@@ -322,8 +335,25 @@ export default function Health() {
.catch(e => toast(e.message))
})
/* One metric, back to nothing — the answer to "these numbers look wrong, start them over". The
confirm names the metric, because the neighbouring "Delete the health data" in the setup sheet
takes all of them and the two must not look alike. */
const resetMetric = (card, close) => confirmSheet({
title: t('Reset {0}?', card.label),
message: t('Every day stored for this metric is removed for this profile. Nothing else is touched, and your next sync from the iPhone sends it again.'),
confirmText: t('Reset'), danger: true,
onConfirm: () => api('/api/vitals?metric=' + encodeURIComponent(card.name), { method: 'DELETE' })
.then(r => {
close()
load()
toast(r && r.metric ? t('{0} reset', card.label) : t('Nothing stored for {0}', card.label))
})
.catch(e => toast(e.message))
})
const setup = () => openSheet(close => <SetupSheet initialKey={data?.key} onKey={key} onRotate={rotate} onDelete={wipe} close={close} />)
const openMetric = card => openSheet(close => <MetricSheet card={card} metric={data.metrics[card.name]} close={close} />)
const openMetric = card => openSheet(close => <MetricSheet card={card} metric={data.metrics[card.name]} close={close}
onReset={c => resetMetric(c, close)} />)
/* Guest mode keeps everything in this browser and never talks to a server, so there is nothing
for a phone to post to. Saying so once is friendlier than a 401 the visitor cannot act on. */
+35
View File
@@ -276,6 +276,41 @@ describe('the detail sheet', () => {
expect(sheet()).toContain('9,000')
})
it('resets one measurement from its own sheet, and names what it is resetting', async () => {
const calls = []
api.mockImplementation(async (path, opts) => {
calls.push([path, opts && opts.method])
if (path.startsWith('/api/vitals/hours')) return HOURS
if (path.startsWith('/api/vitals?metric=')) return { ok: true, metric: 'step_count', days: 3 }
if (path.startsWith('/api/vitals?')) return withHours()
throw new Error('unexpected ' + path)
})
const { confirmSheet } = await import('../sheets.jsx')
confirmSheet.mockClear()
await mountWithSheets()
openSteps()
await act(async () => {})
expect(sheet()).toContain('Reset this measurement')
click([...sheetEl().querySelectorAll('button')].find(b => b.textContent.includes('Reset this measurement')))
await act(async () => {})
// The question names the metric. Its neighbour, "Delete the health data" in the setup sheet,
// takes every metric there is, and the two must not be mistakable for each other.
const opts = confirmSheet.mock.calls.at(-1)[0]
expect(opts.title).toContain('Steps')
expect(opts.danger).toBe(true)
expect(opts.message).toContain('Nothing else is touched')
await act(async () => { opts.onConfirm() })
await act(async () => {})
// One metric, by name — never the profile's whole health file.
expect(calls).toContainEqual(['/api/vitals?metric=step_count', 'DELETE'])
expect(calls).not.toContainEqual(['/api/vitals', 'DELETE'])
// ...and the screen reloads what is left.
expect(calls.filter(([p]) => p === '/api/vitals?days=7').length).toBeGreaterThan(1)
})
it('moves the hour list to a day that has hours when that day is tapped', async () => {
const byDay = {
'2026-09-03': HOURS,