unpublished items dashboard

This commit is contained in:
Cássio Zen 2016-09-08 19:04:54 -03:00
parent 04c50d8def
commit b6874152d9
3 changed files with 66 additions and 7 deletions

View File

@ -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 (
<div>
{entries.map(entry => {
return <Card key={entry.get('slug')}><h4>{entry.getIn(['data', 'title'])}</h4></Card>;
}
)}
</div>
);
}
render() {
const { entries } = this.props;
const columns = entries.entrySeq().map(([key, currEntries]) => (
<div key={key}>
<h3>{statusDescriptions.get(key)}</h3>
{this.renderColumn(currEntries)}
</div>
));
return (
<div>
{columns}
</div>
);
}
}
UnpublishedListing.propTypes = {
entries: ImmutablePropTypes.map,
};
<div>
<h3>Drafts</h3>
<card>Cool Recipe</card>
</div>

View File

@ -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 (
<div>
<h2>HOC</h2>
<UnpublishedListing entries={unpublishedEntries}/>
{super.render()}
</div>
);
@ -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;

View File

@ -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;