-
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
Revisions #5: Add support for page
postTypes
#14928
Conversation
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.
Does the revisions endpoint not support custom post types? Ideally we'd not be tied to posts and pages only. These are mistakes we'd made early in both the REST API and Calypso that would be good to avoid moving forward. Would GET /sites/%s/posts/%d/revisions
return anything if the ID passed was one for a custom post type?
dispatch( http( { | ||
path: `/sites/${ siteId }/posts/${ postId }/revisions`, | ||
path: `/sites/${ siteId }/${ ressourceName }/${ postId }/revisions`, |
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.
Typo: ressourceName
-> resourceName
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.
french sneaking in, it should be fixed ;)
it looks like there is support for some post types.
Nope, but it does work (for some post types) if you use the normalised post type resource name [0]: [0] I can't find logic in calypso that would do what's done in the REST API to compute the resource name though:
The issue comes from the fact we populate I ideally would like to not upgrade the code fetching post types to v2, as it sounds like a deep rabbit hole, so there are 2 options I think: |
Interesting observations. I wonder how common it is to rename
Porting post types to Enabling the UI only for posts and pages is an option, though not ideal per my previous comment. |
Right now, with #14927, we fetch the revisions when the UI gets rendered which makes it impossible to disable the revision UI as a result of a 404, at best, we can display a button redirecting to That said, I think it's safer for now to only enable it for posts/pages, leave a NOTE/TODO comment (or a GH issue?) to revisit it with a bit more mileage on the revisions UI. It makes the UX consistent for all custom types, without having to explain in an error message why some are failing and redirecting the user to wp-admin due to an hidden parameter. |
@@ -87,9 +87,10 @@ export const receiveSuccess = ( { dispatch }, { siteId, postId }, next, revision | |||
* @param {Object} action Redux action | |||
*/ | |||
export const fetchPostRevisions = ( { dispatch }, action ) => { | |||
const { siteId, postId } = action; | |||
const { siteId, postId, postType } = action; | |||
const resourceName = postType === 'page' ? 'pages' : 'posts'; |
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.
Even if we don't support custom post types quite yet, is there a way we could express this to be less tied to posts and pages? If we hypothetically had access to rest_base
, how would we want this data handler and the associated action creator to be written?
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.
-
associated action creator: nothing?
postType
is the most suited parameter to transmit that data in the action imho: using therest_base
in the action would leak a "data-layer" concept +postType
is widely used in the codebase. -
data handler:
export const fetchPostRevisions = ( { dispatch, getState }, action ) => {
const { siteId, postId } = action;
const { siteId, postId, postType } = action;
const resourceName = getPostType( getState(), siteId, postType ).rest_base
(...)
} );
27b769d
to
4ca1184
Compare
ad22062
to
6cf088b
Compare
Now that #14943 is merged, CircleCI is green, it's also rebased on the latest master |
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.
Minor note, but this is looking good.
@@ -77,6 +77,7 @@ const EditorSidebar = ( { | |||
selectedRevisionId={ selectedRevisionId } | |||
selectRevision={ selectRevision } | |||
siteId={ site.ID } | |||
type={ type } |
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.
Passing this as a prop is arguably a bit redundant, because siteId
and postId
props should be sufficient for the component to be able to look up this information from state on its own via connect
. EditorDocumentHead is similar here (though more extreme in that it doesn't accept any props) where it determines the type
using the getEditedPostValue
selector.
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.
interesting, it's updated (I also updated #14927 to load siteId
and postId
from state).
6cf088b
to
e54feed
Compare
b40d9df
to
5122f83
Compare
@bperson This PR needs a rebase |
5122f83
to
0d1618b
Compare
e54feed
to
dcd095a
Compare
1ecf66b
to
d532714
Compare
dcd095a
to
ff6fdae
Compare
6de7aa2
to
ad4121b
Compare
@bperson This PR needs a rebase |
ff6fdae
to
327585d
Compare
Note: This builds on top of #14927, so it's not merge-able yet5th chunk coming from my WIP PR to introduce post revisions in calypso: #13367. This simply adds support for pages. It's mostly code to hit a different endpoint based on the
postType
.testing