import React from 'react'; import { UncontrolledDropdown, DropdownToggle, DropdownMenu, DropdownItem } from 'reactstrap'; import { toPairs } from 'ramda'; import PropTypes from 'prop-types'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import caretUpIcon from '@fortawesome/fontawesome-free-solid/faCaretUp'; import caretDownIcon from '@fortawesome/fontawesome-free-solid/faCaretDown'; import classNames from 'classnames'; import { determineOrderDir } from '../utils/utils'; import './SortingDropdown.scss'; const propTypes = { items: PropTypes.object.isRequired, orderField: PropTypes.string, orderDir: PropTypes.oneOf([ 'ASC', 'DESC' ]), onChange: PropTypes.func.isRequired, isButton: PropTypes.bool, right: PropTypes.bool, }; const defaultProps = { isButton: true, right: false, }; const SortingDropdown = ({ items, orderField, orderDir, onChange, isButton, right }) => { const handleItemClick = (fieldKey) => () => { const newOrderDir = determineOrderDir(fieldKey, orderField, orderDir); onChange(newOrderDir ? fieldKey : undefined, newOrderDir); }; return ( Order by {toPairs(items).map(([ fieldKey, fieldValue ]) => ( {fieldValue} {orderField === fieldKey && ( )} ))} onChange()}> Clear selection ); }; SortingDropdown.propTypes = propTypes; SortingDropdown.defaultProps = defaultProps; export default SortingDropdown;