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

Add ChooseParentView to PageListingViewSet #11734

Closed
laymonage opened this issue Mar 7, 2024 · 3 comments
Closed

Add ChooseParentView to PageListingViewSet #11734

laymonage opened this issue Mar 7, 2024 · 3 comments

Comments

@laymonage
Copy link
Member

Is your proposal related to a problem?

The addition of PageListingViewSet in #11485 brings a flat-listing of pages of the same type, a feature similar to how ModelAdmin supports Page models. However, it currently lacks the option to create a new page of that type from the flat listing, as that needs a way to select the parent page for the new page. ModelAdmin handles this by having an intermediary ChooseParentView that gives you a form with only one field: the parent page where you want to create the new page under. It then redirects you to the create page view under that parent page with the correct page type already selected.

It would be nice to have something similar for PageListingViewSet as well.

Describe the solution you'd like

Create a view with a minimal form for choosing the parent page. Add it to the PageListingViewSet, and make it so that the index view links to that new view via the "add" button in the header.

See the ModelAdmin's ChooseParentView implementation for reference:

https://github.com/wagtail-nest/wagtail-modeladmin/blob/742fbe8d5e942ba641af4c25fb181c65ad4858ed/wagtail_modeladmin/views.py#L926-L963

(I don't think we need the template to be customisable, so get_template_names don't need to be implemented.)

We may need the PagePermissionHelper.get_valid_parent_pages() logic to be implemented either in the view or possibly in the PagePermissionPolicy directly:

https://github.com/wagtail-nest/wagtail-modeladmin/blob/742fbe8d5e942ba641af4c25fb181c65ad4858ed/wagtail_modeladmin/helpers/permission.py#L114-L153

Perhaps it's a better idea to implement it in the view, so we can use PagePermissionTester.can_add_subpage(). Using that method in the PagePermissionPolicy is against the plan we have for wagtail/rfcs#92.

Describe alternatives you've considered

Maybe create a subclass of the page CreateView and incorporate the parent page chooser into the create view's form, but I reckon this will introduce more complexity as the page CreateView has always assumed the parent page is already pre-selected.

Additional context

Be aware of wagtail-nest/wagtail-modeladmin#19. We'll likely need to optimise the "valid parent pages" logic to avoid the same issue, so don't take the ModelAdmin implementation as-is.

Working on this

Anyone can contribute to this. Before working on this, I strongly recommend familiarising yourself with:

  • how ModelAdmin's support for pages works,
  • Wagtail's ViewSet mechanism
    • see example usages of ModelViewSet and SnippetViewSet for more details

View our contributing guidelines, add a comment to the issue once you’re ready to start.

@abdlrhman08
Copy link
Contributor

I'll try to give this one a go, I started with creating a custom header template for PageListingViewSet index view that just adds the plus icon. I'll work on the ChooseParentView and the other stuff now. Any more tips on working on this would be really helpful.

@abdlrhman08
Copy link
Contributor

Hey @laymonage, I added the base functionality in abdlrhman08/wagtail@4223cd6, for now I am using the modeladmins get_valid_parents implementaion. I am currently stuck on optimizing get_valid_parents and trying to figure it out. Your help would be greatly appreciated on this issue !

@laymonage
Copy link
Member Author

Added in #11774.

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

No branches or pull requests

2 participants