static-cms/src/components/UnpublishedListing.js

92 lines
3.5 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 {
2016-10-10 16:10:55 -03:00
return (<div>
{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');
2016-10-10 16:10:55 -03:00
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}>
<span className={styles.cardHeading}><Link to={link}>{entry.getIn(['data', 'title'])}</Link> <small>by {author}</small></span>
<p className={styles.cardText}>Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}</p>
2016-09-15 15:50:33 -03:00
{(ownStatus === status.last()) &&
2016-10-10 16:10:55 -03:00
<button className={styles.button} onClick={this.requestPublish.bind(this, collection, slug, ownStatus)}>Publish now</button>
2016-09-15 15:50:33 -03:00
}
</Card>
</div>
</DragSource>
/* eslint-enable */
2016-09-09 17:15:58 -03:00
);
2016-09-08 19:04:54 -03:00
}
)}
2016-10-10 16:10:55 -03:00
</div>);
2016-09-09 17:15:58 -03:00
}
2016-10-03 14:25:27 +02:00
};
2016-09-08 19:04:54 -03:00
2016-10-03 14:33:48 +02:00
static propTypes = {
entries: ImmutablePropTypes.orderedMap,
handleChangeStatus: PropTypes.func.isRequired,
handlePublish: PropTypes.func.isRequired,
};
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-10-10 16:10:55 -03:00
{columns}
2016-09-13 16:00:24 -03:00
</div>
2016-09-08 19:04:54 -03:00
</div>
);
}
}
2016-09-15 15:50:33 -03:00
export default HTML5DragDrop(UnpublishedListing);