import React from "react"; import { DEFAULT_SORT_ATTRIBUTE, SortOrderEnum, i18n } from "./constants"; import { AvailableSortingAttributesManager } from "./AvailableSortingAttributesManager"; import { SelectedSortingAttributeManager } from "./SelectedSortingAttributeManager"; import SortingOrderDefault from "../images/sort-arrow-down-default.svg"; import SortingOderDown from "../images/sort-arrow-down-active.svg"; import SortingOderUp from "../images/sort-arrow-up-active.svg"; import { DocumentAttributeTitleLookup, DocumentAttributeKeys, } from "../constants"; import "./ResultSorting.scss"; interface OwnProps { availableSortingAttributes: AvailableSortingAttributesManager; selectedSortingAttribute: SelectedSortingAttributeManager; onSortingAttributeChange: ( event: React.ChangeEvent ) => void; onSortingOrderChange: ( event: React.MouseEvent ) => void; } type Props = OwnProps; export class ResultSorting extends React.Component { getSortingAttributeSelectOptions = (attributeList: string[]) => { /* Using optgroup to apply css style for limiting attributes number displayed in dropdown */ return ( {/* Relevance is the first to show */} {/* Shows Created at and Updated at after Relevance */} {attributeList.indexOf(DocumentAttributeKeys.CreatedAt) >= 0 ? ( ) : null} {attributeList.indexOf(DocumentAttributeKeys.UpdatedAt) >= 0 ? ( ) : null} {/* Shows other date type attributes and then shows other types of attributes*/} {attributeList.map((attribute) => { if ( attribute !== DocumentAttributeKeys.CreatedAt && attribute !== DocumentAttributeKeys.UpdatedAt ) { return ( ); } else { return null; } })} ); }; renderSortingAttributeSelect = (attributeList: string[]) => { return ( ); }; getSortOrderToggleButton = (sortingOrder: string | null) => { if (!sortingOrder) { return ( ); } else if (sortingOrder === SortOrderEnum.Desc) { return ( ); } else if (sortingOrder === SortOrderEnum.Asc) { return ( ); } }; render() { const sortingOrder = this.props.selectedSortingAttribute.getSelectedSortingOrder(); return (
{i18n.sort}
{this.renderSortingAttributeSelect( this.props.availableSortingAttributes.get() )}
{!sortingOrder && this.getSortOrderToggleButton(null)} {sortingOrder === SortOrderEnum.Desc && this.getSortOrderToggleButton(SortOrderEnum.Desc)} {sortingOrder === SortOrderEnum.Asc && this.getSortOrderToggleButton(SortOrderEnum.Asc)}
); } }