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

Rearrange order of Snippets in ModelViewSet index view #10816

Open
Timusan opened this issue Aug 23, 2023 · 6 comments
Open

Rearrange order of Snippets in ModelViewSet index view #10816

Timusan opened this issue Aug 23, 2023 · 6 comments

Comments

@Timusan
Copy link

Timusan commented Aug 23, 2023

Is your proposal related to a problem?

With the deprecation of ModelAdmin in favor of Snippets we lose the functionality delivered by Wagtail Orderable: Ordering Snippets in the Index view by the use of drag & drop.

Describe the solution you'd like

As is already the case for a listing of Page models (using the "Sort menu order" feature), enable Snippets to be ordered by drag & drop. It seems Wagtail admin's core already has the functionality build in. Enabling custom sort order this way would, as with Pages, negate the sorting columns. Clicking on a header column for sort disables the drag & drop again.

The above module, that does this for ModelAdmin, adds in a sort_order field to do its bidding, yet extending the functionality that the Pages Index already uses would fit more as no third-party package is needed.

@abhinav700
Copy link

@Timusan I would like to work on this issue. Can you please assign it to me.

@Timusan
Copy link
Author

Timusan commented Sep 17, 2023

@abhinav700 Awesome that you want to work on this! However, I am not the maintainer of the Wagtail repo so I am unable to assign tickets to someone I'm afraid.

@lb-
Copy link
Member

lb- commented Sep 17, 2023

@abhinav700 - I'm not sure that this functionality is suited to Wagtail core. It would need some discussion on how you intend to implement this before any kind of PR or Dev starts.

I think the best solution would be for the existing package, or a new package, be managed by the community for this kind of thing.

There is some functionality for ordering in the admin (pages), maybe it's worth exploring making that JS code reusable with migrating it to Stimulus. This would pave the way for part of this functionality to be usable in Snippets.

If you're keen on contributing that JavaScript change, I can raise a new issue that specifies what's needed.

@abhinav700
Copy link

@lb- Yeah, I would like to contribute that javascript change. Can you please raise that issue?

@lb-
Copy link
Member

lb- commented Sep 18, 2023

@abhinav700 - #10909 created.

@gasman
Copy link
Collaborator

gasman commented Apr 25, 2024

Now that #10909 is in, we're in a good position to consider what the server-side code for this would look like. Proposed outline:

  • TBD: decide whether this functionality will be specific to snippets, or available to all ModelViewSet-registered models. If we're following the same UI as pages, then the reordering handles will replace the bulk actions checkboxes, and currently those are snippet-specific. However, the below assumes we're applying this to ModelViewSet as a whole.
  • ModelViewSet accepts an optional sort_order_field parameter; if the model defines a sort_order_field attribute (the wagtail.models.Orderable mixin does this, although as far as I can see it's not currently used for anything), ModelViewSet will automatically pick that up.
  • If sort_order_field is specified, ModelViewSet will pass this on to its Index and Create views, and register an additional 'reorder' view to handle the POST requests made by the reordering interface on the index.
  • The reordering operation will be available to users with 'publish' permission for models that extend DraftStateMixin, and 'change' permission for models that do not.
  • wagtail.admin.views.generic.models.CreateView will be updated so that whenever sort_order_field is defined, newly-created instances will have that field populated with the next available sort order index.
  • wagtail.admin.views.generic.models.IndexView will be updated so that whenever sort_order_field is defined, an item is added to the top action menu allowing users with the appropriate permission to set ordering. When this is activated, the bulk actions checkboxes will be replaced with the w-orderable drag-to-reorder UI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

4 participants