mirror of
https://github.com/prometheus/alertmanager
synced 2025-02-16 10:37:09 +00:00
Support expanding multiple groups
Signed-off-by: stuart nelson <stuartnelson3@gmail.com>
This commit is contained in:
parent
072365a44e
commit
f46adfe46a
@ -8,6 +8,7 @@ module Views.AlertList.Types exposing
|
||||
import Browser.Navigation exposing (Key)
|
||||
import Data.AlertGroup exposing (AlertGroup)
|
||||
import Data.GettableAlert exposing (GettableAlert)
|
||||
import Set exposing (Set)
|
||||
import Utils.Types exposing (ApiData(..), Labels)
|
||||
import Views.FilterBar.Types as FilterBar
|
||||
import Views.GroupBar.Types as GroupBar
|
||||
@ -24,7 +25,7 @@ type AlertListMsg
|
||||
| ToggleSilenced Bool
|
||||
| ToggleInhibited Bool
|
||||
| SetActive (Maybe String)
|
||||
| SetGroup (Maybe Labels)
|
||||
| ActiveGroups Labels
|
||||
| SetTab Tab
|
||||
|
||||
|
||||
@ -41,7 +42,7 @@ type alias Model =
|
||||
, filterBar : FilterBar.Model
|
||||
, tab : Tab
|
||||
, activeId : Maybe String
|
||||
, activeLabels : Maybe Labels
|
||||
, activeGroups : Set Labels
|
||||
, key : Key
|
||||
}
|
||||
|
||||
@ -55,6 +56,6 @@ initAlertList key =
|
||||
, filterBar = FilterBar.initFilterBar key
|
||||
, tab = FilterTab
|
||||
, activeId = Nothing
|
||||
, activeLabels = Nothing
|
||||
, activeGroups = Set.empty
|
||||
, key = key
|
||||
}
|
||||
|
@ -142,5 +142,13 @@ update msg ({ groupBar, alerts, filterBar, receiverBar, alertGroups } as model)
|
||||
SetActive maybeId ->
|
||||
( { model | activeId = maybeId }, Cmd.none )
|
||||
|
||||
SetGroup maybeLabels ->
|
||||
( { model | activeLabels = maybeLabels }, Cmd.none )
|
||||
ActiveGroups activeGroup ->
|
||||
let
|
||||
activeGroups_ =
|
||||
if Set.member activeGroup model.activeGroups then
|
||||
Set.remove activeGroup model.activeGroups
|
||||
|
||||
else
|
||||
Set.insert activeGroup model.activeGroups
|
||||
in
|
||||
( { model | activeGroups = activeGroups_ }, Cmd.none )
|
||||
|
@ -6,6 +6,7 @@ import Dict exposing (Dict)
|
||||
import Html exposing (..)
|
||||
import Html.Attributes exposing (..)
|
||||
import Html.Events exposing (..)
|
||||
import Set exposing (Set)
|
||||
import Types exposing (Msg(..))
|
||||
import Utils.Filter exposing (Filter)
|
||||
import Utils.List
|
||||
@ -46,7 +47,7 @@ groupTabName customGrouping =
|
||||
|
||||
|
||||
view : Model -> Filter -> Html Msg
|
||||
view { alerts, alertGroups, groupBar, filterBar, receiverBar, tab, activeId, activeLabels } filter =
|
||||
view { alerts, alertGroups, groupBar, filterBar, receiverBar, tab, activeId, activeGroups } filter =
|
||||
div []
|
||||
[ div
|
||||
[ class "card mb-5" ]
|
||||
@ -70,12 +71,12 @@ view { alerts, alertGroups, groupBar, filterBar, receiverBar, tab, activeId, act
|
||||
Html.map (MsgForGroupBar >> MsgForAlertList) (GroupBar.view groupBar filter.customGrouping)
|
||||
]
|
||||
]
|
||||
, Utils.Views.apiData (defaultAlertGroups activeId activeLabels) alertGroups
|
||||
, Utils.Views.apiData (defaultAlertGroups activeId activeGroups) alertGroups
|
||||
]
|
||||
|
||||
|
||||
defaultAlertGroups : Maybe String -> Maybe Labels -> List AlertGroup -> Html Msg
|
||||
defaultAlertGroups activeId activeLabels groups =
|
||||
defaultAlertGroups : Maybe String -> Set Labels -> List AlertGroup -> Html Msg
|
||||
defaultAlertGroups activeId activeGroups groups =
|
||||
case groups of
|
||||
[] ->
|
||||
Utils.Views.error "No alert groups found"
|
||||
@ -85,23 +86,23 @@ defaultAlertGroups activeId activeLabels groups =
|
||||
labels_ =
|
||||
Dict.toList labels
|
||||
in
|
||||
alertGroup activeId (Just labels_) labels_ alerts
|
||||
alertGroup activeId (Set.singleton labels_) labels_ alerts
|
||||
|
||||
_ ->
|
||||
div []
|
||||
(List.map
|
||||
(\{ labels, alerts } ->
|
||||
alertGroup activeId activeLabels (Dict.toList labels) alerts
|
||||
alertGroup activeId activeGroups (Dict.toList labels) alerts
|
||||
)
|
||||
groups
|
||||
)
|
||||
|
||||
|
||||
alertGroup : Maybe String -> Maybe Labels -> Labels -> List GettableAlert -> Html Msg
|
||||
alertGroup activeId activeLabels labels alerts =
|
||||
alertGroup : Maybe String -> Set Labels -> Labels -> List GettableAlert -> Html Msg
|
||||
alertGroup activeId activeGroups labels alerts =
|
||||
let
|
||||
groupActive =
|
||||
activeLabels == Just labels
|
||||
Set.member labels activeGroups
|
||||
|
||||
labels_ =
|
||||
case labels of
|
||||
@ -132,7 +133,7 @@ alertGroup activeId activeLabels labels alerts =
|
||||
|
||||
expandButton =
|
||||
expandAlertGroup groupActive labels
|
||||
|> Html.map (\msg -> MsgForAlertList (SetGroup msg))
|
||||
|> Html.map (\msg -> MsgForAlertList (ActiveGroups msg))
|
||||
|
||||
alertCount =
|
||||
List.length alerts
|
||||
@ -157,18 +158,18 @@ alertGroup activeId activeLabels labels alerts =
|
||||
]
|
||||
|
||||
|
||||
expandAlertGroup : Bool -> Labels -> Html (Maybe Labels)
|
||||
expandAlertGroup : Bool -> Labels -> Html Labels
|
||||
expandAlertGroup expanded labels =
|
||||
if expanded then
|
||||
button
|
||||
[ onClick Nothing
|
||||
, class "btn btn-outline-info border-0 active mr-1 mb-3"
|
||||
]
|
||||
[ i [ class "fa fa-minus" ] [] ]
|
||||
let
|
||||
icon =
|
||||
if expanded then
|
||||
"fa-minus"
|
||||
|
||||
else
|
||||
button
|
||||
[ class "btn btn-outline-info border-0 mr-1 mb-3"
|
||||
, onClick (Just labels)
|
||||
]
|
||||
[ i [ class "fa fa-plus" ] [] ]
|
||||
else
|
||||
"fa-plus"
|
||||
in
|
||||
button
|
||||
[ onClick labels
|
||||
, class "btn btn-outline-info border-0 active mr-1 mb-3"
|
||||
]
|
||||
[ i [ class ("fa " ++ icon) ] [] ]
|
||||
|
Loading…
Reference in New Issue
Block a user