From b6874152d92a8b4b6865076acd3d2fa78efd9050 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A1ssio=20Zen?= Date: Thu, 8 Sep 2016 19:04:54 -0300 Subject: [PATCH] unpublished items dashboard --- src/components/UnpublishedListing.js | 45 ++++++++++++++++++++++++++ src/containers/EditorialWorkflowHoC.js | 15 ++++++--- src/reducers/editorialWorkflow.js | 13 ++++++-- 3 files changed, 66 insertions(+), 7 deletions(-) create mode 100644 src/components/UnpublishedListing.js diff --git a/src/components/UnpublishedListing.js b/src/components/UnpublishedListing.js new file mode 100644 index 00000000..0ef0cdfa --- /dev/null +++ b/src/components/UnpublishedListing.js @@ -0,0 +1,45 @@ +import React from 'react'; +import ImmutablePropTypes from 'react-immutable-proptypes'; +import { Card } from './UI'; +import { statusDescriptions } from '../constants/publishModes'; + +export default class UnpublishedListing extends React.Component { + renderColumn(entries) { + if (!entries) return; + return ( +
+ {entries.map(entry => { + return

{entry.getIn(['data', 'title'])}

; + } + )} +
+ ); + } + + render() { + const { entries } = this.props; + const columns = entries.entrySeq().map(([key, currEntries]) => ( +
+

{statusDescriptions.get(key)}

+ {this.renderColumn(currEntries)} +
+ )); + + return ( +
+ {columns} +
+ ); + } +} + +UnpublishedListing.propTypes = { + entries: ImmutablePropTypes.map, +}; + + + +
+

Drafts

+ Cool Recipe +
diff --git a/src/containers/EditorialWorkflowHoC.js b/src/containers/EditorialWorkflowHoC.js index 3c626d85..a7ffcc74 100644 --- a/src/containers/EditorialWorkflowHoC.js +++ b/src/containers/EditorialWorkflowHoC.js @@ -1,9 +1,12 @@ import React, { PropTypes } from 'react'; import ImmutablePropTypes from 'react-immutable-proptypes'; +import { Map } from 'immutable'; import { init, loadUnpublishedEntries } from '../actions/editorialWorkflow'; import { selectUnpublishedEntries } from '../reducers'; -import { EDITORIAL_WORKFLOW } from '../constants/publishModes'; +import { EDITORIAL_WORKFLOW, status } from '../constants/publishModes'; +import UnpublishedListing from '../components/UnpublishedListing'; import { connect } from 'react-redux'; +import _ from 'lodash'; export default function EditorialWorkflow(WrappedComponent) { class EditorialWorkflow extends WrappedComponent { @@ -18,12 +21,12 @@ export default function EditorialWorkflow(WrappedComponent) { } render() { - const { isEditorialWorkflow } = this.props; + const { isEditorialWorkflow, unpublishedEntries } = this.props; if (!isEditorialWorkflow) return super.render(); return (
-

HOC

+ {super.render()}
); @@ -33,7 +36,7 @@ export default function EditorialWorkflow(WrappedComponent) { EditorialWorkflow.propTypes = { dispatch: PropTypes.func.isRequired, isEditorialWorkflow: PropTypes.bool.isRequired, - unpublishedEntries: ImmutablePropTypes.list, + unpublishedEntries: ImmutablePropTypes.map, }; function mapStateToProps(state) { @@ -42,7 +45,9 @@ export default function EditorialWorkflow(WrappedComponent) { const returnObj = { isEditorialWorkflow }; if (isEditorialWorkflow) { - returnObj.unpublishedEntries = selectUnpublishedEntries(state, 'draft'); + returnObj.unpublishedEntries = _.reduce(status, (acc, currStatus) => { + return acc.set(currStatus, selectUnpublishedEntries(state, currStatus)); + }, Map()); } return returnObj; diff --git a/src/reducers/editorialWorkflow.js b/src/reducers/editorialWorkflow.js index 10307bfd..95cf9e28 100644 --- a/src/reducers/editorialWorkflow.js +++ b/src/reducers/editorialWorkflow.js @@ -28,13 +28,22 @@ const unpublishedEntries = (state = null, action) => { }; export const selectUnpublishedEntry = (state, status, slug) => ( - state.getIn(['entities', `${status}.${slug}`], null) + state.getIn(['entities', `${status}.${slug}`]) ); export const selectUnpublishedEntries = (state, status) => { if (!state) return; const slugs = state.getIn(['pages', 'ids']); - return slugs && slugs.map((slug) => selectUnpublishedEntry(state, status, slug)); + + return slugs && slugs.reduce((acc, slug) => { + const entry = selectUnpublishedEntry(state, status, slug); + if (entry) { + return acc.push(entry); + } else { + return acc; + } + }, List()); }; + export default unpublishedEntries;