Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Conversation

@Aljullu
Copy link
Contributor

@Aljullu Aljullu commented Dec 3, 2019

Fixes #1134.
Fixes #1135.

Follow-up of #1255.

Accessibility

Screenshots

Peek 2019-12-03 11-50

How to test the changes in this Pull Request:

  1. Add a Filter Products by Attribute block to a post and set its Display Style to Dropdown and the Query Type to AND.
  2. Preview the post and interact with the filter (search terms, add them, remove them, repeat only using the keyboard, using a screen reader, etc.).
  3. Verify everything works as expected.
  4. Verify there are no regression in the same component when Query Type is set to OR.

@Aljullu Aljullu added status: needs review type: enhancement The issue is a request for an enhancement. skip-changelog PRs that you don't want to appear in the changelog. labels Dec 3, 2019
@Aljullu Aljullu requested a review from a team December 3, 2019 11:05
@Aljullu Aljullu self-assigned this Dec 3, 2019
@nerrad
Copy link
Contributor

nerrad commented Dec 3, 2019

So to clarify (going by by the gif alone), is AND intended to mean that you can only select one attribute term to query by? Why is this the route taken instead of AND meaning all the selected terms must exist vs OR where any of the terms exist?

It's quite possible this is a limitation of attribute term queries for Woo that I'm not aware of

@Aljullu Aljullu changed the base branch from add/attributefilter-dropdown-display to master December 3, 2019 13:49
@Aljullu Aljullu force-pushed the add/attributefilter-dropdown-and-display branch from 1d43a7f to b1ceb67 Compare December 3, 2019 13:55
@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 3, 2019

So to clarify (going by by the gif alone), is AND intended to mean that you can only select one attribute term to query by? Why is this the route taken instead of AND meaning all the selected terms must exist vs OR where any of the terms exist?

It's quite possible this is a limitation of attribute term queries for Woo that I'm not aware of

@nerrad that's to keep feature-parity with the current widgets. But I would love to do research at some point and see if this can be improved so instead of tying up the dropdown style to the Query Type, we add another attribute to allow single/multiple select. So you could have an AND dropdown that allows selecting multiple filters.

Is that something we might want to pursue in the short-term? I would create an issue if that's the case.

For reference: p6riRB-4CG-p2.

@nerrad
Copy link
Contributor

nerrad commented Dec 3, 2019

Is that something we might want to pursue in the short-term? I would create an issue if that's the case.

I think we should consider it. While I appreciate at a minimum reaching feature parity with existing widgets, I also think we have an opportunity to introduce new enhancements that make the blocks more appealing over existing widgets (which can potentially help with adoption).

So for clarity, I see the following query options:

  1. OR which allows for selecting multiple items to query by (list and dropdown behave similarly). This means that joins are including results that match against any of the terms.
  2. AND with single selection: allows for selecting a single terms to query by (list becomes radios, dropdown is single select). This means that joins are including a match on that selected term which must be present.
  3. AND with multiple selection: allows for selecting multiple terms to query by (list becomes checkboxes, dropdown is multiple select). This means that joins are including a match against ALL selected terms which must be present in the results.

I don't know if such queries are even feasible with the Woo data model, so the issue should explore that as well.

All of the above can be copied into the issue.

