/* * * List * */ import React from 'react'; import { connect } from 'react-redux'; import { createStructuredSelector } from 'reselect'; import { injectIntl } from 'react-intl'; import _ from 'lodash'; import Container from 'components/Container'; import Table from 'components/Table'; import TableFooter from 'components/TableFooter'; import styles from './styles.scss'; import { setCurrentModelName, loadRecords, loadCount, changePage, changeSort, changeLimit, } from './actions'; import { makeSelectRecords, makeSelectLoadingRecords, makeSelectCurrentModelName, makeSelectCurrentModelNamePluralized, makeSelectCount, makeSelectCurrentPage, makeSelectLimit, makeSelectSort, makeSelectLoadingCount, } from './selectors'; import { makeSelectModels, } from 'containers/App/selectors'; export class List extends React.Component { // eslint-disable-line react/prefer-stateless-function init(slug) { // Set current model name this.props.setCurrentModelName(slug.toLowerCase()); // Set default sort value this.props.changeSort(this.props.models[slug.toLowerCase()].primaryKey); // Load records this.props.loadRecords(); // Get the records count this.props.loadCount(); // Define the `create` route url this.addRoute = `${this.props.route.path.replace(':slug', slug)}/create`; } componentWillMount() { // Init the view this.init(this.props.routeParams.slug); } componentWillReceiveProps(nextProps) { // Check if the current slug changed in the url const locationChanged = nextProps.location.pathname !== this.props.location.pathname; // If the location changed, init the view if (locationChanged) { this.init(nextProps.params.slug); } } render() { const PluginHeader = this.props.exposedComponents.PluginHeader; let content; if (this.props.loadingRecords) { content = (
Loading...
No results.
; } else { // Detect current model structure from models list const currentModel = this.props.models[this.props.currentModelName]; // Hide non displayed attributes const displayedAttributes = _.pickBy(currentModel.attributes, (attr) => (!attr.admin || attr.admin.displayed !== false)); // Define table headers const tableHeaders = _.map(displayedAttributes, (value, key) => ({ name: key, label: key, type: value.type, })); // Add the primary key column tableHeaders.unshift({ name: currentModel.primaryKey, label: 'ID', type: 'string', }); content = (