2017-01-26 17:53:47 +01:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Single
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import { connect } from 'react-redux';
|
2017-01-26 18:53:52 +01:00
|
|
|
import { createStructuredSelector } from 'reselect';
|
2017-03-20 22:08:49 +01:00
|
|
|
import Container from 'components/Container';
|
2017-01-26 18:53:52 +01:00
|
|
|
|
|
|
|
import {
|
2017-03-20 22:08:49 +01:00
|
|
|
setCurrentModel,
|
|
|
|
loadRecord,
|
2017-01-26 18:53:52 +01:00
|
|
|
} from './actions';
|
|
|
|
|
|
|
|
import {
|
2017-03-20 22:08:49 +01:00
|
|
|
makeSelectRecord,
|
|
|
|
makeSelectLoading,
|
2017-01-26 18:53:52 +01:00
|
|
|
} from './selectors';
|
2017-01-26 17:53:47 +01:00
|
|
|
|
|
|
|
export class Single extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-01-26 18:53:52 +01:00
|
|
|
|
|
|
|
componentWillMount() {
|
2017-03-20 22:08:49 +01:00
|
|
|
this.props.setCurrentModel(this.props.routeParams.slug.toLowerCase());
|
|
|
|
this.props.loadRecord(this.props.routeParams.id);
|
2017-01-26 18:53:52 +01:00
|
|
|
}
|
|
|
|
|
2017-01-26 17:53:47 +01:00
|
|
|
render() {
|
2017-03-20 22:08:49 +01:00
|
|
|
const PluginHeader = this.props.exposedComponents.PluginHeader;
|
2017-01-26 18:53:52 +01:00
|
|
|
|
2017-03-20 22:08:49 +01:00
|
|
|
let content;
|
|
|
|
if (this.props.loading) {
|
|
|
|
content = (
|
|
|
|
<div>
|
|
|
|
<p>Loading...</p>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} else if (this.props.record) {
|
|
|
|
const items = [];
|
|
|
|
for(var key in this.props.record) {
|
|
|
|
items.push(<li key={key}>{key}: {this.props.record[key]}</li>);
|
|
|
|
}
|
|
|
|
|
|
|
|
content = (
|
|
|
|
<ul>
|
|
|
|
{items}
|
|
|
|
</ul>
|
|
|
|
)
|
2017-01-26 18:53:52 +01:00
|
|
|
}
|
2017-03-20 22:08:49 +01:00
|
|
|
|
2017-01-26 17:53:47 +01:00
|
|
|
return (
|
2017-03-20 22:08:49 +01:00
|
|
|
<div>
|
|
|
|
<div className="container-fluid">
|
|
|
|
<PluginHeader 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}>
|
|
|
|
</PluginHeader>
|
|
|
|
<Container>
|
|
|
|
<p></p>
|
|
|
|
{content}
|
|
|
|
</Container>
|
|
|
|
</div>
|
|
|
|
</div>
|
2017-01-26 17:53:47 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-20 22:08:49 +01:00
|
|
|
|
|
|
|
Single.propTypes = {
|
|
|
|
setCurrentModel: React.PropTypes.func,
|
|
|
|
loadRecord: React.PropTypes.func,
|
|
|
|
loading: React.PropTypes.bool,
|
|
|
|
record: React.PropTypes.oneOfType([
|
|
|
|
React.PropTypes.object,
|
|
|
|
React.PropTypes.bool,
|
|
|
|
]),
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2017-01-26 18:53:52 +01:00
|
|
|
const mapStateToProps = createStructuredSelector({
|
2017-03-20 22:08:49 +01:00
|
|
|
record: makeSelectRecord(),
|
|
|
|
loading: makeSelectLoading(),
|
2017-01-26 18:53:52 +01:00
|
|
|
});
|
2017-01-26 17:53:47 +01:00
|
|
|
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
return {
|
2017-03-20 22:08:49 +01:00
|
|
|
setCurrentModel: (model) => dispatch(setCurrentModel(model)),
|
|
|
|
loadRecord: (id) => dispatch(loadRecord(id)),
|
2017-01-26 17:53:47 +01:00
|
|
|
dispatch,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(Single);
|