Skip to content

feat: add some days of a meal plan to the shopping list - #611

Merged
LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/plan-shopping-range
Nov 7, 2026
Merged

LeMyst merged 1 commit into
cooklang:mainfrom
LeMyst:feat/plan-shopping-range

Conversation

@LeMyst

@LeMyst LeMyst commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #671. One commit on main (#596 has been merged). A plan is any menu dated on two days or more, and a date counts anywhere in a section name (= 2026-10-08 Dinner is that day's dinner).

Step 3a of the proposal: put some days of a meal plan on the shopping list — this week of a fortnight, or just the days until the next shop.

What changes

  • On a plan's page, those who may change the shopping list get a checkbox on each day card, All / Next 7 days / None shortcuts, and Add days to shopping list with the number of days ticked. Only those days count: their recipes, at the factor the menu gives each one times the page's servings, and the ingredients written straight into those days (@almonds{50%g}), merged by name (two days of 50 g almonds → almonds{100%g}).
  • Add All to Shopping List is unchanged: the whole plan is still one menu entry, byte for byte as before (tests/menu_api_test.rs passes untouched).
  • The shopping list page lists the free-hand items under Extra items, each with Remove, and includes them when it generates the list, merged with the recipes' ingredients of the same name, in their aisle, and reduced by the pantry like any other ingredient.

How the days are stored, and why

A menu entry can't hold a choice of days. .shopping-list reads ./Plan.menu followed by its recipes as "the whole menu plus these recipes". The page then adds the menu itself with included_references: [] to pick up its free-hand ingredients, which would bring every day's almonds and bread back in. Filtering that entry would mean new syntax in a file the Cooklang apps share.

So the chosen days are stored with what the format already has:

./Risotto
./Neapolitan Pizza
  ./Shared/Pizza Dough
almonds{100%g}
coffee{2%cups}
  • The recipes become recipe lines, exactly as if each one had been added on its own, with its scale and sub-recipe references worked out by the same loop add_menu runs for a whole menu (cooklang-find's Menu with resolve_scales, the Recipe endpoints and /api/static follow symlinks out of the collection #698 containment checks, nested-menu back references dropped). With dates, that loop only skips the sections not dated one of them. An optional recipe (@?./Cake{}) stays off, as for the whole menu.
  • The free-hand ingredients become top-level free-hand lines. The format has always had these (cooklang::shopping_list::IngredientItem) for items typed in by hand. cook shopping-list and the apps already read them, and before this the server silently dropped them.

The trade-off: once added, the days aren't grouped under the plan's name in the sidebar, and they're removed recipe by recipe and item by item rather than as one plan. I think that's right for a partial plan: you're shopping for those meals, not the menu. A grouped form would need a format change upstream in cooklang-rs.

API

  • POST /api/shopping_list/add_menu takes an optional dates: ["YYYY-MM-DD", …]. I extended this endpoint rather than adding a sibling: it's the same operation, scaling and reference resolution, and without dates nothing changes. 400 for an empty list, more than 400 dates, or something that isn't a date. A date the menu doesn't have adds nothing.
  • GET /api/shopping_list/extra_items returns [{name, quantity?}].
  • POST /api/shopping_list/remove_extra_item with {name, quantity?} removes the first match and compacts the checked log like remove does. It's covered by the existing EditLists prefix in the auth WRITES table.
  • POST /api/shopping_list also accepts {name, quantity} elements (untagged next to {recipe, …}), merged into the required ingredients through core's new add_extra_item, the same path as the CLI's --extra.
  • The checked-log compaction now counts free-hand items, so ticking almonds survives removing a recipe.
  • docs/api.md is regenerated from src/web/api_docs.rs.

In core: FreeHandItem, ShoppingListStore::{add_all, load_free_hand, remove_free_hand} (add_all writes recipes and items in one atomic write), and shopping_list::add_extra_item.

Screenshots

Days ticked on the plan The shopping list afterwards
days list

Monday, Wednesday and Thursday are ticked. Tuesday's curry and bread stay off, and the almonds of Wednesday and Thursday become one 100 g extra item.

Tests

  • Core unit tests: add_all order and bytes, free-hand lines another app wrote (top level only), remove_free_hand matching name and amount, remove leaving a free-hand line of the same text alone, FreeHandItem::spec.
  • Handler unit tests: only the chosen dates' sections count, free-hand merging (units that can't be added stay apart), date validation.
  • Integration (tests/plan_shopping_test.rs, isolated config): the exact .shopping-list for two of three days at ×2, the list it generates, the whole menu unchanged without dates, removing an extra item, bad dates → 400, an absent date → nothing.
  • Playwright (tests/e2e/plan-shopping.spec.ts): tick days, add, check the request, sidebar and generated list, remove an extra item; the three shortcuts; Add All still one entry; axe on the plan.
  • cargo fmt, cargo clippy --all-targets (and --no-default-features: only the warnings already on main), cargo test all clean.
  • Playwright on chromium:
    • The new spec plus meal-plan, menu-scale and the shopping-list* specs: all pass with --workers=1.
    • Full run in parallel: 251 passed. 4 failed, a different set on each run, all in specs that share the seed's .shopping-list (shopping-list-copy, shopping-list-live, one recipe-scaling add); they all pass with one worker.
    • The new spec never clears the shared list; it removes only what it added.

