Recreate silence with previous comment. (#1927)
* Recreate silence with previous comment. Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com> * implement newSilenceFromMatchersAndComment Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com> * Trigger Signed-off-by: m-masataka <m.mizukoshi.wakuwaku@gmail.com>
This commit is contained in:
parent
9f7f4ead46
commit
c1040d5d74
File diff suppressed because one or more lines are too long
|
@ -123,8 +123,8 @@ urlUpdate url =
|
|||
SilenceFormEditRoute silenceId ->
|
||||
NavigateToSilenceFormEdit silenceId
|
||||
|
||||
SilenceFormNewRoute matchers ->
|
||||
NavigateToSilenceFormNew matchers
|
||||
SilenceFormNewRoute params ->
|
||||
NavigateToSilenceFormNew params
|
||||
|
||||
AlertsRoute filter ->
|
||||
NavigateToAlerts filter
|
||||
|
|
|
@ -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)
|
||||
|
@ -39,7 +39,7 @@ type Msg
|
|||
| NavigateToNotFound
|
||||
| NavigateToSilenceView String
|
||||
| NavigateToSilenceFormEdit String
|
||||
| NavigateToSilenceFormNew (List Matcher)
|
||||
| NavigateToSilenceFormNew SilenceFormGetParams
|
||||
| NavigateToSilenceList Filter
|
||||
| NavigateToStatus
|
||||
| NavigateToInternalUrl String
|
||||
|
@ -57,7 +57,7 @@ type Route
|
|||
= AlertsRoute Filter
|
||||
| NotFoundRoute
|
||||
| SilenceFormEditRoute String
|
||||
| SilenceFormNewRoute (List Matcher)
|
||||
| SilenceFormNewRoute SilenceFormGetParams
|
||||
| SilenceListRoute Filter
|
||||
| SilenceViewRoute String
|
||||
| StatusRoute
|
||||
|
|
|
@ -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 ->
|
||||
|
|
|
@ -2,7 +2,9 @@ module Utils.Filter exposing
|
|||
( Filter
|
||||
, MatchOperator(..)
|
||||
, Matcher
|
||||
, SilenceFormGetParams
|
||||
, convertFilterMatcher
|
||||
, emptySilenceFormGetParams
|
||||
, generateAPIQueryString
|
||||
, generateQueryParam
|
||||
, generateQueryString
|
||||
|
@ -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 = ""
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
|
|
@ -5,7 +5,7 @@ module Views.SilenceForm.Types exposing
|
|||
, SilenceFormFieldMsg(..)
|
||||
, SilenceFormMsg(..)
|
||||
, emptyMatcher
|
||||
, fromMatchersAndTime
|
||||
, fromMatchersAndCommentAndTime
|
||||
, fromSilence
|
||||
, initSilenceForm
|
||||
, parseEndsAt
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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))
|
||||
|
@ -208,6 +208,7 @@ fromMatchersAndTime defaultCreator matchers now =
|
|||
|
||||
else
|
||||
List.filterMap (filterMatcherToMatcher >> Maybe.map fromMatcher) matchers
|
||||
, comment = initialField comment
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ import Views.SilenceForm.Types
|
|||
, SilenceFormFieldMsg(..)
|
||||
, SilenceFormMsg(..)
|
||||
, emptyMatcher
|
||||
, fromMatchersAndTime
|
||||
, fromMatchersAndCommentAndTime
|
||||
, fromSilence
|
||||
, parseEndsAt
|
||||
, toSilence
|
||||
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
@ -13,8 +13,8 @@ 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
|
||||
|
@ -22,7 +22,7 @@ view maybeId matchers defaultCreator { form, silenceId, alerts, activeAlertId }
|
|||
( "Edit Silence", FetchSilence silenceId_ )
|
||||
|
||||
Nothing ->
|
||||
( "New Silence", NewSilenceFromMatchers defaultCreator matchers )
|
||||
( "New Silence", NewSilenceFromMatchersAndComment defaultCreator emptySilenceFormGetParams )
|
||||
in
|
||||
div []
|
||||
[ h1 [] [ text title ]
|
||||
|
|
|
@ -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(..))
|
||||
|
||||
|
||||
|
@ -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"
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue