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

1756 add button to remove holds on an item #1835

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

RudyOnRails
Copy link
Collaborator

@RudyOnRails RudyOnRails commented Feb 9, 2025

What it does

Adds a new button to the admin/item's holds view so that individual holds may be ended. Originally the ticket discussed removing the hold entirely but after some discussion it was decided to set the ended_at attribute so our future selves may benefit from the data.

Why it is important

This would resolve #1756

UI Change Screenshot

BEFORE

Screen Shot 2025-02-09 at 3 28 17 PM

AFTER

Screen Shot 2025-02-09 at 3 33 23 PM

Implementation notes

This is my first PR on this project, and my return to coding after taking a year sabbatical, so just a heads-up I may be am rusty and appreciate and feedback.

One thing to confirm is the new "actions" column (see screenshot). In other apps I've worked on in the past we've used this column for a general one-size-fits-all place to put actions. Let me know if there is another solution we'd like to use.

@jim jim requested review from a team and removed request for a team February 12, 2025 01:33
@@ -196,4 +196,24 @@ def setup
reloaded_hold_ids = all(".item-holds-table tr[data-hold-id]").pluck("data-hold-id")
assert_equal expected_hold_ids, reloaded_hold_ids
end

test "ending a specific hold on an item" do
# use factory bot to create a few started holds
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TIL about create_list. So useful!

@@ -1,8 +1,9 @@
module Admin
module Items
class HoldsController < BaseController
before_action :set_item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love to see some refactoring 😄

@@ -11,6 +12,18 @@ def index
holds_scope.active
end
end

def remove
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could also see this using the destroy controller action/HTTP DELETE method. I think it's a little better to use one of the default actions whenever possible, although we definitely have our share of custom ones as well in the app.

Copy link
Collaborator Author

@RudyOnRails RudyOnRails Feb 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good thought! I think originally it was proper if we were going to destroy the hold, but since we decided to just timestamp ended_at I felt something else was appropriate. I considered using the PATCH/create combo but for some reason I didn't; can't remember.

Do you prefer something like this that is more generic?

      def update
        @hold = @item.holds.find(params[:hold_id])
        @hold.update(hold_params)
        redirect_to admin_item_holds_path(@item), flash: {success: "Hold updated."}, status: :see_other
      end

Additionally - when I was working on this I remembered a team I worked on where we discussed creating new controllers for variations of main resources, for example we could have a single concern EndedHoldsController where we simply POST/create.

Where does your intuition point to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel too strongly to be honest. I'd like to say we have a strong pattern in the app for this kind of thing, but it's probably a bit ad-hoc since we've had a lot of different people/perspectives in the code over the years.

I guess whether the hold is deleted or not depends on the perspective: in the database we're not deleting it, but from the UI perspective it's gone! But if we're to say that we're going to keep the controllers in line with the the database-view, then I agree that this isn't really deleting the hold.

I actually like the new controller option. Now that you mention it, I did something similar to implement reordering of the holds to avoid overloading the update action:

class PositionsController < BaseController
def update
@hold = @item.active_holds.find(params[:hold_id])
@hold.insert_at(params[:position].to_i)
@holds = @item.active_holds.ordered_by_position.includes(:member)
respond_to do |format|
format.turbo_stream {
render turbo_stream: turbo_stream.replace("holds-list",
render_to_string(partial: "admin/items/holds/list", locals: {holds: @holds}))
}
end
end
end

So I guess that's my preference, but TBH this is also totally fine as-is and there are other things to implement. I'll leave it up to you if you want to change this or merge it as-is and move on to the next thing 😄. I appreciate the thought you put into this!

@jim
Copy link
Member

jim commented Feb 14, 2025

I forgot to mention it in the review, but I think the Actions column is a good pattern to use here.

@RudyOnRails
Copy link
Collaborator Author

RudyOnRails commented Feb 14, 2025

I forgot to mention it in the review, but I think the Actions column is a good pattern to use here.

@jim Thanks for the excellent review! Very appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add delete buttons to the item holds list
2 participants