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

Framework: Refactor PostTaxonomies to use `withApiData` HoC #2537

Merged
merged 3 commits into from Sep 6, 2017

Conversation

Projects
None yet
2 participants
@youknowriad
Contributor

youknowriad commented Aug 25, 2017

Just some more consistency in fetching API DATA

@youknowriad youknowriad self-assigned this Aug 25, 2017

@youknowriad youknowriad requested a review from aduth Aug 25, 2017

@youknowriad

This comment has been minimized.

Show comment
Hide comment
@youknowriad

youknowriad Aug 25, 2017

Contributor

@aduth Do you have any idea how to use withAPIData when they depend on a local state value? (Thinking about the TermSelectors)? I guess one option would be to store this state value in Redux, but seems weird to do so just for this?

Contributor

youknowriad commented Aug 25, 2017

@aduth Do you have any idea how to use withAPIData when they depend on a local state value? (Thinking about the TermSelectors)? I guess one option would be to store this state value in Redux, but seems weird to do so just for this?

@aduth

This comment has been minimized.

Show comment
Hide comment
@aduth

aduth Aug 25, 2017

Member

Do you have any idea how to use withAPIData when they depend on a local state value?

You could have a parent component which manages the state, then passes the state as a prop to a child component, then available to withAPIData.

This is precisely how search is implemented in Calypso's TermTreeSelector component.

Member

aduth commented Aug 25, 2017

Do you have any idea how to use withAPIData when they depend on a local state value?

You could have a parent component which manages the state, then passes the state as a prop to a child component, then available to withAPIData.

This is precisely how search is implemented in Calypso's TermTreeSelector component.

@youknowriad

This comment has been minimized.

Show comment
Hide comment
@youknowriad

youknowriad Aug 31, 2017

Contributor

Can I get a 👍 or 👎?

Contributor

youknowriad commented Aug 31, 2017

Can I get a 👍 or 👎?

@codecov

This comment has been minimized.

Show comment
Hide comment
@codecov

codecov bot Aug 31, 2017

Codecov Report

Merging #2537 into master will increase coverage by 0.53%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2537      +/-   ##
==========================================
+ Coverage   31.42%   31.95%   +0.53%     
==========================================
  Files         177      177              
  Lines        5407     5576     +169     
  Branches      946      981      +35     
==========================================
+ Hits         1699     1782      +83     
- Misses       3135     3197      +62     
- Partials      573      597      +24
Impacted Files Coverage Δ
editor/sidebar/post-taxonomies/index.js 0% <0%> (ø) ⬆️
blocks/library/latest-posts/index.js 7.4% <0%> (-2.6%) ⬇️
...ebar/post-taxonomies/hierarchical-term-selector.js 0% <0%> (ø) ⬆️
blocks/api/registration.js 100% <0%> (ø) ⬆️
editor/inserter/menu.js 48.46% <0%> (+0.05%) ⬆️
blocks/library/embed/index.js 60.31% <0%> (+14.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5885233...f129648. Read the comment docs.

codecov bot commented Aug 31, 2017

Codecov Report

Merging #2537 into master will increase coverage by 0.53%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2537      +/-   ##
==========================================
+ Coverage   31.42%   31.95%   +0.53%     
==========================================
  Files         177      177              
  Lines        5407     5576     +169     
  Branches      946      981      +35     
==========================================
+ Hits         1699     1782      +83     
- Misses       3135     3197      +62     
- Partials      573      597      +24
Impacted Files Coverage Δ
editor/sidebar/post-taxonomies/index.js 0% <0%> (ø) ⬆️
blocks/library/latest-posts/index.js 7.4% <0%> (-2.6%) ⬇️
...ebar/post-taxonomies/hierarchical-term-selector.js 0% <0%> (ø) ⬆️
blocks/api/registration.js 100% <0%> (ø) ⬆️
editor/inserter/menu.js 48.46% <0%> (+0.05%) ⬆️
blocks/library/embed/index.js 60.31% <0%> (+14.86%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5885233...f129648. Read the comment docs.

Show outdated Hide outdated editor/sidebar/post-taxonomies/index.js Outdated
Show outdated Hide outdated editor/sidebar/post-taxonomies/index.js Outdated
opened={ isOpened }
onToggle={ onTogglePanel }
>
{ availableTaxonomies.map( ( taxonomy ) => {

This comment has been minimized.

@aduth

aduth Aug 31, 2017

Member

To the above point, Lodash's reduce similarly handles undefined and object types, so this could even manage the filtering and mapping in one, ensuring the panel heading is always shown.

<PanelBody
	title={ __( 'Categories & Tags' ) }
	opened={ isOpened }
	onToggle={ onTogglePanel }
>
	{ reduce( taxonomies.data, ( result, taxonomy ) => {
		if ( includes( taxonomy.types, postType ) ) {
			const TaxonomyComponent = taxonomy.hierarchical 
				? HierarchicalTermSelector 
				: FlatTermSelector;

			result.push(
				<TaxonomyComponent
					key={ taxonomy.slug }
					label={ taxonomy.name }
					restBase={ taxonomy.rest_base }
					slug={ taxonomy.slug }
				/>
			);
		}

		return result;
	}, [] ) }
</PanelBody>
@aduth

aduth Aug 31, 2017

Member

To the above point, Lodash's reduce similarly handles undefined and object types, so this could even manage the filtering and mapping in one, ensuring the panel heading is always shown.

<PanelBody
	title={ __( 'Categories & Tags' ) }
	opened={ isOpened }
	onToggle={ onTogglePanel }
>
	{ reduce( taxonomies.data, ( result, taxonomy ) => {
		if ( includes( taxonomy.types, postType ) ) {
			const TaxonomyComponent = taxonomy.hierarchical 
				? HierarchicalTermSelector 
				: FlatTermSelector;

			result.push(
				<TaxonomyComponent
					key={ taxonomy.slug }
					label={ taxonomy.name }
					restBase={ taxonomy.rest_base }
					slug={ taxonomy.slug }
				/>
			);
		}

		return result;
	}, [] ) }
</PanelBody>

This comment has been minimized.

@youknowriad

youknowriad Sep 4, 2017

Contributor

you know I prefer filter + map over reduce on small loops. I do understand the performance reasons for long loops.

@youknowriad

youknowriad Sep 4, 2017

Contributor

you know I prefer filter + map over reduce on small loops. I do understand the performance reasons for long loops.

This comment has been minimized.

@aduth

aduth Sep 6, 2017

Member

I meant nothing of performance by my comment, filter / map or whatever is fine, just that we can skip the early return and account for undefined type with Lodash methods.

@aduth

aduth Sep 6, 2017

Member

I meant nothing of performance by my comment, filter / map or whatever is fine, just that we can skip the early return and account for undefined type with Lodash methods.

@aduth

aduth approved these changes Sep 6, 2017

@youknowriad youknowriad merged commit 81f50ea into master Sep 6, 2017

3 checks passed

codecov/project 31.95% (+0.53%) compared to 5885233
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
continuous-integration/travis-ci/push The Travis CI build passed
Details

@youknowriad youknowriad deleted the update/post-taxonomies-with-api-data branch Sep 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment