mirror of
https://github.com/prometheus/alertmanager
synced 2025-01-10 07:49:36 +00:00
Remove Maybe on Decode for blocks
This commit is contained in:
parent
cb9e95bacb
commit
0edb08fb30
18
src/Api.elm
18
src/Api.elm
@ -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
|
||||
|
@ -34,7 +34,7 @@ type alias Silence =
|
||||
|
||||
|
||||
type alias AlertGroup =
|
||||
{ blocks : Maybe (List Block)
|
||||
{ blocks : List Block
|
||||
, labels : List ( String, String )
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user