From f46adfe46aab8cafa0231f775ed628967fccd692 Mon Sep 17 00:00:00 2001 From: stuart nelson Date: Tue, 7 May 2019 12:08:02 +0200 Subject: [PATCH] Support expanding multiple groups Signed-off-by: stuart nelson --- ui/app/src/Views/AlertList/Types.elm | 7 ++-- ui/app/src/Views/AlertList/Updates.elm | 12 +++++-- ui/app/src/Views/AlertList/Views.elm | 47 +++++++++++++------------- 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/ui/app/src/Views/AlertList/Types.elm b/ui/app/src/Views/AlertList/Types.elm index ad49830b..35a5dc8d 100644 --- a/ui/app/src/Views/AlertList/Types.elm +++ b/ui/app/src/Views/AlertList/Types.elm @@ -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 } diff --git a/ui/app/src/Views/AlertList/Updates.elm b/ui/app/src/Views/AlertList/Updates.elm index ad8e4416..bf0e44f7 100644 --- a/ui/app/src/Views/AlertList/Updates.elm +++ b/ui/app/src/Views/AlertList/Updates.elm @@ -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 ) diff --git a/ui/app/src/Views/AlertList/Views.elm b/ui/app/src/Views/AlertList/Views.elm index 661cbfb5..e830118e 100644 --- a/ui/app/src/Views/AlertList/Views.elm +++ b/ui/app/src/Views/AlertList/Views.elm @@ -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) ] [] ]