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
This commit is contained in:
eikek 2021-07-25 16:03:52 +02:00
parent df5b59a7ce
commit 782ca0fa4f
8 changed files with 61 additions and 17 deletions

View File

@ -331,10 +331,18 @@ updateItemDetail lmsg model =
( hm, hc, hs ) = ( hm, hc, hs ) =
updateHome (Page.Home.Data.SetLinkTarget result.linkTarget) model_ 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 in
( hm ( hm1
, Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc ] , Cmd.batch [ Cmd.map ItemDetailMsg result.cmd, hc, hc1 ]
, Sub.batch [ Sub.map ItemDetailMsg result.sub, hs ] , Sub.batch [ Sub.map ItemDetailMsg result.sub, hs, hs1 ]
) )

View File

@ -46,6 +46,7 @@ type Msg
= SetResults ItemLightList = SetResults ItemLightList
| AddResults ItemLightList | AddResults ItemLightList
| ItemCardMsg ItemLight Comp.ItemCard.Msg | ItemCardMsg ItemLight Comp.ItemCard.Msg
| RemoveItem String
init : Model init : Model
@ -145,6 +146,13 @@ updateDrag dm _ msg model =
result.selection result.selection
result.linkTarget result.linkTarget
RemoveItem id ->
UpdateResult { model | results = removeItemById id model.results }
Cmd.none
dm
Data.ItemSelection.Inactive
Comp.LinkTarget.LinkNone
--- View2 --- View2
@ -232,3 +240,15 @@ isMultiSelectMode cfg =
Data.ItemSelection.Inactive -> Data.ItemSelection.Inactive ->
False 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 }

View File

@ -276,7 +276,7 @@ type Msg
| ItemModalCancelled | ItemModalCancelled
| RequestDelete | RequestDelete
| SaveResp (Result Http.Error BasicResult) | SaveResp (Result Http.Error BasicResult)
| DeleteResp (Result Http.Error BasicResult) | DeleteResp String (Result Http.Error BasicResult)
| GetItemResp (Result Http.Error ItemDetail) | GetItemResp (Result Http.Error ItemDetail)
| GetProposalResp (Result Http.Error ItemProposals) | GetProposalResp (Result Http.Error ItemProposals)
| RemoveDueDate | RemoveDueDate
@ -352,22 +352,23 @@ type alias UpdateResult =
, cmd : Cmd Msg , cmd : Cmd Msg
, sub : Sub Msg , sub : Sub Msg
, linkTarget : LinkTarget , linkTarget : LinkTarget
, removedItem : Maybe String
} }
resultModel : Model -> UpdateResult resultModel : Model -> UpdateResult
resultModel model = 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 Msg ) -> UpdateResult
resultModelCmd ( model, cmd ) = 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 Msg, Sub Msg ) -> UpdateResult
resultModelCmdSub ( model, cmd, sub ) = resultModelCmdSub ( model, cmd, sub ) =
UpdateResult model cmd sub Comp.LinkTarget.LinkNone UpdateResult model cmd sub Comp.LinkTarget.LinkNone Nothing
personMatchesOrg : Model -> Bool personMatchesOrg : Model -> Bool

View File

