static-cms/src/components/UnpublishedListing.js

92 lines
3.4 KiB
JavaScript
Raw Normal View History

2016-09-13 16:00:24 -03:00
import React, { PropTypes } from 'react';
2016-09-15 15:50:33 -03:00
import { DragSource, DropTarget, HTML5DragDrop } from 'react-simple-dnd';
2016-09-08 19:04:54 -03:00
import ImmutablePropTypes from 'react-immutable-proptypes';
import moment from 'moment';
2016-09-08 19:04:54 -03:00
import { Card } from './UI';
2016-09-13 11:27:06 -03:00
import { Link } from 'react-router';
2016-09-14 18:25:45 -03:00
import { status, statusDescriptions } from '../constants/publishModes';
2016-09-09 17:15:58 -03:00
import styles from './UnpublishedListing.css';
2016-09-08 19:04:54 -03:00
2016-09-13 16:00:24 -03:00
class UnpublishedListing extends React.Component {
2016-10-03 14:25:27 +02:00
handleChangeStatus = (newStatus, dragProps) => {
2016-09-15 15:50:33 -03:00
const slug = dragProps.slug;
const collection = dragProps.collection;
const oldStatus = dragProps.ownStatus;
this.props.handleChangeStatus(collection, slug, oldStatus, newStatus);
2016-10-03 14:25:27 +02:00
};
2016-09-15 15:50:33 -03:00
2016-10-03 14:25:27 +02:00
requestPublish = (collection, slug, ownStatus) => {
2016-09-14 18:25:45 -03:00
if (ownStatus !== status.last()) return;
if (window.confirm('Are you sure you want to publish this entry?')) {
this.props.handlePublish(collection, slug, ownStatus);
}
2016-10-03 14:25:27 +02:00
};
2016-09-13 16:00:24 -03:00
2016-10-03 14:25:27 +02:00
renderColumns = (entries, column) => {
2016-09-08 19:04:54 -03:00
if (!entries) return;
2016-09-09 17:15:58 -03:00
if (!column) {
2016-09-15 15:50:33 -03:00
/* eslint-disable */
2016-09-09 17:15:58 -03:00
return entries.entrySeq().map(([currColumn, currEntries]) => (
2016-09-15 15:50:33 -03:00
<DropTarget key={currColumn} onDrop={this.handleChangeStatus.bind(this, currColumn)}>
{(isOver) => (
<div className={isOver ? `${styles.column} ${styles.highlighted}` : styles.column}>
<h2>{statusDescriptions.get(currColumn)}</h2>
{this.renderColumns(currEntries, currColumn)}
</div>
)}
</DropTarget>
/* eslint-enable */
2016-09-09 17:15:58 -03:00
));
} else {
return <div>
2016-09-08 19:04:54 -03:00
{entries.map(entry => {
2016-09-09 17:15:58 -03:00
// Look for an "author" field. Fallback to username on backend implementation;
const author = entry.getIn(['data', 'author'], entry.getIn(['metaData', 'user']));
2016-09-13 11:27:06 -03:00
const timeStamp = moment(entry.getIn(['metaData', 'timeStamp'])).format('llll');
const link = `/editorialworkflow/${entry.getIn(['metaData', 'collection'])}/${entry.getIn(['metaData', 'status'])}/${entry.get('slug')}`;
2016-09-14 18:25:45 -03:00
const slug = entry.get('slug');
2016-09-15 15:50:33 -03:00
const ownStatus = entry.getIn(['metaData', 'status']);
2016-09-14 18:25:45 -03:00
const collection = entry.getIn(['metaData', 'collection']);
2016-09-09 17:15:58 -03:00
return (
2016-09-15 15:50:33 -03:00
/* eslint-disable */
<DragSource key={slug} slug={slug} collection={collection} ownStatus={ownStatus}>
<div className={styles.drag}>
<Card className={styles.card}>
<h2><Link to={link}>{entry.getIn(['data', 'title'])}</Link> <small>by {author}</small></h2>
<p>Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}</p>
{(ownStatus === status.last()) &&
<button onClick={this.requestPublish.bind(this, collection, slug, status)}>Publish now</button>
}
</Card>
</div>
</DragSource>
/* eslint-enable */
2016-09-09 17:15:58 -03:00
);
2016-09-08 19:04:54 -03:00
}
)}
2016-09-09 17:15:58 -03:00
</div>;
}
2016-10-03 14:25:27 +02:00
};
2016-09-08 19:04:54 -03:00
render() {
2016-09-09 17:15:58 -03:00
const columns = this.renderColumns(this.props.entries);
2016-09-08 19:04:54 -03:00
return (
2016-09-13 16:00:24 -03:00
<div className={styles.clear}>
2016-09-13 12:32:26 -03:00
<h1>Editorial Workflow</h1>
2016-09-13 16:00:24 -03:00
<div className={styles.container}>
2016-09-08 19:04:54 -03:00
{columns}
2016-09-13 16:00:24 -03:00
</div>
2016-09-08 19:04:54 -03:00
</div>
);
}
}
UnpublishedListing.propTypes = {
2016-09-09 17:15:58 -03:00
entries: ImmutablePropTypes.orderedMap,
2016-09-13 16:00:24 -03:00
handleChangeStatus: PropTypes.func.isRequired,
2016-09-14 18:25:45 -03:00
handlePublish: PropTypes.func.isRequired,
2016-09-08 19:04:54 -03:00
};
2016-09-13 16:00:24 -03:00
2016-09-15 15:50:33 -03:00
export default HTML5DragDrop(UnpublishedListing);