import React, { memo } from 'react'; import PropTypes from 'prop-types'; import useListView from '../../hooks/useListView'; import CustomInputCheckbox from '../CustomInputCheckbox'; import { Icon, Thead } from './styledComponents'; function TableHeader({ headers, isBulkable }) { const { data, entriesToDelete, firstSortableElement, onChangeBulkSelectall, onChangeParams, searchParams: { _sort }, } = useListView(); const [sortBy, sortOrder] = _sort.split(':'); return ( {isBulkable && ( 0 } /> )} {headers.map(header => { return ( { if (header.sortable) { const isCurrentSort = header.name === sortBy; const nextOrder = isCurrentSort && sortOrder === 'ASC' ? 'DESC' : 'ASC'; let value = `${header.name}:${nextOrder}`; if (isCurrentSort && sortOrder === 'DESC') { value = `${firstSortableElement}:ASC`; } onChangeParams({ target: { name: '_sort', value, }, }); } }} > {header.label} {sortBy === header.name && ( )} ); })} ); } TableHeader.defaultProps = { isBulkable: true, headers: [], }; TableHeader.propTypes = { headers: PropTypes.array, isBulkable: PropTypes.bool, }; export default memo(TableHeader);