Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recreate silence with previous comment. #1927

Merged
merged 3 commits into from
Aug 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions asset/assets_vfsdata.go

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions ui/app/src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ urlUpdate url =
SilenceFormEditRoute silenceId ->
NavigateToSilenceFormEdit silenceId

SilenceFormNewRoute matchers ->
NavigateToSilenceFormNew matchers
SilenceFormNewRoute params ->
NavigateToSilenceFormNew params

AlertsRoute filter ->
NavigateToAlerts filter
Expand Down
6 changes: 3 additions & 3 deletions ui/app/src/Types.elm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Types exposing (Model, Msg(..), Route(..))

import Browser.Navigation exposing (Key)
import Utils.Filter exposing (Filter, Matcher)
import Utils.Filter exposing (Filter, Matcher, SilenceFormGetParams)
import Utils.Types exposing (ApiData)
import Views.AlertList.Types as AlertList exposing (AlertListMsg)
import Views.SilenceForm.Types as SilenceForm exposing (SilenceFormMsg)
Expand Down Expand Up @@ -39,7 +39,7 @@ type Msg
| NavigateToNotFound
| NavigateToSilenceView String
| NavigateToSilenceFormEdit String
| NavigateToSilenceFormNew (List Matcher)
| NavigateToSilenceFormNew SilenceFormGetParams
| NavigateToSilenceList Filter
| NavigateToStatus
| NavigateToInternalUrl String
Expand All @@ -57,7 +57,7 @@ type Route
= AlertsRoute Filter
| NotFoundRoute
| SilenceFormEditRoute String
| SilenceFormNewRoute (List Matcher)
| SilenceFormNewRoute SilenceFormGetParams
| SilenceListRoute Filter
| SilenceViewRoute String
| StatusRoute
Expand Down
6 changes: 3 additions & 3 deletions ui/app/src/Updates.elm
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ update msg ({ basePath, apiUrl } as model) =
, Cmd.map MsgForSilenceView cmd
)

NavigateToSilenceFormNew matchers ->
( { model | route = SilenceFormNewRoute matchers }
, Task.perform (NewSilenceFromMatchers model.defaultCreator >> MsgForSilenceForm) (Task.succeed matchers)
NavigateToSilenceFormNew params ->
( { model | route = SilenceFormNewRoute params }
, Task.perform (NewSilenceFromMatchersAndComment model.defaultCreator >> MsgForSilenceForm) (Task.succeed params)
)

NavigateToSilenceFormEdit uuid ->
Expand Down
15 changes: 15 additions & 0 deletions ui/app/src/Utils/Filter.elm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ module Utils.Filter exposing
( Filter
, MatchOperator(..)
, Matcher
, SilenceFormGetParams
, convertFilterMatcher
, emptySilenceFormGetParams
, generateAPIQueryString
, generateQueryParam
, generateQueryString
Expand Down Expand Up @@ -324,3 +326,16 @@ silencePreviewFilter apiMatchers =
, showInhibited = Just True
, showActive = Just True
}


type alias SilenceFormGetParams =
{ matchers : List Matcher
, comment : String
}


emptySilenceFormGetParams : SilenceFormGetParams
emptySilenceFormGetParams =
{ matchers = []
, comment = ""
}
7 changes: 4 additions & 3 deletions ui/app/src/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Html.Attributes exposing (class, href, rel, src, style)
import Html.Events exposing (on)
import Json.Decode exposing (succeed)
import Types exposing (Model, Msg(..), Route(..))
import Utils.Filter exposing (emptySilenceFormGetParams)
import Utils.Types exposing (ApiData(..))
import Utils.Views exposing (error, loading)
import Views.AlertList.Views as AlertList
Expand Down Expand Up @@ -81,11 +82,11 @@ currentView model =
SilenceListRoute _ ->
SilenceList.view model.silenceList

SilenceFormNewRoute matchers ->
SilenceForm.view Nothing matchers model.defaultCreator model.silenceForm |> Html.map MsgForSilenceForm
SilenceFormNewRoute getParams ->
SilenceForm.view Nothing getParams model.defaultCreator model.silenceForm |> Html.map MsgForSilenceForm

SilenceFormEditRoute silenceId ->
SilenceForm.view (Just silenceId) [] "" model.silenceForm |> Html.map MsgForSilenceForm
SilenceForm.view (Just silenceId) emptySilenceFormGetParams "" model.silenceForm |> Html.map MsgForSilenceForm

TopLevelRoute ->
Utils.Views.loading
Expand Down
21 changes: 16 additions & 5 deletions ui/app/src/Views/SilenceForm/Parsing.elm
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels, newSilenceFromMatchers, silenceFormEditParser, silenceFormNewParser)
module Views.SilenceForm.Parsing exposing (newSilenceFromAlertLabels, newSilenceFromMatchers, newSilenceFromMatchersAndComment, silenceFormEditParser, silenceFormNewParser)

