Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: move_item_from_lista_to_listb/4 function for moving items between lists #427

Closed
3 tasks done
Tracked by #165
nelsonic opened this issue Sep 16, 2023 · 2 comments
Closed
3 tasks done
Tracked by #165
Assignees
Labels
discuss Share your constructive thoughts on how to make progress with this issue elixir Pull requests that update Elixir code enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies

Comments

@nelsonic
Copy link
Member

nelsonic commented Sep 16, 2023

To aid with _moving _an item from one list to another, we need a little function.

Todo

  • Create the tests: item.cid should be removed from lista and added to listb. πŸ§ͺ
  • Write the function. πŸ§‘β€πŸ’»
  • Ship!! :shipit:

Note: this only applies if the list is not "All" which we should not remove items from;
That's the whole point of the "All" list ...

Thankfully we already have two helper functions we can call for this:

mvp/lib/app/list.ex

Lines 171 to 176 in 15af0f1

def add_item_to_list(item_cid, list_cid, person_id) do
list = get_list_by_cid!(list_cid)
prev_seq = get_list_seq(list)
seq = [item_cid | prev_seq] |> Enum.join(",")
update_list(list, %{seq: seq, person_id: person_id})
end

and:

mvp/lib/app/list.ex

Lines 189 to 199 in 15af0f1

def remove_item_from_list(item_cid, list_cid, person_id) do
list = get_list_by_cid!(list_cid)
# get existing list.seq
seq =
get_list_seq(list)
# remove the item_cid from the list.seq:
|> Useful.remove_item_from_list(item_cid)
|> Enum.join(",")
update_list(list, %{seq: seq, person_id: person_id})
end

So this should be relatively straightforward. πŸ’­

@nelsonic nelsonic added enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished discuss Share your constructive thoughts on how to make progress with this issue elixir Pull requests that update Elixir code labels Sep 16, 2023
@nelsonic nelsonic self-assigned this Sep 16, 2023
@nelsonic nelsonic mentioned this issue Sep 16, 2023
10 tasks
@nelsonic
Copy link
Member Author

This is the function:

  def move_item_from_lista_to_listb(item_cid, lista_cid, listb_cid, person_id) do
    # Remove from List A:
    remove_item_from_list(item_cid, lista_cid, person_id)
    # Add to List B:
    add_item_to_list(item_cid, listb_cid, person_id)
  end

Like I said above, it's simple. Because we already had the two precursor functions thanks to #422

But I'm now thinking that from an Interface perspective what we actually want to do is update the whole list.seq from the client so that we preserve the sequence of the items ... πŸ’­

@nelsonic
Copy link
Member Author

Included in #165 :shipit:
If we decide not to use it, easy to remove. πŸ‘Œ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss Share your constructive thoughts on how to make progress with this issue elixir Pull requests that update Elixir code enhancement New feature or enhancement of existing functionality help wanted If you can help make progress with this issue, please comment! priority-2 Second highest priority, should be worked on as soon as the Priority-1 issues are finished T25m Time Estimate 25 Minutes technical A technical issue that requires understanding of the code, infrastructure or dependencies
Projects
Status: Done
Status: βœ… Done
Development

No branches or pull requests

1 participant