Toggle silenced and inhibited alerts (#1049)

* Add inhibited checkbox

* Update ui/bindata.go
This commit is contained in:
Andrey Kuzmin 2017-10-23 11:00:17 +02:00 committed by stuart nelson
parent ae73a3103a
commit 0fa852217b
9 changed files with 41 additions and 23 deletions

View File

@ -26,6 +26,7 @@ type alias Filter =
, group : Maybe String
, receiver : Maybe String
, showSilenced : Maybe Bool
, showInhibited : Maybe Bool
}
@ -35,6 +36,7 @@ nullFilter =
, group = Nothing
, receiver = Nothing
, showSilenced = Nothing
, showInhibited = Nothing
}
@ -44,10 +46,11 @@ generateQueryParam name =
generateQueryString : Filter -> String
generateQueryString { receiver, showSilenced, text, group } =
generateQueryString { receiver, showSilenced, showInhibited, text, group } =
let
parts =
[ ( "silenced", Maybe.withDefault False showSilenced |> toString |> String.toLower |> Just )
, ( "inhibited", Maybe.withDefault False showInhibited |> toString |> String.toLower |> Just )
, ( "filter", emptyToNothing text )
, ( "receiver", emptyToNothing receiver )
, ( "group", group )

View File

@ -17,4 +17,5 @@ alertsParser =
<?> stringParam "group"
<?> stringParam "receiver"
<?> boolParam "silenced"
<?> boolParam "inhibited"
|> map Filter

View File

@ -14,6 +14,7 @@ type AlertListMsg
| MsgForFilterBar FilterBar.Msg
| MsgForGroupBar GroupBar.Msg
| ToggleSilenced Bool
| ToggleInhibited Bool
| SetActive (Maybe String)
| SetTab Tab

View File

@ -59,6 +59,11 @@ update msg ({ groupBar, filterBar, receiverBar } as model) filter apiUrl basePat
, Navigation.newUrl (alertsUrl ++ generateQueryString { filter | showSilenced = Just showSilenced })
)
ToggleInhibited showInhibited ->
( model
, Navigation.newUrl (alertsUrl ++ generateQueryString { filter | showInhibited = Just showInhibited })
)
SetTab tab ->
( { model | tab = tab }, Cmd.none )

View File

@ -19,19 +19,19 @@ import Views.GroupBar.Views as GroupBar
import Dict exposing (Dict)
renderSilenced : Maybe Bool -> Html Msg
renderSilenced maybeShowSilenced =
renderCheckbox : String -> Maybe Bool -> (Bool -> AlertListMsg) -> Html Msg
renderCheckbox textLabel maybeShowSilenced toggleMsg =
li [ class "nav-item" ]
[ label [ class "mt-1 custom-control custom-checkbox" ]
[ label [ class "mt-1 ml-1 custom-control custom-checkbox" ]
[ input
[ type_ "checkbox"
, class "custom-control-input"
, checked (Maybe.withDefault False maybeShowSilenced)
, onCheck (ToggleSilenced >> MsgForAlertList)
, onCheck (toggleMsg >> MsgForAlertList)
]
[]
, span [ class "custom-control-indicator" ] []
, span [ class "custom-control-description" ] [ text "Show Silenced" ]
, span [ class "custom-control-description" ] [ text textLabel ]
]
]
@ -45,8 +45,11 @@ view { alerts, groupBar, filterBar, receiverBar, tab, activeId } filter =
[ ul [ class "nav nav-tabs card-header-tabs" ]
[ Utils.Views.tab FilterTab tab (SetTab >> MsgForAlertList) [ text "Filter" ]
, Utils.Views.tab GroupTab tab (SetTab >> MsgForAlertList) [ text "Group" ]
, ReceiverBar.view filter.receiver receiverBar |> Html.map (MsgForReceiverBar >> MsgForAlertList)
, renderSilenced filter.showSilenced
, receiverBar
|> ReceiverBar.view filter.receiver
|> Html.map (MsgForReceiverBar >> MsgForAlertList)
, renderCheckbox "Silenced" filter.showSilenced ToggleSilenced
, renderCheckbox "Inhibited" filter.showInhibited ToggleInhibited
]
]
, div [ class "card-block" ]

View File

@ -8,6 +8,6 @@ silenceListParser : Parser (Filter -> a) a
silenceListParser =
map
(\t ->
Filter t Nothing Nothing Nothing
Filter t Nothing Nothing Nothing Nothing
)
(s "silences" <?> stringParam "filter")

View File

@ -59,6 +59,7 @@ updateFilter : Maybe String -> Filter
updateFilter maybeFilter =
{ receiver = Nothing
, showSilenced = Nothing
, showInhibited = Nothing
, group = Nothing
, text = maybeFilter
}

View File

@ -29,26 +29,30 @@ parseMatcher =
generateQueryString : Test
generateQueryString =
describe "generateQueryString"
[ test "should default silenced parameter to false if showSilenced is Nothing" <|
[ test "should default silenced & inhibited parameters to false if showSilenced is Nothing" <|
\() ->
Expect.equal "?silenced=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Nothing })
, test "should not render keys with Nothing value except the silenced parameter" <|
Expect.equal "?silenced=false&inhibited=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Nothing, showInhibited = Nothing })
, test "should not render keys with Nothing value except the silenced and inhibited parameters" <|
\() ->
Expect.equal "?silenced=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Nothing })
Expect.equal "?silenced=false&inhibited=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Nothing, showInhibited = Nothing })
, test "should not render filter key with empty value" <|
\() ->
Expect.equal "?silenced=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Just "", showSilenced = Nothing })
Expect.equal "?silenced=false&inhibited=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Just "", showSilenced = Nothing, showInhibited = Nothing })
, test "should render filter key with values" <|
\() ->
Expect.equal "?silenced=false&filter=%7Bfoo%3D%22bar%22%2C%20baz%3D~%22quux.*%22%7D"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Just "{foo=\"bar\", baz=~\"quux.*\"}", showSilenced = Nothing })
Expect.equal "?silenced=false&inhibited=false&filter=%7Bfoo%3D%22bar%22%2C%20baz%3D~%22quux.*%22%7D"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Just "{foo=\"bar\", baz=~\"quux.*\"}", showSilenced = Nothing, showInhibited = Nothing })
, test "should render silenced key with bool" <|
\() ->
Expect.equal "?silenced=true"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Just True })
Expect.equal "?silenced=true&inhibited=false"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Just True, showInhibited = Nothing })
, test "should render inhibited key with bool" <|
\() ->
Expect.equal "?silenced=false&inhibited=true"
(Utils.Filter.generateQueryString { receiver = Nothing, group = Nothing, text = Nothing, showSilenced = Nothing, showInhibited = Just True })
]

File diff suppressed because one or more lines are too long