import Data.Matcher
import Dict exposing (Dict)
import Url exposing (percentEncode)
import Url.Parser exposing ((</>), (<?>), Parser, map, oneOf, s, string)
import Url.Parser.Query as Query
import Utils.Filter exposing (Matcher, parseFilter)
import Utils.Filter exposing (Matcher, SilenceFormGetParams, parseFilter)


newSilenceFromAlertLabels : Dict String String -> String
Expand All @@ -16,12 +16,18 @@ newSilenceFromAlertLabels labels =
|> encodeMatchers


silenceFormNewParser : Parser (List Matcher -> a) a
parseGetParams : Maybe String -> Maybe String -> SilenceFormGetParams
parseGetParams filter comment =
{ matchers = filter |> Maybe.andThen parseFilter >> Maybe.withDefault []
, comment = comment |> Maybe.withDefault ""
}


silenceFormNewParser : Parser (SilenceFormGetParams -> a) a
silenceFormNewParser =
s "silences"
</> s "new"
<?> Query.string "filter"
|> map (Maybe.andThen parseFilter >> Maybe.withDefault [])
<?> Query.map2 parseGetParams (Query.string "filter") (Query.string "comment")


silenceFormEditParser : Parser (String -> a) a
Expand All @@ -47,6 +53,11 @@ newSilenceFromMatchers matchers =
|> encodeMatchers


newSilenceFromMatchersAndComment : List Data.Matcher.Matcher -> String -> String
newSilenceFromMatchersAndComment matchers comment =
newSilenceFromMatchers matchers ++ "&comment=" ++ (comment |> percentEncode)


encodeMatchers : List Utils.Filter.Matcher -> String
encodeMatchers matchers =
matchers
Expand Down
11 changes: 6 additions & 5 deletions ui/app/src/Views/SilenceForm/Types.elm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Views.SilenceForm.Types exposing
, SilenceFormFieldMsg(..)
, SilenceFormMsg(..)
, emptyMatcher
, fromMatchersAndTime
, fromMatchersAndCommentAndTime
, fromSilence
, initSilenceForm
, parseEndsAt
Expand Down Expand Up @@ -67,8 +67,8 @@ type SilenceFormMsg
| AlertGroupsPreview (ApiData (List GettableAlert))
| SetActiveAlert (Maybe String)
| FetchSilence String
| NewSilenceFromMatchers String (List Utils.Filter.Matcher)
| NewSilenceFromMatchersAndTime String (List Utils.Filter.Matcher) Posix
| NewSilenceFromMatchersAndComment String Utils.Filter.SilenceFormGetParams
| NewSilenceFromMatchersAndCommentAndTime String (List Utils.Filter.Matcher) String Posix
| SilenceFetch (ApiData GettableSilence)
| SilenceCreate (ApiData String)

Expand Down Expand Up @@ -194,8 +194,8 @@ defaultDuration =
2 * 60 * 60 * 1000


fromMatchersAndTime : String -> List Utils.Filter.Matcher -> Posix -> SilenceForm
fromMatchersAndTime defaultCreator matchers now =
fromMatchersAndCommentAndTime : String -> List Utils.Filter.Matcher -> String -> Posix -> SilenceForm
fromMatchersAndCommentAndTime defaultCreator matchers comment now =
{ empty
| startsAt = initialField (timeToString now)
, endsAt = initialField (timeToString (addDuration defaultDuration now))
Expand All @@ -208,6 +208,7 @@ fromMatchersAndTime defaultCreator matchers now =

else
List.filterMap (filterMatcherToMatcher >> Maybe.map fromMatcher) matchers
, comment = initialField comment
}


