Editorial workflow Improvements (#212)

* Merge conflicts automatically. Closes #208
* removed unpublished entry route
All entries (either under editorial workflow or not) go through the same edit route.
This commit is contained in:
Cássio Souza
2017-01-11 20:58:15 -02:00
committed by GitHub
parent c40171820f
commit 48d8077ff0
19 changed files with 279 additions and 155 deletions

View File

@ -9,7 +9,7 @@ import {
changeDraftField,
persistEntry,
} from '../actions/entries';
import { cancelEdit } from '../actions/editor';
import { closeEntry } from '../actions/editor';
import { addAsset, removeAsset } from '../actions/media';
import { openSidebar } from '../actions/globalUI';
import { selectEntry, getAsset } from '../reducers';
@ -32,7 +32,7 @@ class EntryPage extends React.Component {
loadEntry: PropTypes.func.isRequired,
persistEntry: PropTypes.func.isRequired,
removeAsset: PropTypes.func.isRequired,
cancelEdit: PropTypes.func.isRequired,
closeEntry: PropTypes.func.isRequired,
openSidebar: PropTypes.func.isRequired,
fields: ImmutablePropTypes.list.isRequired,
slug: PropTypes.string,
@ -45,7 +45,7 @@ class EntryPage extends React.Component {
if (newEntry) {
createEmptyDraft(collection);
} else {
loadEntry(entry, collection, slug);
loadEntry(collection, slug);
}
}
@ -67,6 +67,10 @@ class EntryPage extends React.Component {
if (entry) this.props.createDraftFromEntry(entry);
};
handleCloseEntry = () => {
this.props.closeEntry();
};
handlePersistEntry = () => {
const { persistEntry, collection, entryDraft } = this.props;
persistEntry(collection, entryDraft);
@ -82,7 +86,7 @@ class EntryPage extends React.Component {
changeDraftField,
addAsset,
removeAsset,
cancelEdit,
closeEntry,
} = this.props;
if (entry && entry.get('error')) {
@ -104,7 +108,7 @@ class EntryPage extends React.Component {
onAddAsset={addAsset}
onRemoveAsset={removeAsset}
onPersist={this.handlePersistEntry}
onCancelEdit={cancelEdit}
onCancelEdit={this.handleCloseEntry}
/>
);
}
@ -141,7 +145,7 @@ export default connect(
createEmptyDraft,
discardDraft,
persistEntry,
cancelEdit,
closeEntry,
openSidebar,
}
)(entryPageHOC(EntryPage));

View File

@ -1,7 +1,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { EDITORIAL_WORKFLOW } from '../../constants/publishModes';
import { selectUnpublishedEntry } from '../../reducers';
import { selectUnpublishedEntry, selectEntry } from '../../reducers';
import { loadUnpublishedEntry, persistUnpublishedEntry } from '../../actions/editorialWorkflow';
@ -13,36 +13,32 @@ export default function EntryPageHOC(EntryPage) {
}
function mapStateToProps(state, ownProps) {
const { collections } = state;
const isEditorialWorkflow = (state.config.get('publish_mode') === EDITORIAL_WORKFLOW);
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
const returnObj = { isEditorialWorkflow };
if (isEditorialWorkflow && unpublishedEntry) {
const status = ownProps.params.status;
if (isEditorialWorkflow) {
const slug = ownProps.params.slug;
const entry = selectUnpublishedEntry(state, status, slug);
returnObj.entry = entry;
const collection = collections.get(ownProps.params.name);
const unpublishedEntry = selectUnpublishedEntry(state, collection.get('name'), slug);
if (unpublishedEntry) {
returnObj.unpublishedEntry = true;
returnObj.entry = unpublishedEntry;
}
}
return returnObj;
}
function mergeProps(stateProps, dispatchProps, ownProps) {
const { isEditorialWorkflow } = stateProps;
const { isEditorialWorkflow, unpublishedEntry } = stateProps;
const { dispatch } = dispatchProps;
const unpublishedEntry = ownProps.route && ownProps.route.unpublishedEntry === true;
const status = ownProps.params.status;
const returnObj = {};
if (unpublishedEntry) {
// Overwrite loadEntry to loadUnpublishedEntry
returnObj.loadEntry = (entry, collection, slug) => {
dispatch(loadUnpublishedEntry(collection, status, slug));
};
}
if (isEditorialWorkflow) {
// Overwrite loadEntry to loadUnpublishedEntry
returnObj.loadEntry = (collection, slug) => {
dispatch(loadUnpublishedEntry(collection, slug));
};
// Overwrite persistEntry to persistUnpublishedEntry
returnObj.persistEntry = (collection, entryDraft) => {
dispatch(persistUnpublishedEntry(collection, entryDraft, unpublishedEntry));

View File

@ -3,7 +3,7 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
import { OrderedMap } from 'immutable';
import { connect } from 'react-redux';
import { loadUnpublishedEntries, updateUnpublishedEntryStatus, publishUnpublishedEntry } from '../../actions/editorialWorkflow';
import { selectUnpublishedEntries } from '../../reducers';
import { selectUnpublishedEntriesByStatus } from '../../reducers';
import { EDITORIAL_WORKFLOW, status } from '../../constants/publishModes';
import UnpublishedListing from '../../components/UnpublishedListing/UnpublishedListing';
import { Loader } from '../../components/UI';
@ -48,11 +48,11 @@ function mapStateToProps(state) {
/*
* Generates an ordered Map of the available status as keys.
* Each key containing a List of available unpubhlished entries
* Eg.: OrderedMap{'draft':List(), 'pending_review':List(), 'pending_publish':List()}
* Each key containing a Sequence of available unpubhlished entries
* Eg.: OrderedMap{'draft':Seq(), 'pending_review':Seq(), 'pending_publish':Seq()}
*/
returnObj.unpublishedEntries = status.reduce((acc, currStatus) => (
acc.set(currStatus, selectUnpublishedEntries(state, currStatus))
acc.set(currStatus, selectUnpublishedEntriesByStatus(state, currStatus))
), OrderedMap());
}
return returnObj;