-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4b4dbf0
CPT: Move PostTypeListPost to standalone block directory
aduth 8368280
CPT: Generate post item edit URL using post site ID
aduth 2cb8e8e
State: Implement state behaviors for requesting single site
aduth 44d23a1
Components: Support single site requests from QuerySites
aduth 78e4fad
Components: Add PostItem documentation and example
aduth e0d92da
State: Refactor sites requesting all state
aduth 0483005
Components: Apply post item link styling as separate class
aduth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Post Item | ||
========= | ||
|
||
`<PostItem />` is a connected React component for rendering a post card, including its title, metadata, thumbnail, and actions for managing that post. | ||
|
||
## Usage | ||
|
||
Render the component, passing a global ID of the post to be rendered. | ||
|
||
```jsx | ||
function MyPostList() { | ||
return <PostItem globalId="e532356fdb689509a1a5149072e8aafc" />; | ||
} | ||
``` | ||
|
||
The component does not render a [query component](https://github.com/Automattic/wp-calypso/blob/master/docs/our-approach-to-data.md#query-components), so it's assumed that the post will already have been loaded into global state prior to rendering the component. | ||
|
||
## Props | ||
|
||
### `globalId` | ||
|
||
<table> | ||
<tr><th>Type</th><td>Number</td></tr> | ||
<tr><th>Required</th><td>Yes</td></tr> | ||
</table> | ||
|
||
The global ID of the post to be displayed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React from 'react'; | ||
import { connect } from 'react-redux'; | ||
import { get } from 'lodash'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import QueryPosts from 'components/data/query-posts'; | ||
import QuerySites from 'components/data/query-sites'; | ||
import PostItem from '../'; | ||
import { getCurrentUser } from 'state/current-user/selectors'; | ||
import { getSitePosts } from 'state/posts/selectors'; | ||
|
||
function PostItemExample( { primarySiteId, globalId } ) { | ||
return ( | ||
<div className="docs__design-assets-group"> | ||
<h2> | ||
<a href="/devdocs/blocks/post-item">Post Item</a> | ||
</h2> | ||
{ primarySiteId && <QuerySites siteId={ primarySiteId } /> } | ||
{ primarySiteId && ( | ||
<QueryPosts | ||
siteId={ primarySiteId } | ||
query={ { number: 1, type: 'any' } } /> | ||
) } | ||
{ ! globalId && <em>No posts found</em> } | ||
{ globalId && <PostItem globalId={ globalId } /> } | ||
</div> | ||
); | ||
} | ||
|
||
const ConnectedPostItemExample = connect( ( state ) => { | ||
const primarySiteId = get( getCurrentUser( state ), 'primary_blog' ); | ||
|
||
return { | ||
primarySiteId, | ||
globalId: get( getSitePosts( state, primarySiteId ), [ 0, 'global_ID' ] ) | ||
}; | ||
} )( PostItemExample ); | ||
|
||
ConnectedPostItemExample.displayName = 'PostItem'; | ||
|
||
export default ConnectedPostItemExample; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
.card.post-item { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
} | ||
|
||
.post-item__detail { | ||
position: relative; | ||
display: flex; | ||
width: 100%; | ||
overflow: hidden; | ||
margin-right: auto; | ||
|
||
&::after { | ||
@include long-content-fade( $size: 40px ); | ||
right: 0; | ||
} | ||
} | ||
|
||
.post-item__title-meta { | ||
padding: 6px 0; | ||
} | ||
|
||
.post-item__title { | ||
@extend %content-font; | ||
margin-bottom: 2px; | ||
font-weight: 700; | ||
white-space: nowrap; | ||
} | ||
|
||
a.post-item__title-link { | ||
color: $gray-dark; | ||
|
||
&:hover { | ||
color: darken( $gray, 20% ); | ||
} | ||
|
||
.post-item.is-untitled & { | ||
color: $gray; | ||
font-style: italic; | ||
} | ||
} | ||
|
||
.post-item__meta { | ||
font-size: 12px; | ||
color: lighten( $gray, 10% ); | ||
} | ||
|
||
.post-item__meta .post-relative-time-status, | ||
.post-item__meta .post-type-post-author { | ||
float: left; | ||
} | ||
|
||
.post-item__meta .post-relative-time-status { | ||
margin-bottom: 0; | ||
} | ||
|
||
.post-item__meta .post-relative-time-status .gridicon { | ||
width: 14px; | ||
height: 14px; | ||
margin-top: -3px; | ||
margin-right: 6px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,29 @@ | ||
Query Sites | ||
=========================== | ||
|
||
`<QuerySites />` is a React component used in managing network requests for sites. When placed on the page | ||
it requests all visible sites of the logged in user. | ||
`<QuerySites />` is a React component used in managing network requests for sites. If passed a site ID, it will request the site when the component is mounted. If no site ID is passed, it will request all sites for the current user. | ||
|
||
## Usage | ||
|
||
Render the component. Any props passed to the component will be ignored. It does not accept any children, | ||
nor does it render any elements to the page. | ||
Render the component, optionally passing a site ID. The component does not accept any children, nor does it render any of its own. | ||
|
||
```jsx | ||
function AllSites() { | ||
return <QuerySites />; | ||
} | ||
|
||
function SingleSite() { | ||
return <QuerySites siteId={ 2916284 } /> | ||
} | ||
``` | ||
|
||
## Props | ||
|
||
### `siteId` | ||
|
||
<table> | ||
<tr><th>Type</th><td>Number</td></tr> | ||
<tr><th>Required</th><td>No</td></tr> | ||
</table> | ||
|
||
An optional prop specifying a single site to be requested. If omitted, all sites for the current user will be requested. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 forsiteId
or a separateallSites
(or similarly named) prop.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some context: #2350 (comment)
There was a problem hiding this comment.
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 returnnull
so this would be easy to accidentally trigger.There was a problem hiding this comment.
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.There was a problem hiding this comment.
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: