static-cms/src/components/UnpublishedListing.js

53 lines
1.7 KiB
JavaScript
Raw Normal View History

2016-09-08 19:04:54 -03:00
import React from 'react';
import ImmutablePropTypes from 'react-immutable-proptypes';
import moment from 'moment';
2016-09-08 19:04:54 -03:00
import { Card } from './UI';
import { Link } from 'react-router'
2016-09-08 19:04:54 -03:00
import { 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
export default class UnpublishedListing extends React.Component {
2016-09-09 17:15:58 -03: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) {
return entries.entrySeq().map(([currColumn, currEntries]) => (
<div key={currColumn} className={styles.column}>
<h3>{statusDescriptions.get(currColumn)}</h3>
{this.renderColumns(currEntries, currColumn)}
</div>
));
} 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']));
const timeStamp = moment(entry.getIn(['metaData', 'timeStamp'])).formate('llll');
const link = `/editorialworkflow/${entry.getIn(['metaData', 'collection'])}/${entry.getIn(['metaData', 'status'])}/${entry.get('slug')}`;
2016-09-09 17:15:58 -03:00
return (
<Card key={entry.get('slug')} className={styles.card}>
<h1><Link to={link}>{entry.getIn(['data', 'title'])}</Link> <small>by {author}</small></h1>
2016-09-09 17:15:58 -03:00
<p>Last updated: {timeStamp} by {entry.getIn(['metaData', 'user'])}</p>
</Card>
);
2016-09-08 19:04:54 -03:00
}
)}
2016-09-09 17:15:58 -03:00
</div>;
}
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 (
<div>
{columns}
</div>
);
}
}
UnpublishedListing.propTypes = {
2016-09-09 17:15:58 -03:00
entries: ImmutablePropTypes.orderedMap,
2016-09-08 19:04:54 -03:00
};