human-essentials icon indicating copy to clipboard operation
human-essentials copied to clipboard

[Investigation] Look into removing Cocoon

Open cielf opened this issue 2 years ago • 2 comments

Summary

Per @dorner, on PR #3496 Cocoon is unfortunately old and unmaintained. Look into removing it

Details

Look into alternatives to Cocoon that will allow us to provide the equivalent functionality. Report back to the planning and grooming meeting (Sunday 10am) with a recommendation as to whether we should replace or vendor in, and some idea of the work involved.

Notes

Per Sean 2023-03-25
"A co-worker replaced cocoon at work with rails 7 stuff (hotwire/turbo) — he said he followed what was in this SO post: https://stackoverflow.com/questions/71713303/rails-7-dynamic-nested-forms-with-hotwire-turbo-frames "

Criteria for completion

  • [ ] Investigation
  • [ ] Alternatives
  • [ ] List of things we need to touch
  • [ ] Reporting back to the planning and grooming meeting

cielf avatar Apr 23 '23 15:04 cielf

Hi @cielf, do you know this gem https://github.com/arielj/vanilla-nested? it is well-maintained and also doesn't depend on jQuery. what do you think about it? do you know how many places we need to update?

JuanVqz avatar Oct 06 '23 21:10 JuanVqz

That gem doesn't seem to be super popular (only 115 stars). With Rails I've found that jumping towards using gems for things can bite us in the long run as many of them stop being maintained, or don't quite do what we wanted them to. It shouldn't be too much code to roll our own, especially if we can use Stimulus for it.

It looks like there are around 10 places in the app total that use it, but many of those are funneled through one helper method, add_line_item_button.

dorner avatar Oct 12 '23 00:10 dorner

Is removing cocoon still on the Todo list?

I was thinking of tackling this. I was thinking that we could reuse request behavior and replace:

<div class="col-xs-12">
  <%= add_line_item_button f, "#transfer_line_items" %>
</div>

with

<%= add_item_button('Add Another Item') do %>
  <%= render 'item_request', form: form, object: @partner_request.item_requests.build %>
<% end %>

Edit: this would likely require making the add button method and the stimulus controller a bit more generic but the changes seem pretty reasonable to do.

elasticspoon avatar Mar 06 '24 00:03 elasticspoon

Sure, this would be great. The fewer dependencies, the better.

dorner avatar Mar 07 '24 02:03 dorner