Let the browser remember the creator of a silence (#1112)
* wire default creator through Elm * wire defaultCreator into localStorage * add ui/bindata.go * fix indentation * change defaultCreator type from (Maybe String) to String use an empty string as default value * update ui/bindata.go
This commit is contained in:
parent
266baa089c
commit
af63c85161
|
@ -15,6 +15,11 @@
|
|||
}
|
||||
</script>
|
||||
<script src="script.js"></script>
|
||||
<script>Elm.Main.embed(document.body, { production: true })</script>
|
||||
<script>
|
||||
var app = Elm.Main.embed(document.body, { production: true, defaultCreator: window.localStorage.getItem('defaultCreator') });
|
||||
app.ports.persistDefaultCreator.subscribe(function(name) {
|
||||
window.localStorage.setItem('defaultCreator', name);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -62,6 +62,11 @@ init flags location =
|
|||
|> Json.decodeValue (Json.field "production" Json.bool)
|
||||
|> Result.withDefault False
|
||||
|
||||
defaultCreator =
|
||||
flags
|
||||
|> Json.decodeValue (Json.field "defaultCreator" Json.string)
|
||||
|> Result.withDefault ""
|
||||
|
||||
apiUrl =
|
||||
if prod then
|
||||
Api.makeApiUrl location.pathname
|
||||
|
@ -88,6 +93,7 @@ init flags location =
|
|||
libUrl
|
||||
Loading
|
||||
Loading
|
||||
defaultCreator
|
||||
)
|
||||
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ type alias Model =
|
|||
, libUrl : String
|
||||
, bootstrapCSS : ApiData String
|
||||
, fontAwesomeCSS : ApiData String
|
||||
, defaultCreator : String
|
||||
}
|
||||
|
||||
|
||||
|
@ -45,6 +46,7 @@ type Msg
|
|||
| UpdateFilter String
|
||||
| BootstrapCSSLoaded (ApiData String)
|
||||
| FontAwesomeCSSLoaded (ApiData String)
|
||||
| SetDefaultCreator String
|
||||
|
||||
|
||||
type Route
|
||||
|
|
|
@ -31,9 +31,9 @@ update msg ({ basePath, apiUrl } as model) =
|
|||
List.map (\( k, v ) -> Matcher False k v) labels
|
||||
|
||||
( silenceForm, cmd ) =
|
||||
Views.SilenceForm.Updates.update (NewSilenceFromMatchers matchers) model.silenceForm basePath apiUrl
|
||||
Views.SilenceForm.Updates.update (NewSilenceFromMatchers model.defaultCreator matchers) model.silenceForm basePath apiUrl
|
||||
in
|
||||
( { model | silenceForm = silenceForm }, Cmd.map MsgForSilenceForm cmd )
|
||||
( { model | silenceForm = silenceForm }, cmd )
|
||||
|
||||
NavigateToAlerts filter ->
|
||||
let
|
||||
|
@ -68,7 +68,7 @@ update msg ({ basePath, apiUrl } as model) =
|
|||
, if keep then
|
||||
Cmd.none
|
||||
else
|
||||
Task.perform (NewSilenceFromMatchers >> MsgForSilenceForm) (Task.succeed [])
|
||||
Task.perform (NewSilenceFromMatchers model.defaultCreator >> MsgForSilenceForm) (Task.succeed [])
|
||||
)
|
||||
|
||||
NavigateToSilenceFormEdit uuid ->
|
||||
|
@ -125,10 +125,13 @@ update msg ({ basePath, apiUrl } as model) =
|
|||
( silenceForm, cmd ) =
|
||||
Views.SilenceForm.Updates.update msg model.silenceForm basePath apiUrl
|
||||
in
|
||||
( { model | silenceForm = silenceForm }, Cmd.map MsgForSilenceForm cmd )
|
||||
( { model | silenceForm = silenceForm }, cmd )
|
||||
|
||||
BootstrapCSSLoaded css ->
|
||||
( { model | bootstrapCSS = css }, Cmd.none )
|
||||
|
||||
FontAwesomeCSSLoaded css ->
|
||||
( { model | fontAwesomeCSS = css }, Cmd.none )
|
||||
|
||||
SetDefaultCreator name ->
|
||||
( { model | defaultCreator = name }, Cmd.none )
|
||||
|
|
|
@ -82,10 +82,10 @@ currentView model =
|
|||
SilenceList.view model.silenceList
|
||||
|
||||
SilenceFormNewRoute keep ->
|
||||
SilenceForm.view Nothing model.silenceForm |> Html.map MsgForSilenceForm
|
||||
SilenceForm.view Nothing model.defaultCreator model.silenceForm |> Html.map MsgForSilenceForm
|
||||
|
||||
SilenceFormEditRoute silenceId ->
|
||||
SilenceForm.view (Just silenceId) model.silenceForm |> Html.map MsgForSilenceForm
|
||||
SilenceForm.view (Just silenceId) "" model.silenceForm |> Html.map MsgForSilenceForm
|
||||
|
||||
TopLevelRoute ->
|
||||
Utils.Views.loading
|
||||
|
|
|
@ -60,8 +60,8 @@ type SilenceFormMsg
|
|||
| PreviewSilence
|
||||
| AlertGroupsPreview (ApiData (List Alert))
|
||||
| FetchSilence String
|
||||
| NewSilenceFromMatchers (List Matcher)
|
||||
| NewSilenceFromMatchersAndTime (List Matcher) Time
|
||||
| NewSilenceFromMatchers String (List Matcher)
|
||||
| NewSilenceFromMatchersAndTime String (List Matcher) Time
|
||||
| SilenceFetch (ApiData Silence)
|
||||
| SilenceCreate (ApiData SilenceId)
|
||||
|
||||
|
@ -172,12 +172,13 @@ defaultDuration =
|
|||
2 * Time.hour
|
||||
|
||||
|
||||
fromMatchersAndTime : List Matcher -> Time -> SilenceForm
|
||||
fromMatchersAndTime matchers now =
|
||||
fromMatchersAndTime : String -> List Matcher -> Time -> SilenceForm
|
||||
fromMatchersAndTime defaultCreator matchers now =
|
||||
{ empty
|
||||
| startsAt = initialField (timeToString now)
|
||||
, endsAt = initialField (timeToString (now + defaultDuration))
|
||||
, duration = initialField (durationFormat defaultDuration)
|
||||
, createdBy = initialField defaultCreator
|
||||
, matchers =
|
||||
-- If no matchers were specified, add an empty row
|
||||
if List.isEmpty matchers then
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
module Views.SilenceForm.Updates exposing (update)
|
||||
port module Views.SilenceForm.Updates exposing (update)
|
||||
|
||||
import Alerts.Api
|
||||
import Silences.Api
|
||||
import Task
|
||||
import Time
|
||||
import Types exposing (Msg(MsgForSilenceForm, SetDefaultCreator))
|
||||
import Navigation
|
||||
import Utils.Date exposing (timeFromString)
|
||||
import Utils.List
|
||||
|
@ -169,14 +170,18 @@ updateForm msg form =
|
|||
{ form | matchers = matchers }
|
||||
|
||||
|
||||
update : SilenceFormMsg -> Model -> String -> String -> ( Model, Cmd SilenceFormMsg )
|
||||
update : SilenceFormMsg -> Model -> String -> String -> ( Model, Cmd Msg )
|
||||
update msg model basePath apiUrl =
|
||||
case msg of
|
||||
CreateSilence ->
|
||||
case toSilence model.form of
|
||||
Just silence ->
|
||||
( { model | silenceId = Loading }
|
||||
, Silences.Api.create apiUrl silence |> Cmd.map SilenceCreate
|
||||
, Cmd.batch
|
||||
[ Silences.Api.create apiUrl silence |> Cmd.map (SilenceCreate >> MsgForSilenceForm)
|
||||
, persistDefaultCreator silence.createdBy
|
||||
, Task.succeed silence.createdBy |> Task.perform SetDefaultCreator
|
||||
]
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
|
@ -199,11 +204,11 @@ update msg model basePath apiUrl =
|
|||
in
|
||||
( { model | silenceId = silenceId }, cmd )
|
||||
|
||||
NewSilenceFromMatchers matchers ->
|
||||
( model, Task.perform (NewSilenceFromMatchersAndTime matchers) Time.now )
|
||||
NewSilenceFromMatchers defaultCreator matchers ->
|
||||
( model, Task.perform (NewSilenceFromMatchersAndTime defaultCreator matchers >> MsgForSilenceForm) Time.now )
|
||||
|
||||
NewSilenceFromMatchersAndTime matchers time ->
|
||||
( { form = fromMatchersAndTime matchers time
|
||||
NewSilenceFromMatchersAndTime defaultCreator matchers time ->
|
||||
( { form = fromMatchersAndTime defaultCreator matchers time
|
||||
, alerts = Initial
|
||||
, silenceId = Initial
|
||||
}
|
||||
|
@ -211,11 +216,11 @@ update msg model basePath apiUrl =
|
|||
)
|
||||
|
||||
FetchSilence silenceId ->
|
||||
( model, Silences.Api.getSilence apiUrl silenceId SilenceFetch )
|
||||
( model, Silences.Api.getSilence apiUrl silenceId (SilenceFetch >> MsgForSilenceForm) )
|
||||
|
||||
SilenceFetch (Success silence) ->
|
||||
( { model | form = fromSilence silence }
|
||||
, Task.perform identity (Task.succeed PreviewSilence)
|
||||
, Task.perform identity (Task.succeed (MsgForSilenceForm PreviewSilence))
|
||||
)
|
||||
|
||||
SilenceFetch _ ->
|
||||
|
@ -228,7 +233,7 @@ update msg model basePath apiUrl =
|
|||
, Alerts.Api.fetchAlerts
|
||||
apiUrl
|
||||
{ nullFilter | text = Just (Utils.List.mjoin silence.matchers) }
|
||||
|> Cmd.map AlertGroupsPreview
|
||||
|> Cmd.map (AlertGroupsPreview >> MsgForSilenceForm)
|
||||
)
|
||||
|
||||
Nothing ->
|
||||
|
@ -251,3 +256,6 @@ update msg model basePath apiUrl =
|
|||
}
|
||||
, Cmd.none
|
||||
)
|
||||
|
||||
|
||||
port persistDefaultCreator : String -> Cmd msg
|
||||
|
|
|
@ -13,8 +13,8 @@ import Utils.FormValidation exposing (ValidationState(..), ValidatedField)
|
|||
import Views.SilenceForm.Types exposing (Model, SilenceFormMsg(..), SilenceFormFieldMsg(..), SilenceForm)
|
||||
|
||||
|
||||
view : Maybe SilenceId -> Model -> Html SilenceFormMsg
|
||||
view maybeId { form, silenceId, alerts } =
|
||||
view : Maybe SilenceId -> String -> Model -> Html SilenceFormMsg
|
||||
view maybeId defaultCreator { form, silenceId, alerts } =
|
||||
let
|
||||
( title, resetClick ) =
|
||||
case maybeId of
|
||||
|
@ -22,7 +22,7 @@ view maybeId { form, silenceId, alerts } =
|
|||
( "Edit Silence", FetchSilence silenceId )
|
||||
|
||||
Nothing ->
|
||||
( "New Silence", NewSilenceFromMatchers [] )
|
||||
( "New Silence", NewSilenceFromMatchers defaultCreator [] )
|
||||
in
|
||||
div []
|
||||
[ h1 [] [ text title ]
|
||||
|
|
|
@ -100,7 +100,7 @@ editButton silence =
|
|||
a
|
||||
[ class "btn btn-outline-info border-0"
|
||||
, href "#/silences/new?keep=1"
|
||||
, onClick (NewSilenceFromMatchers silence.matchers |> MsgForSilenceForm)
|
||||
, onClick (NewSilenceFromMatchers silence.createdBy silence.matchers |> MsgForSilenceForm)
|
||||
]
|
||||
[ text "Recreate"
|
||||
]
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue