Save favorites with the measure they were built with - #290
Conversation
Building a food in cups and saving it as a favorite collapsed the portion
to grams, so reopening the favorite to edit it showed "237 g" instead of
the "1 cup" that was picked.
favorite_items now carries the chosen measure alongside quantity_g:
`quantity` + `unit` (both nullable — favorites saved before this, and
items entered in grams, keep displaying in grams). quantity_g stays the
resolved weight everything computes from; the measure only rides along so
the builder can show it back.
Draft items gain `unit_grams` (grams in one of that unit), which lets the
portion row show and edit the amount in cups while still committing grams.
The quantity is re-derived from the current weight, so a portion changed
after it was added (½× chips, a typed value) saves as the matching count
of its own unit rather than drifting.
USDA household-measure labels bake the count in ("0.5 cup"), so
draftPortion splits it out — 3 × "0.5 cup" reads as "1.5 cup", same grams.
One draft↔favorite mapping pair now serves every surface that saves or
opens a favorite (log sheet, favorites route, calculator, quick tab,
ingredient search), and the shared-favorite copy in family.py carries the
measure through too.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KqXjgMRArAxubgd5f5UYgC
|
The job failed at the
Same failure on the base branch: run 31128880028 on What
No open PR fixes these — the current dependabot PRs cover alembic, uvicorn, litellm, sqlalchemy and Proposed fix, as its own PR rather than widening this one (it touches the lockfiles for every service, and
Backend checks for this diff were run locally against Python 3.12 and pass: Generated by Claude Code |
Building a food in cups and saving it as a favorite collapsed the portion to grams, so reopening the favorite to edit it showed
237 ginstead of the1 cupthat was picked. Favorites now remember the measure.What changed
Schema —
favorite_itemsgainsquantity+unit(migration0034_favorite_item_portion). Both nullable: favorites saved before this, and items entered in grams, keep displaying in grams exactly as they do today.quantity_gis still the resolved weight everything computes from — the measure only rides along so the builder can show it back.Draft items gain
unit_grams(grams in one of that unit). That's what lets the portion row render and edit the amount in cups while still committing grams downstream. The saved quantity is re-derived from the item's current weight, so a portion changed after it was added (½× chips, a typed value) saves as the matching count of its own unit rather than drifting out of sync.Portion row (
DraftItemList) now reads[ 2 ] cup · 480gwhen a measure survived, and[ 150 ] gwhen it didn't. Editing the quantity converts back to grams on the way out. A small draft-string state keeps a half-typed value (0., an empty field) from snapping back mid-keystroke.Household-measure labels — USDA ships these with the count baked in (
"0.5 cup"), which would have read as3 × 1 cup.draftPortionsplits the count out, so 3 ×"0.5 cup"reads as1.5 cup— same grams either way.Consolidation — one
favoriteItemFromDraft/draftFromFavoriteItempair now serves every surface that saves or opens a favorite (log sheet, favorites route, calculator tab, quick tab, ingredient search), replacing five divergent inline copies of the same mapping. The shared-favorite copy infamily.pycarries the measure through too.Favorites list — the expanded ingredients drawer shows the measure as a small badge next to the item name; the numeric Weight column is unchanged.
Behavior notes
base_weight_g), matching every other builder surface. Previously the favorites edit view let them drift as the weight changed.NutritionCalculatorCardhas no unit concept in its builder, so favorites saved from there continue to store grams only.Testing
pnpm type-check,pnpm lint(1 pre-existing warning inIngredientBuilder, unchanged),pnpm test— 162 passed, 32 newmypy luma --ignore-missing-imports— clean, 78 filespytest— 201 passed0034_favorite_item_portionNew tests cover the portion helpers, the build → save → reopen round trip (including the legacy grams fallback), and the portion row's unit rendering and gram conversion.
🤖 Generated with Claude Code
https://claude.ai/code/session_01KqXjgMRArAxubgd5f5UYgC
Generated by Claude Code