From 0276e60b18a316085b709fa4ec555d7a410b2730 Mon Sep 17 00:00:00 2001 From: Nicolas Perriault Date: Mon, 27 Jan 2025 11:28:02 +0100 Subject: [PATCH] feat: update default trims when updating product category --- src/Data/Textile/Query.elm | 17 +++++++++++++---- src/Page/Textile.elm | 8 ++++---- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/Data/Textile/Query.elm b/src/Data/Textile/Query.elm index 39b2c11c6..d5b0f79aa 100644 --- a/src/Data/Textile/Query.elm +++ b/src/Data/Textile/Query.elm @@ -266,8 +266,8 @@ handleUpcycling query = query -isAdvancedQuery : Query -> Bool -isAdvancedQuery query = +isAdvancedQuery : List Product -> Query -> Bool +isAdvancedQuery products query = List.any identity [ query.dyeingMedium /= Nothing , query.fabricProcess /= Nothing @@ -277,6 +277,10 @@ isAdvancedQuery query = , query.materials |> List.any (.spinning >> (/=) Nothing) , query.physicalDurability /= Nothing , query.surfaceMass /= Nothing + , products + |> Product.findById query.product + |> Result.map (.trims >> (/=) query.trims) + |> Result.withDefault False , not query.upcycled && List.length query.disabledSteps > 0 , query.yarnSize /= Nothing ] @@ -284,8 +288,8 @@ isAdvancedQuery query = {-| Resets a query to use only regulatory-level fields. -} -regulatory : Query -> Query -regulatory query = +regulatory : List Product -> Query -> Query +regulatory products query = { query | disabledSteps = [] , dyeingMedium = Nothing @@ -296,6 +300,11 @@ regulatory query = , materials = query.materials |> List.map (\m -> { m | spinning = Nothing }) , physicalDurability = Nothing , surfaceMass = Nothing + , trims = + products + |> Product.findById query.product + |> Result.map .trims + |> Result.withDefault [] , yarnSize = Nothing } diff --git a/src/Page/Textile.elm b/src/Page/Textile.elm index ec759a5e2..d1999b387 100644 --- a/src/Page/Textile.elm +++ b/src/Page/Textile.elm @@ -184,7 +184,7 @@ init trigram maybeUrlQuery session = , impact = Definition.get trigram session.db.definitions , modal = NoModal , activeTab = - if Query.isAdvancedQuery initialQuery then + if Query.isAdvancedQuery session.db.textile.products initialQuery then ExploratoryTab else @@ -238,7 +238,7 @@ initFromExample session uuid = , impact = Definition.get Definition.Ecs session.db.definitions , modal = NoModal , activeTab = - if Query.isAdvancedQuery exampleQuery then + if Query.isAdvancedQuery session.db.textile.products exampleQuery then ExploratoryTab else @@ -310,7 +310,7 @@ update ({ queries, navKey } as session) msg model = ( ConfirmSwitchToRegulatory, _ ) -> ( { model | modal = NoModal, activeTab = RegulatoryTab }, session, Cmd.none ) - |> updateQuery (Query.regulatory query) + |> updateQuery (Query.regulatory session.db.textile.products query) ( CopyToClipBoard shareableLink, _ ) -> ( model, session, Ports.copyToClipboard shareableLink ) @@ -539,7 +539,7 @@ update ({ queries, navKey } as session) msg model = ) ( SwitchTab RegulatoryTab, _ ) -> - if Query.isAdvancedQuery query then + if Query.isAdvancedQuery session.db.textile.products query then ( { model | modal = ConfirmSwitchToRegulatoryModal }, session, Cmd.none ) else