ui: Patch /alerts and /receivers to use api v1
With the previous patch /status and /silences were requested from api v2. Requesting alerts from api v1 is done in a separate commit to be able to revert it once alerts also come from api v2. Signed-off-by: Max Leonard Inden <IndenML@gmail.com>
This commit is contained in:
parent
e4e053b18e
commit
fb86df6add
File diff suppressed because one or more lines are too long
|
@ -18,19 +18,19 @@ escapeRegExp text =
|
|||
|
||||
|
||||
fetchReceivers : String -> Cmd (ApiData (List Receiver))
|
||||
fetchReceivers apiUrl =
|
||||
fetchReceivers basePath =
|
||||
Utils.Api.send
|
||||
(Utils.Api.get
|
||||
(apiUrl ++ "/receivers")
|
||||
(makeApiUrl basePath ++ "/receivers")
|
||||
(field "data" (list (Json.map (\receiver -> Receiver receiver (escapeRegExp receiver)) string)))
|
||||
)
|
||||
|
||||
|
||||
fetchAlerts : String -> Filter -> Cmd (ApiData (List Alert))
|
||||
fetchAlerts apiUrl filter =
|
||||
fetchAlerts basePath filter =
|
||||
let
|
||||
url =
|
||||
String.join "/" [ apiUrl, "alerts" ++ generateQueryString filter ]
|
||||
String.join "/" [ makeApiUrl basePath, "alerts" ++ generateQueryString filter ]
|
||||
in
|
||||
Utils.Api.send (Utils.Api.get url alertsDecoder)
|
||||
|
||||
|
@ -58,3 +58,17 @@ alertDecoder =
|
|||
)
|
||||
(field "startsAt" iso8601Time)
|
||||
(field "generatorURL" Json.string)
|
||||
|
||||
|
||||
makeApiUrl : String -> String
|
||||
makeApiUrl externalUrl =
|
||||
let
|
||||
url =
|
||||
if String.endsWith "/" externalUrl then
|
||||
String.dropRight 1 externalUrl
|
||||
|
||||
else
|
||||
externalUrl
|
||||
in
|
||||
-- For now alerts are still fetched from the v1 API.
|
||||
url ++ "/api/v1"
|
||||
|
|
|
@ -41,7 +41,7 @@ update msg ({ basePath, apiUrl } as model) =
|
|||
NavigateToSilenceView silenceId ->
|
||||
let
|
||||
( silenceView, cmd ) =
|
||||
Views.SilenceView.Updates.update (SilenceViewTypes.InitSilenceView silenceId) model.silenceView apiUrl
|
||||
Views.SilenceView.Updates.update (SilenceViewTypes.InitSilenceView silenceId) model.silenceView basePath apiUrl
|
||||
in
|
||||
( { model | route = SilenceViewRoute silenceId, silenceView = silenceView }
|
||||
, Cmd.map MsgForSilenceView cmd
|
||||
|
@ -104,7 +104,7 @@ update msg ({ basePath, apiUrl } as model) =
|
|||
MsgForSilenceView subMsg ->
|
||||
let
|
||||
( silenceView, cmd ) =
|
||||
Views.SilenceView.Updates.update subMsg model.silenceView apiUrl
|
||||
Views.SilenceView.Updates.update subMsg model.silenceView basePath apiUrl
|
||||
in
|
||||
( { model | silenceView = silenceView }, Cmd.map MsgForSilenceView cmd )
|
||||
|
||||
|
|
|
@ -126,7 +126,7 @@ makeApiUrl externalUrl =
|
|||
else
|
||||
externalUrl
|
||||
in
|
||||
url ++ "/api/v1"
|
||||
url ++ "/api/v2"
|
||||
|
||||
|
||||
andMap : Json.Decoder a -> Json.Decoder (a -> b) -> Json.Decoder b
|
||||
|
|
|
@ -48,8 +48,8 @@ update msg ({ groupBar, filterBar, receiverBar } as model) filter apiUrl basePat
|
|||
in
|
||||
( { model | alerts = Loading, filterBar = newFilterBar, groupBar = newGroupBar, activeId = Nothing }
|
||||
, Cmd.batch
|
||||
[ Api.fetchAlerts apiUrl filter |> Cmd.map (AlertsFetched >> MsgForAlertList)
|
||||
, ReceiverBar.fetchReceivers apiUrl |> Cmd.map (MsgForReceiverBar >> MsgForAlertList)
|
||||
[ Api.fetchAlerts basePath filter |> Cmd.map (AlertsFetched >> MsgForAlertList)
|
||||
, ReceiverBar.fetchReceivers basePath |> Cmd.map (MsgForReceiverBar >> MsgForAlertList)
|
||||
]
|
||||
)
|
||||
|
||||
|
|
|
@ -236,7 +236,7 @@ update msg model basePath apiUrl =
|
|||
Just silence ->
|
||||
( { model | alerts = Loading }
|
||||
, Alerts.Api.fetchAlerts
|
||||
apiUrl
|
||||
basePath
|
||||
{ nullFilter | text = Just (Utils.List.mjoin silence.matchers) }
|
||||
|> Cmd.map (AlertGroupsPreview >> MsgForSilenceForm)
|
||||
)
|
||||
|
|
|
@ -9,8 +9,8 @@ import Utils.Types exposing (ApiData(..))
|
|||
import Views.SilenceView.Types exposing (Model, SilenceViewMsg(..))
|
||||
|
||||
|
||||
update : SilenceViewMsg -> Model -> String -> ( Model, Cmd SilenceViewMsg )
|
||||
update msg model apiUrl =
|
||||
update : SilenceViewMsg -> Model -> String -> String -> ( Model, Cmd SilenceViewMsg )
|
||||
update msg model basePath apiUrl =
|
||||
case msg of
|
||||
FetchSilence id ->
|
||||
( model, getSilence apiUrl id SilenceFetched )
|
||||
|
@ -31,7 +31,7 @@ update msg model apiUrl =
|
|||
, alerts = Loading
|
||||
}
|
||||
, Alerts.Api.fetchAlerts
|
||||
apiUrl
|
||||
basePath
|
||||
{ nullFilter | text = Just (Utils.List.mjoin silence.matchers), showSilenced = Just True }
|
||||
|> Cmd.map AlertGroupsPreview
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue