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

Dataviews Filter search widget: do not use Composite store #64985

Conversation

ciampo
Copy link
Contributor

@ciampo ciampo commented Sep 2, 2024

What?

Extracted from #64723

Refactor the dataviews filter search widget so that it doesn't use the store from useCompositeStore to function.

Why?

See #63704 (comment)

How?

By controlling the activeId state via props, and reacting to the onFocusVisible callback

Testing Instructions

There shouldn't be any noticeably different behaviors — make sure that the following happens both in trunk and in this PR:

  • Open the site editor, select "Pages" from the sidebar
  • Click on the filter icon, and select "author". A dropdown menu should open
    • Make sure that, when the menu opens, no "author" option is highlighted
    • Press tab. Make sure that, as focus moves onto the list of possible "author" choices, the first item in the list gets highlighted
  • Repeat the process, but for the "Status" filter
    • Make sure that, when the dropdown menu appears, the first item is automatically highlighted

Screenshots

Kapture.2024-09-02.at.18.09.44.mp4

Copy link

github-actions bot commented Sep 2, 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: ciampo <mciampini@git.wordpress.org>
Co-authored-by: tyxla <tyxla@git.wordpress.org>

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

@ciampo ciampo requested review from jorgefilipecosta, ntsekouras and a team September 2, 2024 16:18
@ciampo ciampo self-assigned this Sep 2, 2024
@ciampo ciampo added [Type] Enhancement A suggestion for improvement. [Package] DataViews /packages/dataviews labels Sep 2, 2024
@ciampo
Copy link
Contributor Author

ciampo commented Sep 3, 2024

e2e test failures seem related — will look into it

@tyxla tyxla requested a review from ajitbohra as a code owner September 3, 2024 09:46
@tyxla
Copy link
Member

tyxla commented Sep 3, 2024

e2e test failures seem related — will look into it

Yeah, seems like we're not exporting Composite.Typeahead and Composite.Hover as private APIs. Fixed in 7c7975b.

@@ -84,22 +86,37 @@ const getNewValue = (
return [ value ];
};

function generateCompositeItemId(
prefix: string,
filterElement: NormalizedFilter[ 'elements' ][ number ]
Copy link
Member

Choose a reason for hiding this comment

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

Should we directly pass the filter.elements[ 0 ].value? Seems like only the value is necessary to construct the ID. Could potentially simplify the second argument type, too.

store={ compositeStore }
virtualFocus
focusLoop
activeId={ activeCompositeId }
Copy link
Member

Choose a reason for hiding this comment

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

We were previously working with defaultActiveId and not activeId. Are we certain this won't introduce suble differences?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We are using to activeId instead of defaultActiveId since we are switching from using Composite uncontrolled, to controlling its active item ID state.

I moved the defaultActiveId value to the initial state value for activeCompositeId.

I'll look more into it, and report any findings

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic affects the composite widget when opening the dropdown — it basically prevents Composite from automatically picking an active composite item if there is more than one filter operator.

I reviewed the code, and I don't think this change will introduce differences in the current state of the code since the filter.operators array doesn't seem to change while the dialog is open.

If this assumption was ever going to change, I suspect the previous version would have also incurred in some unexpected behaviour

Copy link
Contributor Author

@ciampo ciampo Sep 3, 2024

Choose a reason for hiding this comment

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

In general, the current implementation feels a bit hacky. I wish we didn't have to control the activeId state at all. With more time and and a willingness to tweak this UI a bit, we could also consider having different styles for active vs focused items.

But not in the scope for this PR, and without a high priority.

@ciampo ciampo requested a review from tyxla September 3, 2024 13:10
@ciampo ciampo force-pushed the feat/stabilize-composite/dataviews-search-widget-no-composite-store branch from 7c7975b to 0dc1866 Compare September 3, 2024 13:11
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Tests well and code LGTM, thank you 🚀

packages/components/src/private-apis.ts Show resolved Hide resolved
@ciampo ciampo enabled auto-merge (squash) September 3, 2024 13:20
@ciampo ciampo merged commit 7b7196f into trunk Sep 3, 2024
61 checks passed
@ciampo ciampo deleted the feat/stabilize-composite/dataviews-search-widget-no-composite-store branch September 3, 2024 13:53
@github-actions github-actions bot added this to the Gutenberg 19.2 milestone Sep 3, 2024
@bph bph added the [Feature] DataViews Work surrounding upgrading and evolving views in the site editor and beyond label Sep 11, 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 [Package] DataViews /packages/dataviews [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants