Merge remote-tracking branch 'origin/react-pr' into react-ui-updates
Replaced dateFormat with moment Conflicts: package.json src/backends/netlify-git/API.js src/containers/CollectionPage.js src/formats/formats.js
This commit is contained in:
@ -3,13 +3,14 @@ import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { connect } from 'react-redux';
|
||||
import { loadEntries } from '../actions/entries';
|
||||
import { selectEntries } from '../reducers';
|
||||
import { Loader } from '../components/UI';
|
||||
import EntryListing from '../components/EntryListing';
|
||||
import styles from './CollectionPage.css';
|
||||
import EditorialWorkflow from './EditorialWorkflowHoC';
|
||||
|
||||
class DashboardPage extends React.Component {
|
||||
componentDidMount() {
|
||||
const { collection, dispatch } = this.props;
|
||||
|
||||
if (collection) {
|
||||
dispatch(loadEntries(collection));
|
||||
}
|
||||
@ -28,12 +29,16 @@ class DashboardPage extends React.Component {
|
||||
return <h1>No collections defined in your config.yml</h1>;
|
||||
}
|
||||
|
||||
|
||||
return <div className={styles.alignable}>
|
||||
{entries ? <EntryListing collection={collection} entries={entries}/> : 'Loading entries...'}
|
||||
{entries ?
|
||||
<EntryListing collection={collection} entries={entries}/>
|
||||
:
|
||||
<Loader active>{['Loading Entries', 'Caching Entries', 'This might take several minutes']}</Loader>
|
||||
}
|
||||
</div>;
|
||||
}
|
||||
}
|
||||
|
||||
DashboardPage.propTypes = {
|
||||
collection: ImmutablePropTypes.map.isRequired,
|
||||
collections: ImmutablePropTypes.orderedMap.isRequired,
|
||||
@ -41,6 +46,13 @@ DashboardPage.propTypes = {
|
||||
entries: ImmutablePropTypes.list,
|
||||
};
|
||||
|
||||
/*
|
||||
* Instead of checking the publish mode everywhere to dispatch & render the additional editorial workflow stuff,
|
||||
* We delegate it to a Higher Order Component
|
||||
*/
|
||||
DashboardPage = EditorialWorkflow(DashboardPage);
|
||||
|
||||
|
||||
function mapStateToProps(state, ownProps) {
|
||||
const { collections } = state;
|
||||
const { name, slug } = ownProps.params;
|
||||
|
60
src/containers/EditorialWorkflowHoC.js
Normal file
60
src/containers/EditorialWorkflowHoC.js
Normal file
@ -0,0 +1,60 @@
|
||||
import React, { PropTypes } from 'react';
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes';
|
||||
import { OrderedMap } from 'immutable';
|
||||
import { init, loadUnpublishedEntries } from '../actions/editorialWorkflow';
|
||||
import { selectUnpublishedEntries } from '../reducers';
|
||||
import { EDITORIAL_WORKFLOW, status } from '../constants/publishModes';
|
||||
import UnpublishedListing from '../components/UnpublishedListing';
|
||||
import { connect } from 'react-redux';
|
||||
|
||||
export default function EditorialWorkflow(WrappedComponent) {
|
||||
class EditorialWorkflow extends WrappedComponent {
|
||||
|
||||
componentDidMount() {
|
||||
const { dispatch, isEditorialWorkflow } = this.props;
|
||||
if (isEditorialWorkflow) {
|
||||
dispatch(init());
|
||||
dispatch(loadUnpublishedEntries());
|
||||
}
|
||||
super.componentDidMount();
|
||||
}
|
||||
|
||||
render() {
|
||||
const { isEditorialWorkflow, unpublishedEntries } = this.props;
|
||||
if (!isEditorialWorkflow) return super.render();
|
||||
|
||||
return (
|
||||
<div>
|
||||
<UnpublishedListing entries={unpublishedEntries}/>
|
||||
{super.render()}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
EditorialWorkflow.propTypes = {
|
||||
dispatch: PropTypes.func.isRequired,
|
||||
isEditorialWorkflow: PropTypes.bool.isRequired,
|
||||
unpublishedEntries: ImmutablePropTypes.map,
|
||||
};
|
||||
|
||||
function mapStateToProps(state) {
|
||||
const publish_mode = state.config.get('publish_mode');
|
||||
const isEditorialWorkflow = (publish_mode === EDITORIAL_WORKFLOW);
|
||||
const returnObj = { isEditorialWorkflow };
|
||||
|
||||
if (isEditorialWorkflow) {
|
||||
/*
|
||||
* 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()}
|
||||
*/
|
||||
returnObj.unpublishedEntries = status.reduce((acc, currStatus) => {
|
||||
return acc.set(currStatus, selectUnpublishedEntries(state, currStatus));
|
||||
}, OrderedMap());
|
||||
}
|
||||
return returnObj;
|
||||
}
|
||||
|
||||
return connect(mapStateToProps)(EditorialWorkflow);
|
||||
}
|
Reference in New Issue
Block a user