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

Sort/filter the search results of a PageChooserBlock modal #8557

Open
sighmon opened this issue May 18, 2022 · 1 comment
Open

Sort/filter the search results of a PageChooserBlock modal #8557

sighmon opened this issue May 18, 2022 · 1 comment

Comments

@sighmon
Copy link

sighmon commented May 18, 2022

Is your proposal related to a problem?

We'd like to be able to order and filter the search results of a PageChooserBlock modal.

Describe the solution you'd like

  • Ability to click on the column headings TITLE | UPDATED | TYPE | STATUS to be able to sort the results by that column
  • Ability to filter search results by page type by clicking on the page_type

Describe alternatives you've considered

None yet.

Additional context

Screenshot of our page chooser modal in Wagtail admin with the columns we'd like to be able to sort by highlighted in the red box:
wagtail-admin-page-chooser

This is what our chooser_blocks.py currently looks like:

...
class EventAndArticlePageChooserBlock(PageChooserBlock):
    """Select appropriate API representation based on page type."""

    def __init__(self, **kwargs):
        """Overwrite __init__ to only allow event pages and article pages."""
        kwargs["page_type"] = (
            "events.EventPage",
            "articles.ArticlePage",
            "education.EducationEvent",
            "education.EducationResource",
            "collectables.CreatorPage",
        )
        super().__init__(**kwargs)

    def get_api_representation(self, value, context=None):
        """Return API representation based on page type."""
        if value is None:  # is an event has been deleted
            return None
        if ("ArticlePage" in str(value.specific_class)
                or "EducationResource" in str(value.specific_class)):
            return ArticlePageCardSerializer().to_representation(value.specific)
        if ("CreatorPage" in str(value.specific_class)):
            return CreatorPageCardSerializer().to_representation(value.specific)
        return EventCardSerializer().to_representation(value.specific)


class RelatedEventsAndArticlesBlock(StructBlock):
    """A block that displays related pages in a carousel format."""

    heading = CharBlock()
    pages = ListBlock(EventAndArticlePageChooserBlock())

    class Meta:
        label = "Related Pages"
...
@thibaudcolas
Copy link
Member

Note from #4707 – it’d also be nice to have a way to filter the pages based on whether they are valid choices for the chooser.

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