Not in this PR

  • A whole menu as one day's meal (step 3b).

Rebased onto main (d1455f4), 2026-11-07

  • add_menu was rewritten upstream around util::menu::load_menu (cooklang-find MenuItems), so the day filter is now a per-section check (on_a_chosen_day, same web::plan::section_date as the calendar) inside that loop. The free-hand items of the chosen days still come from the Cooklang parse of the menu at the page's scale, so their amounts add up by unit as before.
  • Stored entries keep their optional-ingredient selections (? name{qty} lines, feat(shopping-list): leave optional ingredients out unless --include-optional #592's split): recipe_item writes them for both add and add_all. Free-hand items go into required, in the generated list and in the tick compaction.
  • Error bodies go through json_error. The new messages are in el-GR too.
  • cargo fmt, cargo clippy --workspace --all-targets clean; cargo test --workspace --no-fail-fast: all 56 binaries pass. Full chromium Playwright with --workers=1: 331 passed, 5 skipped, 3 failed (and 4 that did not run after them in serial blocks), all spawn target/debug/cook ENOENT because my build used a private target dir (static-file-search, sign-in-notice, the "does not parse" pantry test). plan-shopping.spec.ts and every shopping-list* spec pass.

🤖 Generated with Claude Code

https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK

A meal plan's page gets a checkbox on each day, All / Next 7 days / None
shortcuts, and "Add days to shopping list". Only those days' recipes go
on the list, at the menu's factors times the page's servings, and the
ingredients written straight into those days (`@almonds{50%g}`) go on as
free-hand items, merged by name.

A menu entry cannot carry a choice of days: the list reads a menu entry
as the whole menu plus its listed recipes, so every day's free-hand
ingredients would come along. The chosen days are therefore stored with
what the `.shopping-list` format already has: recipe lines, as if each
recipe had been added on its own, and top-level free-hand lines such as
`almonds{100%g}`, which the Cooklang apps also read and write.

- `POST /api/shopping_list/add_menu` takes optional `dates`; without it
  the whole menu is one entry, byte for byte as before.
- `ShoppingListStore::add_all`, `load_free_hand`, `remove_free_hand`
  and `FreeHandItem`; core's `add_extra_item` merges one into an
  ingredient list like the CLI's `--extra`.
- `GET /api/shopping_list/extra_items`,
  `POST /api/shopping_list/remove_extra_item`; `POST /api/shopping_list`
  accepts `{name, quantity}` elements; compaction counts free-hand items.
- The shopping list page lists them under "Extra items", each with
  Remove, and sends them along when generating the list.
- Strings in all 9 locales; docs/server.md, docs/api.md.

A day's sections are found as the calendar finds them
(`web::plan::section_date`): a `YYYY-MM-DD` anywhere in the name, so a
`= 2026-10-08 Dinner` section is that day too.

Part of cooklang#385.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01RXA3hAKY9Q8hLCZGeokLPK
@LeMyst
LeMyst force-pushed the feat/plan-shopping-range branch from 03471a9 to 0ff5056 Compare November 7, 2026 05:28
@LeMyst
LeMyst marked this pull request as ready for review November 7, 2026 05:28
@LeMyst
LeMyst merged commit c53c97f into cooklang:main Nov 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant