From e9419f9ba5d947f805efec85e73eaa561d16a1fb Mon Sep 17 00:00:00 2001 From: Philippe PITTOLI Date: Mon, 15 Apr 2024 23:59:09 +0200 Subject: [PATCH] Selections: enable pretty selections. --- src/App/Page/Zone.purs | 7 ++++++- src/App/Type/DMARC.purs | 3 +++ src/Bulma.purs | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/App/Page/Zone.purs b/src/App/Page/Zone.purs index d526dbb..19da279 100644 --- a/src/App/Page/Zone.purs +++ b/src/App/Page/Zone.purs @@ -566,7 +566,9 @@ render state , Bulma.box_input "idDMARCpct" "Sample rate [0..100]" "100" DMARC_pct (maybe "100" show state.dmarc.pct) , Bulma.hr - , Bulma.selection_field "idDMARCfo" "When to send a report" DMARC_fo DMARC.report_occasions_txt (maybe "-" show state.dmarc.fo) + , Bulma.selection_field' "idDMARCfo" "When to send a report" DMARC_fo + (zip_nullable DMARC.report_occasions_txt DMARC.report_occasions_raw) + (maybe "-" show state.dmarc.fo) , Bulma.hr , Bulma.div_content [Bulma.explanation Explanations.dmarc_contact] @@ -613,6 +615,9 @@ render state RemoveRRModal rr_id -> "Error: should display removal modal instead (for RR " <> show rr_id <> ")" foot = foot_ <> [Bulma.cancel_button CancelModal] +zip_nullable :: forall a. Array a -> Array String -> Array (Tuple a String) +zip_nullable txt raw = A.zip txt ([""] <> raw) + handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit handleAction = case _ of -- | Cancel the current modal being presented. diff --git a/src/App/Type/DMARC.purs b/src/App/Type/DMARC.purs index d83be74..d3a820b 100644 --- a/src/App/Type/DMARC.purs +++ b/src/App/Type/DMARC.purs @@ -115,6 +115,9 @@ report_occasions_txt , "Upon any error" ] +report_occasions_raw :: Array String +report_occasions_raw = map show report_occasions + -- | Codec for just encoding a single value of type `ReportOccasion`. codecReportOccasion :: CA.JsonCodec ReportOccasion codecReportOccasion = CA.prismaticCodec "ReportOccasion" str_to_report_occasion generic_serialization CA.string diff --git a/src/Bulma.purs b/src/Bulma.purs index c74110e..345236b 100644 --- a/src/Bulma.purs +++ b/src/Bulma.purs @@ -2,6 +2,7 @@ module Bulma where import Prelude +import Data.Tuple (Tuple, fst, snd) import Halogen.HTML as HH import DOM.HTML.Indexed as DHI import Halogen.HTML.Properties as HP @@ -515,6 +516,22 @@ selection_field id title action values selected , div_field_content $ selection action values selected ] +selection_field' :: forall w i. + String -> String -> (Int -> i) -> Array (Tuple String String) -> String -> HH.HTML w i +selection_field' id title action values selected + = div_field + [ div_field_label id title + , div_field_content $ selection' action values selected + ] + +-- | selection': as `selection` but takes an array of tuple as values. +-- | First value in the tuple is what to display, the second one is what to match on. +selection' :: forall w i. (Int -> i) -> Array (Tuple String String) -> String -> HH.HTML w i +selection' action values selected = HH.div [HP.classes $ C.select <> C.is_normal] + [ HH.select [ HE.onSelectedIndexChange action ] + $ map (\n -> HH.option [HP.value (snd n), HP.selected ((snd n) == selected)] [HH.text (fst n)]) values + ] + tag_light_info :: forall w i. String -> HH.HTML w i tag_light_info str = HH.span [HP.classes (C.tag <> C.is_info <> C.is_light)] [HH.text str]