/* @flow */ import * as React from 'react'; import type { Sort, SortVariant } from "../../../../GridView"; import { SetSortContext } from "../../../../contexts/SetSortContext"; import { ContentContext } from "../../../../contexts/ContentContext"; type SetSort = (column: ?string, sort: ?SortVariant) => void; type SortLinkProps = {| column: string, value: string, enableSorting?: boolean |} export default class SortLink extends React.PureComponent { setSort = (setSort: SetSort, sort: Sort, e: SyntheticInputEvent<>) => { e.preventDefault(); let newSort; const column = e.target.getAttribute('data-column'); if (!column) { throw new Error('Invalid column'); } const oldSort = sort[column]; if (!oldSort) { newSort = 'ASC'; } else if (oldSort === 'ASC') { newSort = 'DESC'; } else { newSort = null; } setSort(column, newSort); return newSort; }; render(): React.Node { return { (setSort) => { ({ sort }) => { let className = sort[this.props.column]; return { this.props.value } } } } ; } }