import React from 'react'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; import SilverStripeComponent from 'silverstripe-component'; import GridFieldTable from './table'; import GridFieldHeader from './header'; import GridFieldHeaderCell from './header-cell'; import GridFieldRow from './row'; import GridFieldCell from './cell'; import GridFieldAction from './action'; import * as actions from 'state/records/actions'; /** * The component acts as a container for a grid field, * with smarts around data retrieval from external sources. * * @todo Convert to higher order component which hooks up form * schema data to an API backend as a grid data source * @todo Replace "dumb" inner components with third party library (e.g. https://griddlegriddle.github.io) */ class GridField extends SilverStripeComponent { constructor(props) { super(props); this.deleteRecord = this.deleteRecord.bind(this); this.editRecord = this.editRecord.bind(this); } componentDidMount() { super.componentDidMount(); const data = this.props.data; this.props.actions.fetchRecords( data.recordType, data.collectionReadEndpoint.method, data.collectionReadEndpoint.url ); } render() { const records = this.props.records; if (!records) { return
; } const columns = this.props.data.columns; // Placeholder to align the headers correctly with the content const actionPlaceholder = ; const headerCells = columns.map((column, i) =>