Expand Down
10 changes: 5 additions & 5 deletions ui/app/src/Views/SilenceForm/Updates.elm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Views.SilenceForm.Types
, SilenceFormFieldMsg(..)
, SilenceFormMsg(..)
, emptyMatcher
, fromMatchersAndTime
, fromMatchersAndCommentAndTime
, fromSilence
, parseEndsAt
, toSilence
Expand Down Expand Up @@ -207,11 +207,11 @@ update msg model basePath apiUrl =
in
( { model | silenceId = silenceId }, cmd )

NewSilenceFromMatchers defaultCreator matchers ->
( model, Task.perform (NewSilenceFromMatchersAndTime defaultCreator matchers >> MsgForSilenceForm) Time.now )
NewSilenceFromMatchersAndComment defaultCreator params ->
( model, Task.perform (NewSilenceFromMatchersAndCommentAndTime defaultCreator params.matchers params.comment >> MsgForSilenceForm) Time.now )

NewSilenceFromMatchersAndTime defaultCreator matchers time ->
( { form = fromMatchersAndTime defaultCreator matchers time
NewSilenceFromMatchersAndCommentAndTime defaultCreator matchers comment time ->
( { form = fromMatchersAndCommentAndTime defaultCreator matchers comment time
, alerts = Initial
, activeAlertId = Nothing
, silenceId = Initial
Expand Down
8 changes: 4 additions & 4 deletions ui/app/src/Views/SilenceForm/Views.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Data.GettableAlert exposing (GettableAlert)
import Html exposing (Html, a, button, div, fieldset, h1, input, label, legend, span, strong, text, textarea)
import Html.Attributes exposing (class, href)
import Html.Events exposing (onClick)
import Utils.Filter
import Utils.Filter exposing (SilenceFormGetParams, emptySilenceFormGetParams)
import Utils.FormValidation exposing (ValidatedField, ValidationState(..))
import Utils.Types exposing (ApiData)
import Utils.Views exposing (checkbox, iconButtonMsg, loading, validatedField, validatedTextareaField)
Expand All @@ -13,16 +13,16 @@ import Views.Shared.Types exposing (Msg)
import Views.SilenceForm.Types exposing (MatcherForm, Model, SilenceForm, SilenceFormFieldMsg(..), SilenceFormMsg(..))


view : Maybe String -> List Utils.Filter.Matcher -> String -> Model -> Html SilenceFormMsg
view maybeId matchers defaultCreator { form, silenceId, alerts, activeAlertId } =
view : Maybe String -> SilenceFormGetParams -> String -> Model -> Html SilenceFormMsg
view maybeId { matchers, comment } defaultCreator { form, silenceId, alerts, activeAlertId } =
let
( title, resetClick ) =
case maybeId of
Just silenceId_ ->
( "Edit Silence", FetchSilence silenceId_ )

Nothing ->
( "New Silence", NewSilenceFromMatchers defaultCreator matchers )
( "New Silence", NewSilenceFromMatchersAndComment defaultCreator emptySilenceFormGetParams )
in
div []
[ h1 [] [ text title ]
Expand Down
4 changes: 2 additions & 2 deletions ui/app/src/Views/SilenceList/SilenceView.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Utils.List
import Utils.Views exposing (buttonLink)
import Views.FilterBar.Types as FilterBarTypes
import Views.Shared.Dialog as Dialog
import Views.SilenceForm.Parsing exposing (newSilenceFromMatchers)
import Views.SilenceForm.Parsing exposing (newSilenceFromMatchers, newSilenceFromMatchersAndComment)
import Views.SilenceList.Types exposing (SilenceListMsg(..))


Expand Down Expand Up @@ -114,7 +114,7 @@ editButton silence =
Expired ->
a
[ class "btn btn-outline-info border-0"
, href (newSilenceFromMatchers silence.matchers)
, href (newSilenceFromMatchersAndComment silence.matchers silence.comment)
]
[ text "Recreate"
]
Expand Down