@ -279,6 +279,7 @@ update key flags inav settings msg model =
, res9.sub , res9.sub
] ]
, linkTarget = Comp.LinkTarget.LinkNone , linkTarget = Comp.LinkTarget.LinkNone
, removedItem = Nothing
} }
SetActiveAttachment pos -> SetActiveAttachment pos ->
@ -560,7 +561,7 @@ update key flags inav settings msg model =
DeleteItemConfirmed -> DeleteItemConfirmed ->
let let
cmd = cmd =
Api.deleteItem flags model.item.id DeleteResp Api.deleteItem flags model.item.id (DeleteResp model.item.id)
in in
resultModelCmd ( { model | itemModal = Nothing }, cmd ) resultModelCmd ( { model | itemModal = Nothing }, cmd )
@ -677,6 +678,7 @@ update key flags inav settings msg model =
, cmd = Cmd.batch [ res1.cmd, res2.cmd ] , cmd = Cmd.batch [ res1.cmd, res2.cmd ]
, sub = Sub.batch [ res1.sub, res2.sub ] , sub = Sub.batch [ res1.sub, res2.sub ]
, linkTarget = Comp.LinkTarget.LinkNone , linkTarget = Comp.LinkTarget.LinkNone
, removedItem = Nothing
} }
GetPersonResp (Err _) -> GetPersonResp (Err _) ->
@ -720,19 +722,23 @@ update key flags inav settings msg model =
SaveNameResp (Err _) -> SaveNameResp (Err _) ->
resultModel { model | nameState = SaveFailed } resultModel { model | nameState = SaveFailed }
DeleteResp (Ok res) -> DeleteResp removedId (Ok res) ->
if res.success then if res.success then
case inav.next of let
Just id -> result_ =
resultModelCmd ( model, Page.set key (ItemDetailPage id) ) case inav.next of
Just id ->
resultModelCmd ( model, Page.set key (ItemDetailPage id) )
Nothing -> Nothing ->
resultModelCmd ( model, Page.set key HomePage ) resultModelCmd ( model, Page.set key HomePage )
in
{ result_ | removedItem = Just removedId }
else else
resultModel model resultModel model
DeleteResp (Err _) -> DeleteResp _ (Err _) ->
resultModel model resultModel model
GetItemResp (Ok item) -> GetItemResp (Ok item) ->
@ -1421,6 +1427,7 @@ update key flags inav settings msg model =
, cmd = Cmd.none , cmd = Cmd.none
, sub = Sub.none , sub = Sub.none
, linkTarget = lt , linkTarget = lt
, removedItem = Nothing
} }
CustomFieldMsg lm -> CustomFieldMsg lm ->
@ -1747,6 +1754,7 @@ withSub ( m, c ) =
m.customFieldThrottle m.customFieldThrottle
] ]
, linkTarget = Comp.LinkTarget.LinkNone , linkTarget = Comp.LinkTarget.LinkNone
, removedItem = Nothing
} }

View File

@ -201,6 +201,7 @@ type Msg
| RequestReprocessSelected | RequestReprocessSelected
| ReprocessSelectedConfirmed | ReprocessSelectedConfirmed
| ClientSettingsSaveResp UiSettings (Result Http.Error BasicResult) | ClientSettingsSaveResp UiSettings (Result Http.Error BasicResult)
| RemoveItem String
type SearchType type SearchType

View File

@ -652,6 +652,9 @@ update mId key flags settings msg model =
KeyUpPowerSearchbarMsg _ -> KeyUpPowerSearchbarMsg _ ->
withSub ( model, Cmd.none ) withSub ( model, Cmd.none )
RemoveItem id ->
update mId key flags settings (ItemCardListMsg (Comp.ItemCardList.RemoveItem id)) model
--- Helpers --- Helpers

View File

@ -44,4 +44,5 @@ type alias UpdateResult =
, cmd : Cmd Msg , cmd : Cmd Msg
, sub : Sub Msg , sub : Sub Msg
, linkTarget : LinkTarget , linkTarget : LinkTarget
, removedItem : Maybe String
} }

View File

@ -46,6 +46,7 @@ update key flags inav settings msg model =
] ]
, sub = Sub.map ItemDetailMsg result.sub , sub = Sub.map ItemDetailMsg result.sub
, linkTarget = result.linkTarget , linkTarget = result.linkTarget
, removedItem = result.removedItem
} }
ItemDetailMsg lmsg -> ItemDetailMsg lmsg ->
@ -65,6 +66,7 @@ update key flags inav settings msg model =
, cmd = Cmd.batch [ pageSwitch, Cmd.map ItemDetailMsg result.cmd ] , cmd = Cmd.batch [ pageSwitch, Cmd.map ItemDetailMsg result.cmd ]
, sub = Sub.map ItemDetailMsg result.sub , sub = Sub.map ItemDetailMsg result.sub
, linkTarget = result.linkTarget , linkTarget = result.linkTarget
, removedItem = result.removedItem
} }
ItemResp (Ok item) -> ItemResp (Ok item) ->
@ -75,10 +77,10 @@ update key flags inav settings msg model =
update key flags inav settings (ItemDetailMsg lmsg) model update key flags inav settings (ItemDetailMsg lmsg) model
ItemResp (Err _) -> ItemResp (Err _) ->
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing
ScrollResult _ -> ScrollResult _ ->
UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone UpdateResult model Cmd.none Sub.none Comp.LinkTarget.LinkNone Nothing
UiSettingsUpdated -> UiSettingsUpdated ->
let let