From 782ca0fa4fc827c32c02e361d25f30decd2c0cfe Mon Sep 17 00:00:00 2001 From: eikek Date: Sun, 25 Jul 2021 16:03:52 +0200 Subject: [PATCH] Remove a deleted item from search results When an item is deleted in detail view, the results must be updated to reflect the new state. The results are now changed by removing the corresponding item. Fixes: #920 --- modules/webapp/src/main/elm/App/Update.elm | 14 ++++++++--- .../webapp/src/main/elm/Comp/ItemCardList.elm | 20 ++++++++++++++++ .../src/main/elm/Comp/ItemDetail/Model.elm | 9 +++---- .../src/main/elm/Comp/ItemDetail/Update.elm | 24 ++++++++++++------- .../webapp/src/main/elm/Page/Home/Data.elm | 1 + .../webapp/src/main/elm/Page/Home/Update.elm | 3 +++ .../src/main/elm/Page/ItemDetail/Data.elm | 1 + .../src/main/elm/Page/ItemDetail/Update.elm | 6 +++-- 8 files changed, 61 insertions(+), 17 deletions(-) diff --git a/modules/webapp/src/main/elm/App/Update.elm b/modules/webapp/src/main/elm/App/Update.elm index 04b752e0..b5381433 100644 --- a/modules/webapp/src/main/elm/App/Update.elm +++ b/modules/webapp/src/main/elm/App/Update.elm @@ -331,10 +331,18 @@ updateItemDetail lmsg model = ( hm, hc, hs ) = updateHome (Page.Home.Data.SetLinkTarget result.linkTarget) model_ + + ( hm1, hc1, hs1 ) = + case result.removedItem of + Just removedId -> + updateHome (Page.Home.Data.RemoveItem removedId) hm + + Nothing -> + ( hm, hc, hs ) in - ( hm - , Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc ] - , Sub.batch [ Sub.map ItemDetailMsg result.sub, hs ] + ( hm1 + , Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc, hc1 ] + , Sub.batch [ Sub.map ItemDetailMsg result.sub, hs, hs1 ] ) diff --git a/modules/webapp/src/main/elm/Comp/ItemCardList.elm b/modules/webapp/src/main/elm/Comp/ItemCardList.elm index d9087b59..4be8d40f 100644 --- a/modules/webapp/src/main/elm/Comp/ItemCardList.elm +++ b/modules/webapp/src/main/elm/Comp/ItemCardList.elm @@ -46,6 +46,7 @@ type Msg = SetResults ItemLightList | AddResults ItemLightList | ItemCardMsg ItemLight Comp.ItemCard.Msg + | RemoveItem String init : Model @@ -145,6 +146,13 @@ updateDrag dm _ msg model = result.selection result.linkTarget + RemoveItem id -> + UpdateResult { model | results = removeItemById id model.results } + Cmd.none + dm + Data.ItemSelection.Inactive + Comp.LinkTarget.LinkNone + --- View2 @@ -232,3 +240,15 @@ isMultiSelectMode cfg = Data.ItemSelection.Inactive -> False + + +removeItemById : String -> ItemLightList -> ItemLightList +removeItemById id list = + let + filterItem item = + item.id /= id + + filterGroup group = + { group | items = List.filter filterItem group.items } + in + { list | groups = List.map filterGroup list.groups } diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm index 58c44201..65246daf 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Model.elm @@ -276,7 +276,7 @@ type Msg | ItemModalCancelled | RequestDelete | SaveResp (Result Http.Error BasicResult) - | DeleteResp (Result Http.Error BasicResult) + | DeleteResp String (Result Http.Error BasicResult) | GetItemResp (Result Http.Error ItemDetail) | GetProposalResp (Result Http.Error ItemProposals) | RemoveDueDate @@ -352,22 +352,23 @@ type alias UpdateResult = , cmd : Cmd Msg , sub : Sub Msg , linkTarget : LinkTarget + , removedItem : Maybe String } resultModel : Model -> UpdateResult resultModel model = - UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone + UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing resultModelCmd : ( Model, Cmd Msg ) -> UpdateResult resultModelCmd ( model, cmd ) = - UpdateResult model cmd Sub.none Comp.LinkTarget.LinkNone + UpdateResult model cmd Sub.none Comp.LinkTarget.LinkNone Nothing resultModelCmdSub : ( Model, Cmd Msg, Sub Msg ) -> UpdateResult resultModelCmdSub ( model, cmd, sub ) = - UpdateResult model cmd sub Comp.LinkTarget.LinkNone + UpdateResult model cmd sub Comp.LinkTarget.LinkNone Nothing personMatchesOrg : Model -> Bool diff --git a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm index 7e2200f5..6e9ebe1f 100644 --- a/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Comp/ItemDetail/Update.elm @@ -279,6 +279,7 @@ update key flags inav settings msg model = , res9.sub ] , linkTarget = Comp.LinkTarget.LinkNone + , removedItem = Nothing } SetActiveAttachment pos -> @@ -560,7 +561,7 @@ update key flags inav settings msg model = DeleteItemConfirmed -> let cmd = - Api.deleteItem flags model.item.id DeleteResp + Api.deleteItem flags model.item.id (DeleteResp model.item.id) in resultModelCmd ( { model | itemModal = Nothing }, cmd ) @@ -677,6 +678,7 @@ update key flags inav settings msg model = , cmd = Cmd.batch [ res1.cmd, res2.cmd ] , sub = Sub.batch [ res1.sub, res2.sub ] , linkTarget = Comp.LinkTarget.LinkNone + , removedItem = Nothing } GetPersonResp (Err _) -> @@ -720,19 +722,23 @@ update key flags inav settings msg model = SaveNameResp (Err _) -> resultModel { model | nameState = SaveFailed } - DeleteResp (Ok res) -> + DeleteResp removedId (Ok res) -> if res.success then - case inav.next of - Just id -> - resultModelCmd ( model, Page.set key (ItemDetailPage id) ) + let + result_ = + case inav.next of + Just id -> + resultModelCmd ( model, Page.set key (ItemDetailPage id) ) - Nothing -> - resultModelCmd ( model, Page.set key HomePage ) + Nothing -> + resultModelCmd ( model, Page.set key HomePage ) + in + { result_ | removedItem = Just removedId } else resultModel model - DeleteResp (Err _) -> + DeleteResp _ (Err _) -> resultModel model GetItemResp (Ok item) -> @@ -1421,6 +1427,7 @@ update key flags inav settings msg model = , cmd = Cmd.none , sub = Sub.none , linkTarget = lt + , removedItem = Nothing } CustomFieldMsg lm -> @@ -1747,6 +1754,7 @@ withSub ( m, c ) = m.customFieldThrottle ] , linkTarget = Comp.LinkTarget.LinkNone + , removedItem = Nothing } diff --git a/modules/webapp/src/main/elm/Page/Home/Data.elm b/modules/webapp/src/main/elm/Page/Home/Data.elm index 032c922f..8560ca9d 100644 --- a/modules/webapp/src/main/elm/Page/Home/Data.elm +++ b/modules/webapp/src/main/elm/Page/Home/Data.elm @@ -201,6 +201,7 @@ type Msg | RequestReprocessSelected | ReprocessSelectedConfirmed | ClientSettingsSaveResp UiSettings (Result Http.Error BasicResult) + | RemoveItem String type SearchType diff --git a/modules/webapp/src/main/elm/Page/Home/Update.elm b/modules/webapp/src/main/elm/Page/Home/Update.elm index dece6888..55a45ce7 100644 --- a/modules/webapp/src/main/elm/Page/Home/Update.elm +++ b/modules/webapp/src/main/elm/Page/Home/Update.elm @@ -652,6 +652,9 @@ update mId key flags settings msg model = KeyUpPowerSearchbarMsg _ -> withSub ( model, Cmd.none ) + RemoveItem id -> + update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model + --- Helpers diff --git a/modules/webapp/src/main/elm/Page/ItemDetail/Data.elm b/modules/webapp/src/main/elm/Page/ItemDetail/Data.elm index 84ee3605..0d679da7 100644 --- a/modules/webapp/src/main/elm/Page/ItemDetail/Data.elm +++ b/modules/webapp/src/main/elm/Page/ItemDetail/Data.elm @@ -44,4 +44,5 @@ type alias UpdateResult = , cmd : Cmd Msg , sub : Sub Msg , linkTarget : LinkTarget + , removedItem : Maybe String } diff --git a/modules/webapp/src/main/elm/Page/ItemDetail/Update.elm b/modules/webapp/src/main/elm/Page/ItemDetail/Update.elm index 0d0a9a88..1ac23be2 100644 --- a/modules/webapp/src/main/elm/Page/ItemDetail/Update.elm +++ b/modules/webapp/src/main/elm/Page/ItemDetail/Update.elm @@ -46,6 +46,7 @@ update key flags inav settings msg model = ] , sub = Sub.map ItemDetailMsg result.sub , linkTarget = result.linkTarget + , removedItem = result.removedItem } ItemDetailMsg lmsg -> @@ -65,6 +66,7 @@ update key flags inav settings msg model = , cmd = Cmd.batch [ pageSwitch, Cmd.map ItemDetailMsg result.cmd ] , sub = Sub.map ItemDetailMsg result.sub , linkTarget = result.linkTarget + , removedItem = result.removedItem } ItemResp (Ok item) -> @@ -75,10 +77,10 @@ update key flags inav settings msg model = update key flags inav settings (ItemDetailMsg lmsg) model ItemResp (Err _) -> - UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone + UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing ScrollResult _ -> - UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone + UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing UiSettingsUpdated -> let