2017-01-20 16:22:57 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* List
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import { createStructuredSelector } from 'reselect';
|
|
|
|
import { injectIntl } from 'react-intl';
|
2017-01-23 20:04:12 +01:00
|
|
|
import Container from 'components/Container';
|
2017-01-26 17:53:47 +01:00
|
|
|
import ListItem from 'components/ListItem';
|
2017-01-20 16:22:57 +01:00
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
2017-01-26 18:53:52 +01:00
|
|
|
import {
|
|
|
|
loadRecords
|
|
|
|
} from './actions';
|
2017-01-23 20:04:12 +01:00
|
|
|
|
|
|
|
import {
|
|
|
|
makeSelectModelRecords,
|
|
|
|
makeSelectLoading
|
|
|
|
} from './selectors';
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
export class List extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-01-23 20:04:12 +01:00
|
|
|
|
|
|
|
componentWillMount() {
|
|
|
|
this.props.loadRecords(this.props.routeParams.slug.toLowerCase());
|
|
|
|
}
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
render() {
|
2017-01-23 20:04:12 +01:00
|
|
|
if (this.props.loading) {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p>Loading...</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const Plugin = this.props.plugin;
|
2017-01-26 17:53:47 +01:00
|
|
|
const items = this.props.records.map((record, key) => {
|
|
|
|
const destination = this.props.route.path.replace(':slug', this.props.routeParams.slug) + '/' + record.id;
|
|
|
|
|
2017-01-23 20:04:12 +01:00
|
|
|
return (
|
2017-01-26 17:53:47 +01:00
|
|
|
<ListItem key={key} destination={destination} {...record} />
|
2017-01-23 20:04:12 +01:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2017-01-23 20:04:12 +01:00
|
|
|
<div className={`container-fluid ${styles.containerFluid}`}>
|
|
|
|
<Plugin title={{
|
|
|
|
id: 'plugin-content-manager-title',
|
|
|
|
defaultMessage: `Content Manager > ${this.props.routeParams.slug}`
|
|
|
|
}} description={{
|
|
|
|
id: 'plugin-content-manager-description',
|
|
|
|
defaultMessage: `Manage your ${this.props.routeParams.slug}`
|
|
|
|
}} noActions={false}>
|
|
|
|
</Plugin>
|
|
|
|
<Container>
|
|
|
|
<p></p>
|
|
|
|
<ul>
|
2017-01-26 17:53:47 +01:00
|
|
|
{items}
|
2017-01-23 20:04:12 +01:00
|
|
|
</ul>
|
|
|
|
</Container>
|
2017-01-20 16:22:57 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-23 20:04:12 +01:00
|
|
|
List.propTypes = {
|
|
|
|
records: React.PropTypes.array,
|
|
|
|
loadRecords: React.PropTypes.func,
|
|
|
|
loading: React.PropTypes.bool
|
|
|
|
};
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return {
|
2017-01-23 20:04:12 +01:00
|
|
|
loadRecords: (model) => dispatch(loadRecords(model)),
|
2017-01-20 16:22:57 +01:00
|
|
|
dispatch,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-01-23 20:04:12 +01:00
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
|
|
records: makeSelectModelRecords(),
|
|
|
|
loading: makeSelectLoading()
|
|
|
|
});
|
2017-01-20 16:22:57 +01:00
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(List));
|