import _ from 'lodash'; import PropTypes from 'prop-types'; import React, { Component } from 'react'; import { sortDirections } from 'Helpers/Props'; import VirtualTable from 'Components/Table/VirtualTable'; import ArtistIndexItemConnector from 'Artist/Index/ArtistIndexItemConnector'; import ArtistIndexHeaderConnector from './ArtistIndexHeaderConnector'; import ArtistIndexRow from './ArtistIndexRow'; import styles from './ArtistIndexTable.css'; class ArtistIndexTable extends Component { constructor(props, context) { super(props, context); this._table = null; } // // Control /** * Sets the reference to the virtual table * @param ref */ setTableRef = (ref) => { this._table = ref; }; scrollToFirstCharacter(character) { const items = this.props.items; const row = _.findIndex(items, (item) => { const firstCharacter = item.sortName.charAt(0); if (character === '#') { return !isNaN(firstCharacter); } return firstCharacter === character; }); if (row != null) { this._table.scrollToRow(row); } } rowRenderer = ({ key, rowIndex, style }) => { const { items, columns } = this.props; const artist = items[rowIndex]; return ( ); } // // Render render() { const { items, columns, filterKey, filterValue, sortKey, sortDirection, isSmallScreen, scrollTop, contentBody, onSortPress, onRender, onScroll } = this.props; return ( } columns={columns} filterKey={filterKey} filterValue={filterValue} sortKey={sortKey} sortDirection={sortDirection} onRender={onRender} onScroll={onScroll} /> ); } } ArtistIndexTable.propTypes = { items: PropTypes.arrayOf(PropTypes.object).isRequired, columns: PropTypes.arrayOf(PropTypes.object).isRequired, filterKey: PropTypes.string, filterValue: PropTypes.oneOfType([PropTypes.bool, PropTypes.number, PropTypes.string]), sortKey: PropTypes.string, sortDirection: PropTypes.oneOf(sortDirections.all), scrollTop: PropTypes.number.isRequired, contentBody: PropTypes.object.isRequired, isSmallScreen: PropTypes.bool.isRequired, onSortPress: PropTypes.func.isRequired, onRender: PropTypes.func.isRequired, onScroll: PropTypes.func.isRequired }; export default ArtistIndexTable;