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

Renamed & moved QueryControls from blocks/QueryPanel to components/QueryControls #5319

Merged
merged 1 commit into from
Mar 7, 2018

Conversation

jorgefilipecosta
Copy link
Member

@jorgefilipecosta jorgefilipecosta commented Feb 28, 2018

Closes #4998.

This change also exposes the component to be available for general usage, the export was missing. A dependency of applyWithAPIData was also removed from the component because the component should not be the one dealing with data requests.

This PR comes as a result of discussions that happened in #4999 (comment).

How Has This Been Tested?

Verify that QueryControls currently only used in latest posts works as expected. E.g: change the sorting, category, and number of items and verify everything works as expected.

@jorgefilipecosta jorgefilipecosta added the [Type] Enhancement A suggestion for improvement. label Feb 28, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Feb 28, 2018
} ) {
return [
( onOrderChange || onOrderByChange ) && (
( onOrderChange && onOrderByChange ) && (
<SelectControl
key="query-panel-select"
Copy link
Member

Choose a reason for hiding this comment

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

There are 3 key props that still reference panel. All of them should start now with: query-controls-*.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch keys were updated.

const termsTree = buildTermsTree( categories );
return (
<TreeSelect
{ ...{ label, noOptionLabel, onChange } }
Copy link
Member

Choose a reason for hiding this comment

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

Interesting trick :)

import TreeSelect from '../tree-select';

export default function CategorySelect( { label, noOptionLabel, categories, selectedCategory, onChange } ) {
const termsTree = buildTermsTree( categories );
Copy link
Member

Choose a reason for hiding this comment

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

Just wanted to leave a note that it is suboptimal to compute this on every prop change. Whenever selectedCategory changes this will also need to be processed. @aduth, does it make sense to use memoize here to have this logic executed only when the list of categories changes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it is a really nice suggestion maybe we can simply add memoize to buildTermsTree function.

{ ...{ order, orderBy } }
numberOfItems={ postsToShow }
categories={ get( categoriesList, 'data', {} ) }
category={ categories }
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't category be renamed to selectedCategoryId in here to reflect its further usage? Should we also rename categories to something that is closer to the aforementioned prop name?

Copy link
Member Author

Choose a reason for hiding this comment

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

The props were renamed :)

@gziolo
Copy link
Member

gziolo commented Mar 5, 2018

@jorgefilipecosta thanks for working on it. Great work so far. I had some comments regarding category vs categories props. After your refactoring, it is more prominent that there is some confusing naming. It would be nice to sort it out together with your changes. I think we also might have one place where we could add some perf improvement.
Otherwise everything looks good 👍

@gziolo gziolo added the [Feature] Extensibility The ability to extend blocks or the editing experience label Mar 5, 2018
@jorgefilipecosta jorgefilipecosta force-pushed the update/exposed-QueryControls-component branch from 2d983da to da4156a Compare March 5, 2018 21:46
…QueryControls.

This change also exposes the component to be available for general usage. A depency of applyWithAPIData was also removed from the component, because the component should not be the one dealing with data requests.
@jorgefilipecosta jorgefilipecosta force-pushed the update/exposed-QueryControls-component branch from da4156a to b446fc0 Compare March 5, 2018 21:51
{ ...{ order, orderBy } }
numberOfItems={ postsToShow }
category={ categories }
categoriesList={ get( categoriesList, 'data', {} ) }
Copy link
Member

Choose a reason for hiding this comment

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

categoriesList will never be undefined, get isn't strictly necessary.

In a perfect world we wouldn't assume the source of the value, but given the data property access, we already kinda are.

@gziolo gziolo merged commit 98ea5d2 into master Mar 7, 2018
@gziolo gziolo deleted the update/exposed-QueryControls-component branch March 7, 2018 14:25
@jorgefilipecosta
Copy link
Member Author

Thank you for landing this PR @gziolo!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants