Skip to content

Commit

Permalink
feat: update query mass from input.
Browse files Browse the repository at this point in the history
  • Loading branch information
n1k0 committed Nov 6, 2024
1 parent 6366ca3 commit 02f1309
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/Data/Food/Query.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module Data.Food.Query exposing
, setTransform
, updateDistribution
, updateIngredient
, updateMass
, updatePackaging
, updatePreparation
, updateTransform
Expand Down Expand Up @@ -253,6 +254,12 @@ setDistribution distribution query =
{ query | distribution = Just distribution }


updateMass : Mass -> Query -> Query
updateMass mass query =
-- FIXME: update ingredient masses from product final mass
{ query | mass = mass }


updatePreparation : Preparation.Id -> Preparation.Id -> Query -> Query
updatePreparation oldId newId query =
{ query
Expand Down
10 changes: 9 additions & 1 deletion src/Page/Food.elm
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ type Msg
| UpdateBookmarkName String
| UpdateDistribution String
| UpdateIngredient Query.IngredientQuery Query.IngredientQuery
| UpdateMass (Maybe Mass)
| UpdatePackaging Process.Identifier Query.ProcessQuery
| UpdatePreparation Preparation.Id Preparation.Id
| UpdateTransform Query.ProcessQuery
Expand Down Expand Up @@ -451,6 +452,13 @@ update ({ db, queries } as session) msg model =
( model, session, Cmd.none )
|> updateQuery (Query.updateIngredient oldIngredient.id newIngredient query)

UpdateMass (Just mass) ->
( model, session, Cmd.none )
|> updateQuery (Query.updateMass mass query)

UpdateMass Nothing ->
( model, session, Cmd.none )

UpdatePackaging code newPackaging ->
( model, session, Cmd.none )
|> updateQuery (Query.updatePackaging code newPackaging query)
Expand Down Expand Up @@ -1358,7 +1366,7 @@ mainView ({ db } as session) model =
[ span [ class "text-nowrap" ] [ text "Masse du produit fini" ]
, MassInput.view
{ mass = query.mass
, onChange = always NoOp
, onChange = UpdateMass
, disabled = False
}
]
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e-food.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@
},
{
"name": "Mango from default origin, but by boat",
"query": ["mass=1000", "ingredients[]=mango-non-eu;120;;noPlane", "category=fruitsAndVegetables"],
"query": [
"mass=1000",
"ingredients[]=mango-non-eu;120;;noPlane",
"category=fruitsAndVegetables"
],
"impacts": {
"acd": 0.0016648344354554664,
"cch": 0.16906826360893284,
Expand Down

0 comments on commit 02f1309

Please sign in to comment.