Salud: one grid, every metric the same card
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
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
"Pasos, energía activa, horas de pie, tiempo de ejercicio se ven una sola tarjeta por fila y se ven grande; debe ser igual que las demás." That was the "Trends" section: the first four metrics in catalogue order drawn as full-width panels with a big chart and the window's own min/avg/high, with those four taken out of the grid below so nothing was drawn twice. It was a bad idea for two reasons. Four huge cards, one per row, above a tidy grid of small ones read as two screens stapled together — which is exactly what was reported. And the four it picked are the four most people open this screen for, so the grid looked like it was missing its own headline metrics: Steps was a panel *instead of* a card. Every metric is now one card in one grid, two to a row, with its sparkline; the chart worth reading is one tap away in the detail sheet, where it also has the hours and the day-by-day numbers around it. That makes `trendCards` and `seriesStats` unused, so they and their tests are gone with the section, along with the `.vh-charts` / `.vh-tchart*` rules that only it used. The render test now asserts the grid holds *every* metric (5 of 5 in the fixture, labels included), that no `.vh-tchart` is rendered anywhere, and that no "Trends" heading is left behind. Checked against the old behaviour by holding one metric back out of the grid: four tests fail.
This commit is contained in:
1 parent
3c88e3c188
commit
d93861a73f
6 files changed
+44
-118
No files matched your search
@@ -1404,22 +1404,10 @@ body.chips-dragging *{cursor:inherit}
|
||||
/* --- the chart panels -----------------------------------------------------
|
||||
Full-width panels for the few metrics people open this screen for. Same `--tint` contract as
|
||||
the tiles, so a panel and its card are recognisably the same metric. */
|
||||
.vh-charts{display:flex;flex-direction:column;gap:10px;margin-bottom:14px}
|
||||
.vh-tchart{--tint:var(--grey);width:100%;text-align:left;display:block;font:inherit;color:inherit;
|
||||
padding:12px 10px 6px;background:color-mix(in srgb,var(--tint) 9%,var(--glass));
|
||||
border:var(--hair) solid color-mix(in srgb,var(--tint) 20%,transparent);
|
||||
-webkit-backdrop-filter:blur(10px) saturate(140%);backdrop-filter:blur(10px) saturate(140%)}
|
||||
.vh-tchart:active{background:color-mix(in srgb,var(--tint) 14%,var(--glass))}
|
||||
/* Deliberately NO opaque fallback where backdrop-filter is missing, unlike the tab bar. The bar
|
||||
floats over scrolling content, where a see-through panel would put text on text; a card sits in
|
||||
the page flow, and the only thing behind it is the aura. Losing the blur there costs nothing, and
|
||||
the opaque fallback is exactly what made these cards look solid on a device that took it. */
|
||||
.vh-tchart-hd{display:flex;align-items:baseline;justify-content:space-between;gap:10px;padding:0 2px;margin-bottom:2px}
|
||||
.vh-tchart-t{display:flex;align-items:center;gap:5px;font-size:14px;font-weight:500;color:var(--label-2)}
|
||||
.vh-tchart-t .icn{font-size:15px;color:var(--tint)}
|
||||
.vh-tchart-v{font-size:22px;font-weight:600;letter-spacing:-.022em;color:var(--tint);font-variant-numeric:tabular-nums}
|
||||
.vh-tchart-v i{margin-left:3px;font-size:12px;font-weight:500;font-style:normal;color:var(--label-2)}
|
||||
.vh-tchart-ft{display:flex;gap:12px;padding:0 2px;margin-top:1px;font-size:11.5px;color:var(--label-3);font-variant-numeric:tabular-nums}
|
||||
.vh-window{font-weight:400;color:var(--label-3);text-transform:none;letter-spacing:0}
|
||||
|
||||
.vh-sheet-top{margin:2px 0 12px}
|
||||
|
||||
@@ -314,27 +314,6 @@ export function dayLabel(day, now = new Date()) {
|
||||
return fmtDate(day)
|
||||
}
|
||||
|
||||
/**
|
||||
* The cards worth a full-width chart: the catalogue's own order (steps, heart rate, sleep…),
|
||||
* only the ones the window has enough days to draw. A chart of a single point is a dot, so those
|
||||
* are left to the grid's own card rather than given a panel that looks broken.
|
||||
*/
|
||||
export function trendCards(cards, { limit = 4, minDays = 2 } = {}) {
|
||||
return cards.filter(c => c.series.length >= minDays).slice(0, limit)
|
||||
}
|
||||
|
||||
/** min / max / average over a card's window, for the caption under a chart. */
|
||||
export function seriesStats(card) {
|
||||
const vs = (card?.series || []).map(p => p.v).filter(v => Number.isFinite(v))
|
||||
if (!vs.length) return null
|
||||
return {
|
||||
min: Math.min(...vs),
|
||||
max: Math.max(...vs),
|
||||
avg: vs.reduce((a, b) => a + b, 0) / vs.length,
|
||||
days: vs.length
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- units and numbers ---------- */
|
||||
|
||||
// HAE's unit strings are compact and sometimes need a human spelling. Values are never converted:
|
||||
|
||||
@@ -2,7 +2,7 @@ import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
METRICS, specOf, humanize, valueOfDay, metricCards, sortCards, groupedCards, trendOf,
|
||||
chartPoints, workoutRows, hasVitals, activeDays, ingestUrl, unitLabel, fmtValue, agoLabel,
|
||||
detailRows, workoutIcon, GROUP_ORDER, tintOf, dayLabel, trendCards, seriesStats,
|
||||
detailRows, workoutIcon, GROUP_ORDER, tintOf, dayLabel,
|
||||
hourRows, hourChartPoints, historyRows
|
||||
} from './vitals-view.js'
|
||||
|
||||
@@ -213,7 +213,7 @@ describe('aliases', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('dayLabel / trendCards / seriesStats', () => {
|
||||
describe('dayLabel', () => {
|
||||
const now = new Date('2026-05-03T09:00:00')
|
||||
|
||||
it('names the newest day in words when it is recent', () => {
|
||||
@@ -226,21 +226,7 @@ describe('dayLabel / trendCards / seriesStats', () => {
|
||||
expect(dayLabel(undefined, now)).toBe('')
|
||||
})
|
||||
|
||||
it('picks the cards a full-width chart is worth, in catalogue order', () => {
|
||||
const cards = metricCards(doc)
|
||||
const picked = trendCards(cards, { limit: 3 })
|
||||
// In this fixture only two metrics have two days or more; heart_rate and weight_body_mass
|
||||
// carry a single day each, and a one-point chart is a dot nobody can read.
|
||||
expect(picked.map(c => c.name)).toEqual(['step_count', 'resting_heart_rate'])
|
||||
expect(trendCards(cards, { limit: 20 }).every(c => c.series.length >= 2)).toBe(true)
|
||||
// A card with a single day is left out: a one-point chart is a dot.
|
||||
expect(trendCards([{ name: 'x', series: [{ day: '2026-05-03', v: 1 }] }])).toEqual([])
|
||||
})
|
||||
|
||||
it('summarises a window for the caption under a chart', () => {
|
||||
expect(seriesStats(card(doc, 'step_count'))).toMatchObject({ min: 5000, max: 12000, days: 3 })
|
||||
expect(seriesStats(card(doc, 'step_count')).avg).toBe(8000)
|
||||
expect(seriesStats({ series: [] })).toBeNull()
|
||||
it('keeps the newest reading\'s timestamp, which is what makes a card checkable', () => {
|
||||
expect(card(doc, 'step_count').lastTs).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -26,7 +26,7 @@ import LineChart from '../components/LineChart.jsx'
|
||||
import { todayISO } from '../lib/format.js'
|
||||
import {
|
||||
groupedCards, metricCards, trendOf, chartPoints, workoutRows, hasVitals,
|
||||
fmtValue, unitLabel, agoLabel, ingestUrl, detailRows, dayLabel, trendCards, seriesStats,
|
||||
fmtValue, unitLabel, agoLabel, ingestUrl, detailRows, dayLabel,
|
||||
hourRows, hourChartPoints, historyRows
|
||||
} from '../lib/vitals-view.js'
|
||||
|
||||
@@ -78,39 +78,14 @@ function MetricCard({ card, onOpen }) {
|
||||
</button>
|
||||
}
|
||||
|
||||
/**
|
||||
* The charts. Every card in the grid carries a sparkline, which is enough to see a shape and not
|
||||
* enough to read one — so the first few metrics in the catalogue's own order (steps, heart rate,
|
||||
* sleep…, the ones people open this screen for) get a panel: axes, the window's own min/max/avg,
|
||||
* and the card's colour, so a panel and its tile are recognisably the same thing.
|
||||
*/
|
||||
function TrendSection({ cards, windowLabel, onOpen }) {
|
||||
const picked = cards
|
||||
if (!picked.length) return null
|
||||
return <>
|
||||
<h4 className="sec">{t('Trends')}<span className="vh-window"> · {windowLabel}</span></h4>
|
||||
<div className="vh-charts">
|
||||
{picked.map(c => {
|
||||
const st = seriesStats(c)
|
||||
return <button key={c.name} className="card vh-tchart" style={{ '--tint': c.tint }} onClick={() => onOpen(c)}>
|
||||
<div className="vh-tchart-hd">
|
||||
<span className="vh-tchart-t"><Icon name={c.icon} />{c.label}</span>
|
||||
<span className="vh-tchart-v">
|
||||
{fmtValue(c.value, c.dec)}
|
||||
{unitLabel(c.unit) ? <i>{unitLabel(c.unit)}</i> : null}
|
||||
</span>
|
||||
</div>
|
||||
<LineChart points={chartPoints(c)} h={104} unit={unitLabel(c.unit)} color={c.tint} />
|
||||
{st && <div className="vh-tchart-ft">
|
||||
<span>{t('low {0}', fmtValue(st.min, c.dec))}</span>
|
||||
<span>{t('avg {0}', fmtValue(st.avg, c.dec))}</span>
|
||||
<span>{t('high {0}', fmtValue(st.max, c.dec))}</span>
|
||||
</div>}
|
||||
</button>
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
/* There used to be a "Trends" section here: the first four metrics in catalogue order (steps,
|
||||
active energy, exercise time, stand hours) drawn as full-width panels with a big chart and the
|
||||
window's own min/avg/high, with those four taken out of the grid below so nothing was shown
|
||||
twice. It read as a different screen stapled to the top of this one — four huge cards, one per
|
||||
row, above a tidy grid of small ones, and the four it happened to pick were the four most people
|
||||
look at, so the grid looked like it was missing its own headline metrics. Every metric is now the
|
||||
same card, two to a row; the shape of a week is the sparkline on it, and the chart worth reading
|
||||
is one tap away, where it also has the hours and the day-by-day numbers around it. */
|
||||
|
||||
/* ---------- the two sheets ---------- */
|
||||
|
||||
@@ -373,15 +348,11 @@ export default function Health() {
|
||||
const fresh = all.filter(c => c.day === todayISO_)
|
||||
const cards = days === 1 && fresh.length ? fresh : all
|
||||
const fellBack = days === 1 && !fresh.length && all.length > 0
|
||||
/* A metric appears exactly once. The panels above are drawn from the same set as the grid, and
|
||||
the ones they cover are taken out of it — before this, steps (say) was a chart panel and a
|
||||
tile, which read as the screen showing everything twice. */
|
||||
const featured = trendCards(cards, { limit: 4 })
|
||||
const featuredNames = new Set(featured.map(c => c.name))
|
||||
const groups = groupedCards(cards.filter(c => !featuredNames.has(c.name)))
|
||||
// One grid, every metric, one card each: catalogue order inside its group, and no card drawn
|
||||
// twice in two different sizes (see the note above the sheets).
|
||||
const groups = groupedCards(cards)
|
||||
const workouts = workoutRows(data, { limit: 20 })
|
||||
const last = data?.last?.ts
|
||||
const windowLabel = chartDays >= 365 ? t('the last year') : t('the last {0} days', chartDays)
|
||||
const ranges = RANGES.map(r => ({ value: r.value, label: r.key ? t(r.key) : r.label }))
|
||||
|
||||
return <>
|
||||
@@ -417,8 +388,6 @@ export default function Health() {
|
||||
{t('Nothing has come in today yet — this is the latest reading of each metric.')}
|
||||
</div>}
|
||||
|
||||
<TrendSection cards={featured} windowLabel={windowLabel} onOpen={openMetric} />
|
||||
|
||||
{groups.map(g => <div key={g.group}>
|
||||
<h4 className="sec">{g.label}</h4>
|
||||
{/* Two per row (`vh-tiles`), on a phone and on a wide screen alike: every other grid in
|
||||
|
||||
@@ -67,29 +67,25 @@ const mount = async () => {
|
||||
await act(async () => {}) // let the fetch's promise settle
|
||||
}
|
||||
const text = () => host.textContent
|
||||
/* Everything on the screen that is a metric: the chart panels at the top (`.vh-tchart`) and the
|
||||
tiles in the grid (`.vh-card`), in the order they are painted. The screen is supposed to show
|
||||
each metric exactly once across the two — it did not, which is why `seenOnce` exists below. */
|
||||
const entries = () => [...host.querySelectorAll('.vh-card, .vh-tchart')]
|
||||
/* Every metric on the screen is one card in one grid, in the order it is painted. `seenOnce`
|
||||
guards that: the screen used to draw its first four metrics twice — a full-width panel on top
|
||||
and a tile below — which read as a bug because it was one, and the panels are gone now for a
|
||||
different reason (four huge cards above a tidy grid read as two screens stapled together). */
|
||||
const cards = () => [...host.querySelectorAll('.vh-card')]
|
||||
const entryText = el => el.textContent
|
||||
const seenOnce = () => {
|
||||
const labels = entries().map(e => e.querySelector('.l, .vh-tchart-t').textContent)
|
||||
return labels.filter((l, i) => labels.indexOf(l) !== i)
|
||||
}
|
||||
const labels = () => cards().map(c => c.querySelector('.l').textContent)
|
||||
const seenOnce = () => labels().filter((l, i) => labels().indexOf(l) !== i)
|
||||
|
||||
describe('Salud', () => {
|
||||
it('draws one card per metric, grouped, with the number the catalogue says to show', async () => {
|
||||
api.mockResolvedValue(VITALS)
|
||||
await mount()
|
||||
|
||||
const shown = entries().map(e => e.querySelector('.l, .vh-tchart-t').textContent)
|
||||
expect(shown.sort()).toEqual(['Heart rate', 'Sleep', 'Some metric from the future', 'Steps', 'Walking steadiness'])
|
||||
// The one that was reported: every metric once, never a chart panel AND its tile.
|
||||
expect(labels().sort()).toEqual(['Heart rate', 'Sleep', 'Some metric from the future', 'Steps', 'Walking steadiness'])
|
||||
// Every metric once, never a big card AND a small one.
|
||||
expect(seenOnce()).toEqual([])
|
||||
// Steps show the day's total, heart rate the day's average, sleep hours asleep. The unknown
|
||||
// metric falls back to the field with the most samples (its average), rather than a dash.
|
||||
const byLabel = Object.fromEntries(entries().map(e => [e.querySelector('.l, .vh-tchart-t').textContent, entryText(e)]))
|
||||
const byLabel = Object.fromEntries(cards().map(e => [e.querySelector('.l').textContent, e.textContent]))
|
||||
expect(byLabel['Steps']).toContain('12,481')
|
||||
expect(byLabel['Heart rate']).toContain('69')
|
||||
expect(byLabel['Heart rate']).toContain('bpm')
|
||||
@@ -97,14 +93,15 @@ describe('Salud', () => {
|
||||
expect(byLabel['Walking steadiness']).toContain('91')
|
||||
expect(byLabel['Some metric from the future']).toContain('120')
|
||||
|
||||
// Group headings, the range control, and the read-only workout list. Activity is absent on
|
||||
// purpose: in this fixture its only metric is Steps, which the panels took, and a heading with
|
||||
// nothing under it is worse than no heading.
|
||||
expect(text()).not.toContain('Activity')
|
||||
// Group headings, the range control, and the read-only workout list. Activity is here now:
|
||||
// Steps is in the grid like everything else (it used to be a panel, which took it out).
|
||||
expect(text()).toContain('Activity')
|
||||
expect(text()).toContain('Heart')
|
||||
expect(text()).toContain('Vitals')
|
||||
expect(text()).toContain('Other')
|
||||
expect(text()).toContain('Trends')
|
||||
// ...and there is no second, bigger rendering of the same metrics above the grid.
|
||||
expect(text()).not.toContain('Trends')
|
||||
expect(host.querySelectorAll('.vh-tchart').length).toBe(0)
|
||||
expect(text()).toContain('Workouts from your iPhone')
|
||||
expect(text()).toContain('Functional Strength Training')
|
||||
expect(text()).toContain('50 min')
|
||||
@@ -123,7 +120,7 @@ describe('Salud', () => {
|
||||
await mount()
|
||||
const grids = [...host.querySelectorAll('.tiles.vh-tiles')]
|
||||
expect(grids.length).toBeGreaterThan(1) // one per group that has cards
|
||||
expect(grids.reduce((n, g) => n + g.querySelectorAll('.vh-card').length, 0)).toBe(4)
|
||||
expect(grids.reduce((n, g) => n + g.querySelectorAll('.vh-card').length, 0)).toBe(5)
|
||||
// ...and every grid on the screen is one of them: a group that lost the class would silently
|
||||
// go back to four columns at ≥1000px.
|
||||
expect([...host.querySelectorAll('.tiles')]).toEqual(grids)
|
||||
@@ -136,9 +133,9 @@ describe('Salud', () => {
|
||||
api.mockResolvedValue(VITALS)
|
||||
await mount()
|
||||
// Panels and tiles carry the same property, so the colours come out in the order they paint.
|
||||
expect(entries().map(e => e.style.getPropertyValue('--tint')))
|
||||
expect(cards().map(e => e.style.getPropertyValue('--tint')))
|
||||
.toEqual(['var(--orange)', 'var(--red)', 'var(--indigo)', 'var(--green)', 'var(--grey)'])
|
||||
expect(entries().every(e => e.getAttribute('style').includes('--tint'))).toBe(true)
|
||||
expect(cards().every(e => e.getAttribute('style').includes('--tint'))).toBe(true)
|
||||
})
|
||||
|
||||
it('offers the setup steps instead of a blank screen when nothing has arrived', async () => {
|
||||
@@ -217,7 +214,7 @@ describe('the detail sheet', () => {
|
||||
// outlives the screen's root), so reading document.body would read somebody else's day.
|
||||
const sheetEl = () => [...document.querySelectorAll('.sheet')].pop()
|
||||
const sheet = () => sheetEl()?.textContent || ''
|
||||
const openSteps = () => click(entries().find(e => (e.querySelector('.l, .vh-tchart-t') || {}).textContent === 'Steps'))
|
||||
const openSteps = () => click(cards().find(e => e.querySelector('.l').textContent === 'Steps'))
|
||||
|
||||
const withHours = () => ({
|
||||
...VITALS,
|
||||
|
||||
Reference in new issue
Block a user