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-04-10 16:28:30 +02:00
|
|
|
import Table from 'components/Table';
|
|
|
|
|
import _ from 'lodash';
|
2017-01-20 16:22:57 +01:00
|
|
|
|
|
|
|
|
import styles from './styles.scss';
|
|
|
|
|
|
2017-01-26 18:53:52 +01:00
|
|
|
import {
|
2017-04-10 16:28:30 +02:00
|
|
|
setCurrentModelName,
|
2017-03-20 22:08:49 +01:00
|
|
|
loadRecords,
|
2017-01-26 18:53:52 +01:00
|
|
|
} from './actions';
|
2017-01-23 20:04:12 +01:00
|
|
|
|
|
|
|
|
import {
|
2017-03-20 22:08:49 +01:00
|
|
|
makeSelectLoading,
|
|
|
|
|
makeSelectModelRecords,
|
2017-04-10 16:28:30 +02:00
|
|
|
makeSelectCurrentModelName,
|
2017-01-23 20:04:12 +01:00
|
|
|
} from './selectors';
|
|
|
|
|
|
2017-04-10 16:28:30 +02:00
|
|
|
import {
|
|
|
|
|
makeSelectModels,
|
|
|
|
|
} from 'containers/App/selectors';
|
2017-01-23 20:04:12 +01:00
|
|
|
|
2017-04-10 16:28:30 +02:00
|
|
|
export class List extends React.Component { // eslint-disable-line react/prefer-stateless-function
|
2017-01-23 20:04:12 +01:00
|
|
|
componentWillMount() {
|
2017-04-10 16:28:30 +02:00
|
|
|
this.props.setCurrentModelName(this.props.routeParams.slug.toLowerCase());
|
2017-03-20 22:08:49 +01:00
|
|
|
this.props.loadRecords();
|
2017-01-23 20:04:12 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
render() {
|
2017-03-20 22:08:49 +01:00
|
|
|
const PluginHeader = this.props.exposedComponents.PluginHeader;
|
|
|
|
|
|
|
|
|
|
let content;
|
2017-01-23 20:04:12 +01:00
|
|
|
if (this.props.loading) {
|
2017-03-20 22:08:49 +01:00
|
|
|
content = (
|
2017-01-23 20:04:12 +01:00
|
|
|
<div>
|
|
|
|
|
<p>Loading...</p>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2017-03-20 22:08:49 +01:00
|
|
|
} else {
|
2017-04-10 16:28:30 +02:00
|
|
|
// Detect current model structure from models list
|
|
|
|
|
const currentModel = this.props.models[this.props.currentModelName];
|
2017-01-23 20:04:12 +01:00
|
|
|
|
2017-04-10 16:35:51 +02:00
|
|
|
// Hide non displayed attributes
|
|
|
|
|
const displayedAttributes = _.pickBy(currentModel.attributes, (attr) => (!attr.admin || attr.admin.displayed !== false));
|
|
|
|
|
|
2017-04-10 16:28:30 +02:00
|
|
|
// Define table headers
|
2017-04-10 16:35:51 +02:00
|
|
|
const tableHeaders = _.map(displayedAttributes, (value, key) => ({
|
2017-04-10 16:28:30 +02:00
|
|
|
name: key,
|
|
|
|
|
label: key,
|
|
|
|
|
type: value.type,
|
|
|
|
|
})
|
|
|
|
|
);
|
2017-01-26 17:53:47 +01:00
|
|
|
|
2017-03-20 22:08:49 +01:00
|
|
|
content = (
|
2017-04-10 16:28:30 +02:00
|
|
|
<Table
|
|
|
|
|
records={this.props.records}
|
|
|
|
|
route={this.props.route}
|
|
|
|
|
routeParams={this.props.routeParams}
|
|
|
|
|
headers={tableHeaders}
|
|
|
|
|
/>
|
2017-03-20 22:08:49 +01:00
|
|
|
)
|
|
|
|
|
}
|
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}`}>
|
2017-03-20 22:08:49 +01:00
|
|
|
<PluginHeader title={{
|
2017-01-23 20:04:12 +01:00
|
|
|
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}>
|
2017-03-20 22:08:49 +01:00
|
|
|
</PluginHeader>
|
2017-01-23 20:04:12 +01:00
|
|
|
<Container>
|
|
|
|
|
<p></p>
|
2017-03-20 22:08:49 +01:00
|
|
|
{content}
|
2017-01-23 20:04:12 +01:00
|
|
|
</Container>
|
2017-01-20 16:22:57 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 20:04:12 +01:00
|
|
|
List.propTypes = {
|
2017-04-10 16:28:30 +02:00
|
|
|
setCurrentModelName: React.PropTypes.func,
|
2017-03-20 22:08:49 +01:00
|
|
|
records: React.PropTypes.oneOfType([
|
|
|
|
|
React.PropTypes.array,
|
|
|
|
|
React.PropTypes.bool,
|
|
|
|
|
]),
|
2017-01-23 20:04:12 +01:00
|
|
|
loadRecords: React.PropTypes.func,
|
2017-04-10 16:28:30 +02:00
|
|
|
loading: React.PropTypes.bool,
|
|
|
|
|
models: React.PropTypes.oneOfType([
|
|
|
|
|
React.PropTypes.object,
|
|
|
|
|
React.PropTypes.bool,
|
|
|
|
|
]),
|
|
|
|
|
currentModelName: React.PropTypes.string,
|
2017-01-23 20:04:12 +01:00
|
|
|
};
|
|
|
|
|
|
2017-01-20 16:22:57 +01:00
|
|
|
function mapDispatchToProps(dispatch) {
|
|
|
|
|
return {
|
2017-04-10 16:28:30 +02:00
|
|
|
setCurrentModelName: (modelName) => dispatch(setCurrentModelName(modelName)),
|
2017-03-20 22:08:49 +01:00
|
|
|
loadRecords: () => dispatch(loadRecords()),
|
2017-01-20 16:22:57 +01:00
|
|
|
dispatch,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 20:04:12 +01:00
|
|
|
const mapStateToProps = createStructuredSelector({
|
|
|
|
|
records: makeSelectModelRecords(),
|
2017-03-18 17:34:00 +01:00
|
|
|
loading: makeSelectLoading(),
|
2017-04-10 16:28:30 +02:00
|
|
|
models: makeSelectModels(),
|
|
|
|
|
currentModelName: makeSelectCurrentModelName(),
|
2017-01-23 20:04:12 +01:00
|
|
|
});
|
2017-01-20 16:22:57 +01:00
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(List));
|