Skip to content

Commit

Permalink
Revisions: Add supoprt for page postTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
bperson committed Jul 11, 2017
1 parent 1ecf66b commit dcd095a
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/components/data/query-post-revisions/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class QueryPostRevisions extends Component {
}

request() {
this.props.requestPostRevisions( this.props.siteId, this.props.postId );
this.props.requestPostRevisions( this.props.siteId, this.props.postId, this.props.postType );
}

render() {
Expand All @@ -36,6 +36,7 @@ class QueryPostRevisions extends Component {

QueryPostRevisions.propTypes = {
postId: PropTypes.number,
postType: PropTypes.string,
siteId: PropTypes.number,
requestPostRevisions: PropTypes.func,
};
Expand Down
10 changes: 9 additions & 1 deletion client/post-editor/editor-revisions-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import classNames from 'classnames';
import EditorRevisionsListHeader from './header';
import EditorRevisionsListItem from './item';
import QueryPostRevisions from 'components/data/query-post-revisions';
import { getEditedPostValue } from 'state/posts/selectors';
import getPostRevision from 'state/selectors/get-post-revision';
import getPostRevisions from 'state/selectors/get-post-revisions';
import { getSelectedSiteId } from 'state/ui/selectors';
Expand Down Expand Up @@ -49,7 +50,11 @@ class EditorRevisionsList extends PureComponent {
render() {
return (
<div>
<QueryPostRevisions postId={ this.props.postId } siteId={ this.props.siteId } />
<QueryPostRevisions
postId={ this.props.postId }
postType={ this.props.type }
siteId={ this.props.siteId }
/>
<EditorRevisionsListHeader
loadRevision={ this.loadRevision }
selectedRevisionId={ this.props.selectedRevisionId }
Expand Down Expand Up @@ -83,19 +88,22 @@ EditorRevisionsList.propTypes = {
selectedRevisionId: PropTypes.number,
selectRevision: PropTypes.func.isRequired,
siteId: PropTypes.number,
type: PropTypes.string,
};

export default connect(
( state, ownProps ) => {
const siteId = getSelectedSiteId( state );
const postId = getEditorPostId( state );
const type = getEditedPostValue( state, siteId, postId, 'type' );
return {
postId,
revisions: getPostRevisions( state, siteId, postId, 'display' ),
selectedRevision: getPostRevision(
state, siteId, postId, ownProps.selectedRevisionId, 'editing'
),
siteId,
type,
};
},
)( EditorRevisionsList );
7 changes: 4 additions & 3 deletions client/state/data-layer/wpcom/posts/revisions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from 'state/posts/revisions/actions';

/**
* Normalize a WP REST API Post Revisions ressource for consumption in Calypso
* Normalize a WP REST API Post Revisions resource for consumption in Calypso
*
* @param {Object} revision Raw revision from the API
* @returns {Object} the normalized revision
Expand Down Expand Up @@ -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';
dispatch( http( {
path: `/sites/${ siteId }/posts/${ postId }/revisions`,
path: `/sites/${ siteId }/${ resourceName }/${ postId }/revisions`,
method: 'GET',
query: {
apiNamespace: 'wp/v2',
Expand Down
16 changes: 16 additions & 0 deletions client/state/data-layer/wpcom/posts/revisions/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,22 @@ describe( '#fetchPostRevisions', () => {
},
}, action ) );
} );

it( 'should dispatch HTTP request to page revisions endpoint', () => {
const action = requestPostRevisions( 12345678, 10, 'page' );
const dispatch = sinon.spy();

fetchPostRevisions( { dispatch }, action );

expect( dispatch ).to.have.been.calledOnce;
expect( dispatch ).to.have.been.calledWith( http( {
method: 'GET',
path: '/sites/12345678/pages/10/revisions',
query: {
apiNamespace: 'wp/v2',
},
}, action ) );
} );
} );

describe( '#receiveSuccess', () => {
Expand Down
7 changes: 5 additions & 2 deletions client/state/posts/revisions/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import {
*
* @param {String} siteId of the revisions
* @param {String} postId of the revisions
* @param {String} [postType='post'] post type of the revisions
* @return {Object} action object
*/
export const requestPostRevisions = ( siteId, postId ) => ( {
export const requestPostRevisions = ( siteId, postId, postType = 'post' ) => ( {
type: POST_REVISIONS_REQUEST,
siteId, postId,
postId,
postType,
siteId
} );

/**
Expand Down

0 comments on commit dcd095a

Please sign in to comment.