Skip to content

Commit

Permalink
Require dependency publishing to publish unpublished entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Benaiah committed Mar 6, 2017
1 parent 12f37e2 commit eca9c97
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
18 changes: 18 additions & 0 deletions src/actions/editorialWorkflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,3 +474,21 @@ export function getUnpublishedEntryDependencies(collection, slug) {
.catch(err => dispatch(unpublishedEntryDependenciesError(collection, slug, err)));
};
}

export function publishUnpublishedEntryAndDependencies(collection, slug) {
return (dispatch, getState) => dispatch(getUnpublishedEntryDependencies(collection, slug))
.then(({ payload }) => {
if (payload.dependencies.size === 1) {
return dispatch(publishUnpublishedEntry(collection, slug));
}

const confirmationMessage = `\
Thisntry has dependencies, and cannot be published on its own. Publish all the following posts?
${ payload.dependencies.join("\n") }`;

if (window.confirm(confirmationMessage)) {
return dispatch(publishUnpublishedEntries(payload.dependencies.map(
dep => dep.split("."))));
}
});
}
5 changes: 3 additions & 2 deletions src/containers/editorialWorkflow/UnpublishedEntriesPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import React, { Component, PropTypes } from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { OrderedMap } from 'immutable';
import { connect } from 'react-redux';
import { loadUnpublishedEntries, updateUnpublishedEntryStatus, publishUnpublishedEntry } from '../../actions/editorialWorkflow';
import { loadUnpublishedEntries, updateUnpublishedEntryStatus,
publishUnpublishedEntryAndDependencies } from '../../actions/editorialWorkflow';
import { selectUnpublishedEntriesByStatus } from '../../reducers';
import { EDITORIAL_WORKFLOW, status } from '../../constants/publishModes';
import UnpublishedListing from '../../components/UnpublishedListing/UnpublishedListing';
Expand Down Expand Up @@ -61,5 +62,5 @@ function mapStateToProps(state) {
export default connect(mapStateToProps, {
loadUnpublishedEntries,
updateUnpublishedEntryStatus,
publishUnpublishedEntry,
publishUnpublishedEntry: publishUnpublishedEntryAndDependencies,
})(unpublishedEntriesPanel);

0 comments on commit eca9c97

Please sign in to comment.