Skip to content

Conversation

oliveror
Copy link
Member

Changes

  • New apps/web/src/lib/ingredientUnits.ts: the editor's unit list in English (g, kg, ml, dL, L, tsp, tbsp, cup, pcs) plus normalizeUnit() / unitLabel().
  • Legacy Norwegian units are translated wherever a recipe is shown or opened for editing: ss → tbsp, ts → tsp, stk → pcs. Existing recipes keep working without a data migration; saving an edited recipe stores the English unit.
  • Custom stored units (the seed uses e.g. cloves, leaves) stay selectable in the editor and display as stored. Previously most seed units were missing from the list.
  • The detail view shows unit labels (1 L instead of 1 l).

Validation

  • npm run check passes (215 unit tests), incl. new unit tests for the mapping and an editor test that opens a recipe with ss, shows tbsp, and saves tbsp.
  • Real-database browser test passes.

AI usage

Written with Claude Code (Anthropic) to address a teammate's review of the final-delivery findings. Please review the diff as you would any other contribution.

Closes #99

The editor offered Norwegian units (ss, ts, stk) in an otherwise English
UI. A shared ingredientUnits module now lists English units (g, kg, ml,
dL, L, tsp, tbsp, cup, pcs), and maps legacy ss/ts/stk to tbsp/tsp/pcs
in the editor and the detail view, so stored recipes keep working without
a data migration (saving stores English). Custom stored units such as
"cloves" stay selectable.

Closes #99
@oliveror oliveror requested a review from a team as a code owner November 16, 2026 14:09
Copy link
Member

@olestan olestan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good overall, and I didn't find any merge-blocking issues. One minor concern worth addressing:

  • apps/web/src/lib/ingredientUnits.ts:32: The legacy unit lookup can resolve inherited properties like __proto__, returning a non-string value. Since custom units are supported, this could cause the recipe editor to crash for affected recipes. Consider using Object.hasOwn() to restrict lookups to explicitly defined mappings.

normalizeUnit() looked units up with a plain index, so free-text units such
as "__proto__" or "constructor" resolved to inherited object properties
and returned a non-string. Lookups now use Object.hasOwn().
@oliveror
Copy link
Member Author

Thanks for the approval. The follow-up is done in the latest commit:

  • Inherited properties in the legacy lookup: normalizeUnit() now uses Object.hasOwn(LEGACY_UNITS, key), so only the three defined mappings (ss, ts, stk) are translated. Any other free-text unit is returned as typed.
  • Test: __proto__, constructor, toString and hasOwnProperty are kept as typed by both normalizeUnit() and unitLabel(). The __proto__ and constructor cases fail on the previous commit, where they returned an object or a function.

npm run check (219 unit tests) passes.

# Conflicts:
#	apps/web/src/features/recipe-detail/RecipeDetailPage.tsx
#	apps/web/src/features/recipes/RecipeCreatePage.test.tsx
#	apps/web/src/features/recipes/RecipeCreatePage.tsx
@oliveror oliveror merged commit 51b513e into dev Nov 17, 2026
2 checks passed
@oliveror oliveror deleted the fix/recipe-english-units branch November 20, 2026 15:32
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants