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

CPT: Move PostTypeListPost to standalone block directory #7195

Merged
merged 7 commits into from
Aug 1, 2016

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Aug 1, 2016

This pull request seeks to move the <PostTypeListPost> component to my-sites/post-type-list/post.jsx to blocks/post-item/index.jsx, renamed as a standalone <PostItem> component. This is part of a series of pull requests aimed at refactoring the custom pots types listing components for more generalized and customizable usage.

Testing instructions:

Verify that there are no regressions in the display and interaction of the custom post types list page post items.

/cc @mtias

Test live: https://calypso.live/?branch=move/cpt-list-post-item

@aduth aduth added [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. Custom Post Types (CPT) labels Aug 1, 2016
font-weight: 700;
white-space: nowrap;

a {
Copy link
Member

Choose a reason for hiding this comment

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

It'd be nice to have a class for this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be nice to have a class for this.

Refactored in 0483005

@mtias
Copy link
Member

mtias commented Aug 1, 2016

Looks good to me.

@mtias mtias added [Status] Ready to Merge and removed [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. labels Aug 1, 2016
@mtias
Copy link
Member

mtias commented Aug 1, 2016

@aduth can we plan on adding it to the blocks gallery in devdocs?

@aduth aduth force-pushed the move/cpt-list-post-item branch from 1b3a81c to e0d92da Compare August 1, 2016 18:31
@aduth
Copy link
Contributor Author

aduth commented Aug 1, 2016

@mtias : Pushed up a handful of new commits to document and add a DevDocs example for <PostItem />. Turned into a bit of a rabbit hole, and in the process refactored sites state and enhanced the <QuerySites /> component for requesting a single site (necessary for the edit URL in the example to correctly include the site slug). This query component and state isn't used anywhere yet, so it should be low risk.

Looping in @gwwar as the original author of this state and query component (#5066).

@aduth aduth merged commit 5fa909a into master Aug 1, 2016
@aduth aduth deleted the move/cpt-list-post-item branch August 1, 2016 18:53
}

request( props ) {
if ( ! props.siteId && ! props.requestingSites ) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to be careful about the case where we may need to wait until a siteId is available? We might accidentally trigger an all sites request if we pass through a falsy value before we pass through a siteId.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we need to be careful about the case where we may need to wait until a siteId is available? We might accidentally trigger an all sites request if we pass through a falsy value before we pass through a siteId.

Yes, but I think that should be on the developer to ensure that if they're intending to request a single site that they not render the <QuerySites /> component until the site ID is ready. That said, we could/should probably have better documentation about this behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

The sites request is heavy enough that I'd think it be worthwhile to try and avoid this case. I can see this being overlooked in a PR pretty easily.

Have we considered creating a QuerySites and QuerySite component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have we considered creating a QuerySites and QuerySite component?

I know it had come up previously in the case of single post vs. all posts for a site, and IIRC there was a desire to keep it to a single flexible component that could accommodate both cases. I see benefits to both angles. Separate components not only avoids this as a mistake, but is also a simpler implementation for the individual components. Another alternative to consider is only doing the "mass" request if explicitly passing a null parameter for siteId or a separate allSites (or similarly named) prop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some context: #2350 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't hold up the PR, but I think splitting it into two keeps it simple and makes it easier to use.

Passing an explicit null parameter works too, but we'd need to communicate the convention. Currently, selectors often return null so this would be easy to accidentally trigger.

Copy link
Member

Choose a reason for hiding this comment

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

To me it's just an attribute difference of the same query — the same way I can say "query only posts for this author" I should be able to say "query all my latest drafts". Mentally I'm querying for the same item (posts) and I don't care how our API is setup, or whether I'm hitting different endpoints. Agreed on guarding against triggering unnecessary fetches, though. Perhaps allSites is a good prop to have.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough, and if we ever end up paging the results this makes sense too. I think an extra prop works better than giving extra meaning to null. Usage then looks like:

<QuerySites allSites />
<QuerySites siteId={ siteId } />

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

Successfully merging this pull request may close these issues.

4 participants