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

Fix: Changing sorting direction on patterns does nothing. #64508

Conversation

jorgefilipecosta
Copy link
Member

The sorting direction controls are not working for patterns, that happens because we don't include a default sorting field when changing the direction, this PR fixes the issue.

Now when changing the sorting direction, if no sorting field is set changing the sorting direction assigns the first sortable field as the sort-by field.

This bug was reported at #64380 (review) by @t-hamano.

Testing Instructions

Go to the patterns sections, open the view configuration UI and verify the sort controls work as expected.

@jorgefilipecosta jorgefilipecosta added [Type] Bug An existing feature does not function as intended [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Package] DataViews /packages/dataviews labels Aug 14, 2024
Copy link

github-actions bot commented Aug 14, 2024

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: jorgefilipecosta <jorgefilipecosta@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@t-hamano t-hamano self-requested a review August 14, 2024 15:35
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick fix!

This PR works as expected, but I have two questions:

  • Why doesn't this issue occur in Templates or Pages? Sort by never seems to be undefined there 🤔 Are the initial values ​​of the Sort By explicitly set for these?
  • Is it possible that the first field where enableSorting is not false doesn't match the field when shown in the Sort By?

@jorgefilipecosta
Copy link
Member Author

Hi @t-hamano, excellent questions.

  • Why doesn't this issue occur in Templates or Pages?

In both of these cases, there is a default sorting passed on the view, on Templates ascending by title on pages descending by date. So the bug is not noticeable.

Is it possible that the first field where enableSorting is not false doesn't match the field when shown in the Sort By?

No that will not happen because the select HTML element shows the first option element as the selected option.
For example, in this sample, the selected element will be "One"

<select>
  <option value="1">One</option>
  <option value="2">Two</option>
  <option value="3">Three</option>
  <option value="4">Four</option>
  <option value="5">Five</option>
</select>

In our code, we filter the fields for sortable and pass each field as an option, in the order they appear, so the first option will appear as selected.

@t-hamano t-hamano self-requested a review August 15, 2024 10:38
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the detailed explanation! If so, I think this PR makes sense 👍

@jorgefilipecosta jorgefilipecosta merged commit f4fe8d7 into trunk Aug 15, 2024
71 checks passed
@jorgefilipecosta jorgefilipecosta deleted the fix/changing-sorting-directions-on-patterns-does-nothing branch August 15, 2024 12:01
@github-actions github-actions bot added this to the Gutenberg 19.1 milestone Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond [Feature] Patterns A collection of blocks that can be synced (previously reusable blocks) or unsynced [Package] DataViews /packages/dataviews [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants