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 ->
|
SilenceFormEditRoute silenceId ->
|
||||||
NavigateToSilenceFormEdit silenceId
|
NavigateToSilenceFormEdit silenceId
|
||||||
|
|
||||||
SilenceFormNewRoute matchers ->
|
SilenceFormNewRoute params ->
|
||||||
NavigateToSilenceFormNew matchers
|
NavigateToSilenceFormNew params
|
||||||
|
|
||||||
AlertsRoute filter ->
|
AlertsRoute filter ->
|
||||||
NavigateToAlerts filter
|
NavigateToAlerts filter
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
module Types exposing (Model, Msg(..), Route(..))
|
module Types exposing (Model, Msg(..), Route(..))
|
||||||
|
|
||||||
import Browser.Navigation exposing (Key)
|
import Browser.Navigation exposing (Key)
|
||||||
import Utils.Filter exposing (Filter, Matcher)
|
import Utils.Filter exposing (Filter, Matcher, SilenceFormGetParams)
|
||||||
import Utils.Types exposing (ApiData)
|
import Utils.Types exposing (ApiData)
|
||||||
import Views.AlertList.Types as AlertList exposing (AlertListMsg)
|
import Views.AlertList.Types as AlertList exposing (AlertListMsg)
|
||||||
import Views.SilenceForm.Types as SilenceForm exposing (SilenceFormMsg)
|
import Views.SilenceForm.Types as SilenceForm exposing (SilenceFormMsg)
|
||||||
|
@ -39,7 +39,7 @@ type Msg
|
||||||
| NavigateToNotFound
|
| NavigateToNotFound
|
||||||
| NavigateToSilenceView String
|
| NavigateToSilenceView String
|
||||||
| NavigateToSilenceFormEdit String
|
| NavigateToSilenceFormEdit String
|
||||||
| NavigateToSilenceFormNew (List Matcher)
|
| NavigateToSilenceFormNew SilenceFormGetParams
|
||||||
| NavigateToSilenceList Filter
|
| NavigateToSilenceList Filter
|
||||||
| NavigateToStatus
|
| NavigateToStatus
|
||||||
| NavigateToInternalUrl String
|
| NavigateToInternalUrl String
|
||||||
|
@ -57,7 +57,7 @@ type Route
|
||||||
= AlertsRoute Filter
|
= AlertsRoute Filter
|
||||||
| NotFoundRoute
|
| NotFoundRoute
|
||||||
| SilenceFormEditRoute String
|
| SilenceFormEditRoute String
|
||||||
| SilenceFormNewRoute (List Matcher)
|
| SilenceFormNewRoute SilenceFormGetParams
|
||||||
| SilenceListRoute Filter
|
| SilenceListRoute Filter
|
||||||
| SilenceViewRoute String
|
| SilenceViewRoute String
|
||||||
| StatusRoute
|
| StatusRoute
|
||||||
|
|
|
@ -47,9 +47,9 @@ update msg ({ basePath, apiUrl } as model) =
|
||||||
, Cmd.map MsgForSilenceView cmd
|
, Cmd.map MsgForSilenceView cmd
|
||||||
)
|
)
|
||||||
|
|
||||||
NavigateToSilenceFormNew matchers ->
|
NavigateToSilenceFormNew params ->
|
||||||
( { model | route = SilenceFormNewRoute matchers }
|
( { model | route = SilenceFormNewRoute params }
|
||||||
, Task.perform (NewSilenceFromMatchers model.defaultCreator >> MsgForSilenceForm) (Task.succeed matchers)
|
, Task.perform (NewSilenceFromMatchersAndComment model.defaultCreator >> MsgForSilenceForm) (Task.succeed params)
|
||||||
)
|
)
|
||||||
|
|
||||||
NavigateToSilenceFormEdit uuid ->
|
NavigateToSilenceFormEdit uuid ->
|
||||||
|
|
|
@ -2,7 +2,9 @@ module Utils.Filter exposing
|
||||||
( Filter
|
( Filter
|
||||||
, MatchOperator(..)
|
, MatchOperator(..)
|
||||||
, Matcher
|
, Matcher
|
||||||
|
, SilenceFormGetParams
|
||||||
, convertFilterMatcher
|
, convertFilterMatcher
|
||||||
|
, emptySilenceFormGetParams
|
||||||
, generateAPIQueryString
|
, generateAPIQueryString
|
||||||
, generateQueryParam
|
, generateQueryParam
|
||||||
, generateQueryString
|
, generateQueryString
|
||||||
|
@ -324,3 +326,16 @@ silencePreviewFilter apiMatchers =
|
||||||
, showInhibited = Just True
|
, showInhibited = Just True
|
||||||
, showActive = 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 Html.Events exposing (on)
|
||||||
import Json.Decode exposing (succeed)
|
import Json.Decode exposing (succeed)
|
||||||
import Types exposing (Model, Msg(..), Route(..))
|
import Types exposing (Model, Msg(..), Route(..))
|
||||||
|
import Utils.Filter exposing (emptySilenceFormGetParams)
|
||||||
import Utils.Types exposing (ApiData(..))
|
import Utils.Types exposing (ApiData(..))
|
||||||
import Utils.Views exposing (error, loading)
|
import Utils.Views exposing (error, loading)
|
||||||
import Views.AlertList.Views as AlertList
|
import Views.AlertList.Views as AlertList
|
||||||
|
@ -81,11 +82,11 @@ currentView model =
|
||||||
SilenceListRoute _ ->
|
SilenceListRoute _ ->
|
||||||
SilenceList.view model.silenceList
|
SilenceList.view model.silenceList
|
||||||
|
|
||||||
SilenceFormNewRoute matchers ->
|
SilenceFormNewRoute getParams ->
|
||||||
SilenceForm.view Nothing matchers model.defaultCreator model.silenceForm |> Html.map MsgForSilenceForm
|
SilenceForm.view Nothing getParams model.defaultCreator model.silenceForm |> Html.map MsgForSilenceForm
|
||||||
|
|
||||||
SilenceFormEditRoute silenceId ->
|
SilenceFormEditRoute silenceId ->
|
||||||
SilenceForm.view (Just silenceId) [] "" model.silenceForm |> Html.map MsgForSilenceForm
|
SilenceForm.view (Just silenceId) emptySilenceFormGetParams "" model.silenceForm |> Html.map MsgForSilenceForm
|
||||||
|
|
||||||
TopLevelRoute ->
|
TopLevelRoute ->
|
||||||
Utils.Views.loading
|
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 Data.Matcher
|
||||||
import Dict exposing (Dict)
|
import Dict exposing (Dict)
|
||||||
import Url exposing (percentEncode)
|
import Url exposing (percentEncode)
|
||||||
import Url.Parser exposing ((</>), (<?>), Parser, map, oneOf, s, string)
|
import Url.Parser exposing ((</>), (<?>), Parser, map, oneOf, s, string)
|
||||||
import Url.Parser.Query as Query
|
import Url.Parser.Query as Query
|
||||||
import Utils.Filter exposing (Matcher, parseFilter)
|
import Utils.Filter exposing (Matcher, SilenceFormGetParams, parseFilter)
|
||||||
|
|
||||||
|
|
||||||
newSilenceFromAlertLabels : Dict String String -> String
|
newSilenceFromAlertLabels : Dict String String -> String
|
||||||
|
@ -16,12 +16,18 @@ newSilenceFromAlertLabels labels =
|
||||||
|> encodeMatchers
|
|> 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 =
|
silenceFormNewParser =
|
||||||
s "silences"
|
s "silences"
|
||||||
</> s "new"
|
</> s "new"
|
||||||
<?> Query.string "filter"
|
<?> Query.map2 parseGetParams (Query.string "filter") (Query.string "comment")
|
||||||
|> map (Maybe.andThen parseFilter >> Maybe.withDefault [])
|
|
||||||
|
|
||||||
|
|
||||||
silenceFormEditParser : Parser (String -> a) a
|
silenceFormEditParser : Parser (String -> a) a
|
||||||
|
@ -47,6 +53,11 @@ newSilenceFromMatchers matchers =
|
||||||
|> encodeMatchers
|
|> encodeMatchers
|
||||||
|
|
||||||
|
|
||||||
|
newSilenceFromMatchersAndComment : List Data.Matcher.Matcher -> String -> String
|
||||||
|
newSilenceFromMatchersAndComment matchers comment =
|
||||||
|
newSilenceFromMatchers matchers ++ "&comment=" ++ (comment |> percentEncode)
|
||||||
|
|
||||||
|
|
||||||
encodeMatchers : List Utils.Filter.Matcher -> String
|
encodeMatchers : List Utils.Filter.Matcher -> String
|
||||||
encodeMatchers matchers =
|
encodeMatchers matchers =
|
||||||
matchers
|
matchers
|
||||||
|
|
|
@ -5,7 +5,7 @@ module Views.SilenceForm.Types exposing
|
||||||
, SilenceFormFieldMsg(..)
|
, SilenceFormFieldMsg(..)
|
||||||
, SilenceFormMsg(..)
|
, SilenceFormMsg(..)
|
||||||
, emptyMatcher
|
, emptyMatcher
|
||||||
, fromMatchersAndTime
|
, fromMatchersAndCommentAndTime
|
||||||
, fromSilence
|
, fromSilence
|
||||||
, initSilenceForm
|
, initSilenceForm
|
||||||
, parseEndsAt
|
, parseEndsAt
|
||||||
|
@ -67,8 +67,8 @@ type SilenceFormMsg
|
||||||
| AlertGroupsPreview (ApiData (List GettableAlert))
|
| AlertGroupsPreview (ApiData (List GettableAlert))
|
||||||
| SetActiveAlert (Maybe String)
|
| SetActiveAlert (Maybe String)
|
||||||
| FetchSilence String
|
| FetchSilence String
|
||||||
| NewSilenceFromMatchers String (List Utils.Filter.Matcher)
|
| NewSilenceFromMatchersAndComment String Utils.Filter.SilenceFormGetParams
|
||||||
| NewSilenceFromMatchersAndTime String (List Utils.Filter.Matcher) Posix
|
| NewSilenceFromMatchersAndCommentAndTime String (List Utils.Filter.Matcher) String Posix
|
||||||
| SilenceFetch (ApiData GettableSilence)
|
| SilenceFetch (ApiData GettableSilence)
|
||||||
| SilenceCreate (ApiData String)
|
| SilenceCreate (ApiData String)
|
||||||
|
|
||||||
|
@ -194,8 +194,8 @@ defaultDuration =
|
||||||
2 * 60 * 60 * 1000
|
2 * 60 * 60 * 1000
|
||||||
|
|
||||||
|
|
||||||
fromMatchersAndTime : String -> List Utils.Filter.Matcher -> Posix -> SilenceForm
|
fromMatchersAndCommentAndTime : String -> List Utils.Filter.Matcher -> String -> Posix -> SilenceForm
|
||||||
fromMatchersAndTime defaultCreator matchers now =
|
fromMatchersAndCommentAndTime defaultCreator matchers comment now =
|
||||||
{ empty
|
{ empty
|
||||||
| startsAt = initialField (timeToString now)
|
| startsAt = initialField (timeToString now)
|
||||||
, endsAt = initialField (timeToString (addDuration defaultDuration now))
|
, endsAt = initialField (timeToString (addDuration defaultDuration now))
|
||||||
|
@ -208,6 +208,7 @@ fromMatchersAndTime defaultCreator matchers now =
|
||||||
|
|
||||||
else
|
else
|
||||||
List.filterMap (filterMatcherToMatcher >> Maybe.map fromMatcher) matchers
|
List.filterMap (filterMatcherToMatcher >> Maybe.map fromMatcher) matchers
|
||||||
|
, comment = initialField comment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import Views.SilenceForm.Types
|
||||||
, SilenceFormFieldMsg(..)
|
, SilenceFormFieldMsg(..)
|
||||||
, SilenceFormMsg(..)
|
, SilenceFormMsg(..)
|
||||||
, emptyMatcher
|
, emptyMatcher
|
||||||
, fromMatchersAndTime
|
, fromMatchersAndCommentAndTime
|
||||||
, fromSilence
|
, fromSilence
|
||||||
, parseEndsAt
|
, parseEndsAt
|
||||||
, toSilence
|
, toSilence
|
||||||
|
@ -207,11 +207,11 @@ update msg model basePath apiUrl =
|
||||||
in
|
in
|
||||||
( { model | silenceId = silenceId }, cmd )
|
( { model | silenceId = silenceId }, cmd )
|
||||||
|
|
||||||
NewSilenceFromMatchers defaultCreator matchers ->
|
NewSilenceFromMatchersAndComment defaultCreator params ->
|
||||||
( model, Task.perform (NewSilenceFromMatchersAndTime defaultCreator matchers >> MsgForSilenceForm) Time.now )
|
( model, Task.perform (NewSilenceFromMatchersAndCommentAndTime defaultCreator params.matchers params.comment >> MsgForSilenceForm) Time.now )
|
||||||
|
|
||||||
NewSilenceFromMatchersAndTime defaultCreator matchers time ->
|
NewSilenceFromMatchersAndCommentAndTime defaultCreator matchers comment time ->
|
||||||
( { form = fromMatchersAndTime defaultCreator matchers time
|
( { form = fromMatchersAndCommentAndTime defaultCreator matchers comment time
|
||||||
, alerts = Initial
|
, alerts = Initial
|
||||||
, activeAlertId = Nothing
|
, activeAlertId = Nothing
|
||||||
, silenceId = Initial
|
, 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 exposing (Html, a, button, div, fieldset, h1, input, label, legend, span, strong, text, textarea)
|
||||||
import Html.Attributes exposing (class, href)
|
import Html.Attributes exposing (class, href)
|
||||||
import Html.Events exposing (onClick)
|
import Html.Events exposing (onClick)
|
||||||
import Utils.Filter
|
import Utils.Filter exposing (SilenceFormGetParams, emptySilenceFormGetParams)
|
||||||
import Utils.FormValidation exposing (ValidatedField, ValidationState(..))
|
import Utils.FormValidation exposing (ValidatedField, ValidationState(..))
|
||||||
import Utils.Types exposing (ApiData)
|
import Utils.Types exposing (ApiData)
|
||||||
import Utils.Views exposing (checkbox, iconButtonMsg, loading, validatedField, validatedTextareaField)
|
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(..))
|
import Views.SilenceForm.Types exposing (MatcherForm, Model, SilenceForm, SilenceFormFieldMsg(..), SilenceFormMsg(..))
|
||||||
|
|
||||||
|
|
||||||
view : Maybe String -> List Utils.Filter.Matcher -> String -> Model -> Html SilenceFormMsg
|
view : Maybe String -> SilenceFormGetParams -> String -> Model -> Html SilenceFormMsg
|
||||||
view maybeId matchers defaultCreator { form, silenceId, alerts, activeAlertId } =
|
view maybeId { matchers, comment } defaultCreator { form, silenceId, alerts, activeAlertId } =
|
||||||
let
|
let
|
||||||
( title, resetClick ) =
|
( title, resetClick ) =
|
||||||
case maybeId of
|
case maybeId of
|
||||||
|
@ -22,7 +22,7 @@ view maybeId matchers defaultCreator { form, silenceId, alerts, activeAlertId }
|
||||||
( "Edit Silence", FetchSilence silenceId_ )
|
( "Edit Silence", FetchSilence silenceId_ )
|
||||||
|
|
||||||
Nothing ->
|
Nothing ->
|
||||||
( "New Silence", NewSilenceFromMatchers defaultCreator matchers )
|
( "New Silence", NewSilenceFromMatchersAndComment defaultCreator emptySilenceFormGetParams )
|
||||||
in
|
in
|
||||||
div []
|
div []
|
||||||
[ h1 [] [ text title ]
|
[ h1 [] [ text title ]
|
||||||
|
|
|
@ -15,7 +15,7 @@ import Utils.List
|
||||||
import Utils.Views exposing (buttonLink)
|
import Utils.Views exposing (buttonLink)
|
||||||
import Views.FilterBar.Types as FilterBarTypes
|
import Views.FilterBar.Types as FilterBarTypes
|
||||||
import Views.Shared.Dialog as Dialog
|
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(..))
|
import Views.SilenceList.Types exposing (SilenceListMsg(..))
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,7 +114,7 @@ editButton silence =
|
||||||
Expired ->
|
Expired ->
|
||||||
a
|
a
|
||||||
[ class "btn btn-outline-info border-0"
|
[ class "btn btn-outline-info border-0"
|
||||||
, href (newSilenceFromMatchers silence.matchers)
|
, href (newSilenceFromMatchersAndComment silence.matchers silence.comment)
|
||||||
]
|
]
|
||||||
[ text "Recreate"
|
[ text "Recreate"
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in New Issue