This particular pull then is concerned with item 2 (I'll review from that context).

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 3, 2019

AND with single selection:

Actually, if we only allow single selection, it doesn't matter if it's AND or OR, right? So I would hide the Query Type option in that case. Something like this:
Peek 2019-12-03 16-28

I also wonder if we should allow the List display style with single selection. We could implement it with radio boxes. Is that something that would be useful?

@nerrad
Copy link
Contributor

nerrad commented Dec 3, 2019

it doesn't matter if it's AND or OR, right? So I would hide the Query Type option in that case.

I think it does. OR is always multiple selection. However "AND" could be either single or multiple depending on how the selections apply to the final query eg. And: "Blue AND Yellow" Or: "Blue OR Yellow". So one way of doing it would be to flip the controls around so that if they select AND, there is a Single or Multiple controls. If it's "OR" then no single/multiple control.

Should we move this specific convo to a new issue though or were you thinking of just getting it done in this pull (which I'd be fine with assuming it won't take too much more time and the resulting query is okay to do server side).

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

Just a few comments, but otherwise looking good. I've reviewed this assuming we would merge as is and continue the conversation about multiple selections for an AND query type in a separate issue. Obviously things will change if you decide to implement that in this pull.

Comment on lines 45 to 62
const stateReducer = ( state, changes ) => {
switch ( changes.type ) {
case Downshift.stateChangeTypes.keyDownEnter:
case Downshift.stateChangeTypes.clickItem:
return {
...changes,
highlightedIndex: state.highlightedIndex,
isOpen: multiple,
inputValue: '',
};
case Downshift.stateChangeTypes.blurInput:
case Downshift.stateChangeTypes.mouseUp:
return {
...changes,
inputValue: state.inputValue,
};
default:
return changes;
Copy link
Contributor

Choose a reason for hiding this comment

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

One of those times where I wish we had performance measuring tools to know whether we should wrap this in useCallback (memoized on the multiple prop). I'm on the fence. Being this is a reducer passed through to Downshift, and in particular the wrapping component, I think there's value in wrapping this in useCallback here. Especially since parent components in a tree using this component are likely to re-render (filters due to attribute count changes?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Converting it to useCallback makes sense, I did the change in 9c7c8c0.

queryType: blockAttributes.queryType,
},
queryState,
queryState: filterAvailableFilters ? queryState : null,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having trouble grokking the purpose of this. Can you explain why this was needed?

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 is used for the List display style with the AND query type, so filters that would display 0 results are hidden:
Peek 2019-12-03 17-50

In 27eea78, I updated the logic so available filters are only filtered in the case I said (style: List and query: AND).

filterAddedName,
filterRemovedName
),
'assertive'
Copy link
Contributor

Choose a reason for hiding this comment

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

From this doc it seems like this should be 'polite' not assertive. What rationale is being used for using 'assertive' here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal was so it announces the filter change before announcing the current focused button. But it doesn't seem to work anyway, so removing it: f2f3c7c.

speak(
sprintf(
__(
'%s filter replaced with %s.',
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be good to add translator comment here maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! Done in 8d100bd.

} else if ( filterAddedName ) {
speak(
sprintf(
__( '%s filter added.', 'woo-gutenberg-products-block' ),
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here, should we add translator comments? "filter" could potentially have different meanings in different contexts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in 8d100bd.

const checkedOption = displayedOptions.find(
( option ) => option.value === checkedValue
);
const onChange = ( replace ) => ( checkedValue ) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot happening here. I'd still wrap (checkedValue) => { /**/ } in a useCallback.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, done in 9c7c8c0.

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 3, 2019

Should we move this specific convo to a new issue though or were you thinking of just getting it done in this pull (which I'd be fine with assuming it won't take too much more time and the resulting query is okay to do server side).

I would prefer to do it in a follow-up (I usually prefer to keep PRs small). I created an issue here: #1311 and added some feedback to your last comment.

@Aljullu Aljullu force-pushed the add/attributefilter-dropdown-and-display branch 2 times, most recently from 14e93b2 to 27eea78 Compare December 3, 2019 16:58
@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 3, 2019

Thanks for the review @nerrad. This is ready for another look!

@Aljullu Aljullu requested a review from nerrad December 3, 2019 17:03
Copy link
Member

@mikejolley mikejolley 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 tackling this @Aljullu !

Some feedback on how it works.

  1. The 'and' dropdown has no placeholder/default text which looks broken.
  2. Can we populate/select some default values in the editor too?
  3. The styles are off in 2019 theme, I didn't try others. But after selecting, there were weird highlights and the text wasn't visible.
  4. There are no pointer styles when selecting an item, but there are once an item is selected.

Whilst this works, the dropdown component itself feels unfinished currently.

I wonder how many people actually find dropdown useful vs the list which has limiting in place now (core doesn't limit options, but blocks limits to 10 with an expand link)... @nerrad also had feedback around single vs multiple selection, but that is something possible with list mode already.

@Aljullu Aljullu force-pushed the add/attributefilter-dropdown-and-display branch from 27eea78 to 90a1297 Compare December 4, 2019 14:09
@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 4, 2019

Thanks for the review @mikejolley! I addressed most of your feedback and answered your comments below.

  1. The 'and' dropdown has no placeholder/default text which looks broken.

Good point! I thought that was per-design, but looking at the widgets, they both have a placeholder, so I fixed it in 807f7b2.

  1. Can we populate/select some default values in the editor too?

In general, isn't it a better practice to display the block as it will be shown in the frontend? There are some cases where that's not possible (Active Filters or the Cart block, for example), but when it is possible I would prefer not to pre-fill it. I think it might be confusing for users that the select box has a value by default in the editor while it shows a placeholder in the frontend.

  1. The styles are off in 2019 theme, I didn't try others. But after selecting, there were weird highlights and the text wasn't visible.

Right, I added fixes for 2016, 2017, 2019 and 2020 in this commit: 90a1297.

  1. There are no pointer styles when selecting an item, but there are once an item is selected.

I'm not sure I understood you. I added cursor styles to list items in b31acde, but maybe you meant something else?

Whilst this works, the dropdown component itself feels unfinished currently.

What do you mean by that? Is that a design consideration or are you missing some functionality?

I wonder how many people actually find dropdown useful vs the list which has limiting in place now (core doesn't limit options, but blocks limits to 10 with an expand link)...

In a store with many terms for one attribute, having an input field where you can write the term name is probably more practical than having to search the value in a long list, no?

@Aljullu Aljullu requested a review from mikejolley December 4, 2019 14:14
@mikejolley
Copy link
Member

In general, isn't it a better practice to display the block as it will be shown in the frontend? There are some cases where that's not possible (Active Filters or the Cart block, for example), but when it is possible I would prefer not to pre-fill it. I think it might be confusing for users that the select box has a value by default in the editor while it shows a placeholder in the frontend.

Now there is a placeholder it's not as important.

I'm not sure I understood you. I added cursor styles to list items in b31acde, but maybe you meant something else?

Select boxes usually use cursor:pointer (hand) but I see now it's like a text input. Maybe it's ok :)

What do you mean by that? Is that a design consideration or are you missing some functionality?

Yes design/styling. This is what I'm seeing:

Screenshot 2019-12-04 at 15 48 41

To me it's lacking some polish, and it's not clear this is actually a dropdown just looking at it. It can be improved in follow ups, but I think it needs work before going into a stable release.

In a store with many terms for one attribute, having an input field where you can write the term name is probably more practical than having to search the value in a long list, no?

Good point, that is useful.

Changes look good 👍

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 4, 2019

@mikejolley

To me it's lacking some polish, and it's not clear this is actually a dropdown just looking at it. It can be improved in follow ups, but I think it needs work before going into a stable release.

I tried to mimic the styles from p6riRB-4CG-p2, if we want to change/improve them I think it would be better to do that in a follow-up so we don't block this PR. 🙂

Yes design/styling. This is what I'm seeing:

What theme and browser are you using? I did another round of testing with three browsers and five themes and did some more tweaking (5d6cdea) but I'm always unsure what should be left to the theme to style and what should be forced to follow our own styles.

@mikejolley
Copy link
Member

@Aljullu

What theme and browser are you using?

2019, firefox.

I'm always unsure what should be left to the theme to style and what should be forced to follow our own styles.

Hmm I think for inputs we should reset theme styles and apply as much as possible ourselves so as to match other form elements as best as we can. Like the range slider; that's not left for themes because it's an input. Themes can of course changes styles if they want to.

@Aljullu
Copy link
Contributor Author

Aljullu commented Dec 5, 2019

2019, firefox.

For me it's looking much better (it might be related to the last changes I did):

Screenshot from 2019-12-05 09-52-10

There was an issue with the label misaligned in Firefox with Twenty Twenty, I filled the issue there and hopefully it will be fixed in the next point release (there is already a patch):

https://core.trac.wordpress.org/ticket/48876

Hmm I think for inputs we should reset theme styles and apply as much as possible ourselves so as to match other form elements as best as we can. Like the range slider; that's not left for themes because it's an input. Themes can of course changes styles if they want to.

Makes sense. Currently, only the font-family and font-size are persisted in the themes I tested, everything else (colors, text-transform, underlines, font weight, margin & padding, etc.) is reset.

@mikejolley
Copy link
Member

Thanks, I think this is good to go now and anything else can be resolved with follow-ups after feedback.

Copy link
Contributor

@nerrad nerrad left a comment

Choose a reason for hiding this comment

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

lgtm too. Agreed with Mike, followups can happen as necessary post merge.

@Aljullu Aljullu merged commit 33554af into master Dec 5, 2019
@Aljullu Aljullu deleted the add/attributefilter-dropdown-and-display branch December 5, 2019 13:58
@nerrad nerrad added this to the 2.6.0 milestone Jan 27, 2020
@Aljullu Aljullu mentioned this pull request May 26, 2020
17 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

skip-changelog PRs that you don't want to appear in the changelog. type: enhancement The issue is a request for an enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Filter products by attribute - Option to show as dropdown instead of a list Multiselect checkbox/tag input component

5 participants