avo-hq / avo

Build Ruby on Rails apps 10x faster
https://avohq.io
Other
1.43k stars 222 forks source link

Paginated resource selection #2824

Open ddmck opened 1 month ago

ddmck commented 1 month ago

Feature

On the index page of a resource, or when viewing nested resources on a resource show page, when a user selected a one or more records and then cicks on a pagination link/button the selected resources are not persisted.

Ideally a user would be able to select multiple resources across the paginated records and then bulk delete or perform a bulk action.

Right now, it is not clear to the user the the prior resources are no longer selected.

Current workarounds

For smaller collections of resources it is possible to increase the number of items per page to select more than the default pagination amount, but for larger collections this would likely cause memory issues.

Screenshots or screen recordings

https://github.com/avo-hq/avo/assets/3110565/deb847e2-04f7-4546-912a-07aa8a4bbf65

The video shows what happens when selecting a resource from the blog posts on the AVO demo site. When no records are selected the action is disabled, which occurs after changing pages. When navigating back the checkbox briefly shows as selected but I think this is just due to browser caching, as no params are passed in the the pagination request related to selected resources.

Additional context

I have not seen this behavior implemented elsewhere. This could potentially be solved by having a stimulus controller tracking the selected items, or by making a get request when checkboxes are updated, and use turboframes/streams to update the pagination links with the currently selected resources, and then create hidden form fields for the resources not shown on the page.

It might be a good idea to indicate to the user the number of resources currently selected, so that they are not performing actions/deleting records they are unaware of.

adrianthedev commented 1 month ago

As a side-note, I fixed the failing action.

Yeah. this could be a cool feature. I'm thinking of a few things that might prove difficult to build, maintain. It's probably going to land in a paid tier in the future.

The first things that comes to mind when I think about how to implement it is using localStorage and have some kind of JS controller that overlays the selected items somewhere in the UI (the Ui will be tricky to get right). That will ensure that the selection is persisted when the users changes pages. One thing that I don't have an answer for is when to reset that selection. Maybe never and let the user do it manually?

But yeah, a good feature to have