Remove Maybe on Decode for blocks

This commit is contained in:
stuart nelson 2016-12-11 19:57:58 +01:00
parent cb9e95bacb
commit 0edb08fb30
3 changed files with 22 additions and 18 deletions

View File

@ -61,10 +61,26 @@ alertGroupsDecoder =
alertGroupDecoder : Json.Decoder AlertGroup
alertGroupDecoder =
Json.map2 AlertGroup
(Json.at [ "blocks" ] <| Json.maybe <| Json.list blockDecoder)
(decodeBlocks)
(Json.at [ "labels" ] (Json.keyValuePairs Json.string))
decodeBlocks : Json.Decoder (List Block)
decodeBlocks =
Json.maybe (Json.at [ "blocks" ] (Json.list blockDecoder))
|> andThen (unwrapWithDefault [])
unwrapWithDefault : a -> Maybe a -> Json.Decoder a
unwrapWithDefault default val =
case val of
Just a ->
Json.succeed a
Nothing ->
Json.succeed default
blockDecoder : Json.Decoder Block
blockDecoder =
Json.map Block

View File

@ -34,7 +34,7 @@ type alias Silence =
type alias AlertGroup =
{ blocks : Maybe (List Block)
{ blocks : List Block
, labels : List ( String, String )
}

View File

@ -63,22 +63,10 @@ silenceFormView kind silence =
alertGroupsView : AlertGroup -> Html Msg
alertGroupsView alertGroup =
let
blocks =
case alertGroup.blocks of
Just blocks ->
blocks
Nothing ->
[]
pairs =
List.map2 (,) alertGroup.labels blocks
in
li [ class "pa3 pa4-ns bb b--black-10" ]
[ div [] (List.map labelHeader alertGroup.labels)
, div [] (List.map blockView blocks)
]
li [ class "pa3 pa4-ns bb b--black-10" ]
[ div [] (List.map labelHeader alertGroup.labels)
, div [] (List.map blockView alertGroup.blocks)
]
blockView : Block -> Html msg