renderSortableHeaderCell.tsx 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import type {MouseEvent} from 'react';
  2. import type {LocationDescriptorObject} from 'history';
  3. import type {GridColumnOrder} from 'sentry/components/gridEditable';
  4. import SortLink from 'sentry/components/gridEditable/sortLink';
  5. import type {Sort} from 'sentry/utils/discover/fields';
  6. interface Props<Key extends string> {
  7. currentSort: Sort;
  8. makeSortLinkGenerator: (column: GridColumnOrder<Key>) => () => LocationDescriptorObject;
  9. onClick(column: GridColumnOrder<Key>, e: MouseEvent<HTMLAnchorElement>): void;
  10. rightAlignedColumns: GridColumnOrder<string>[];
  11. sortableColumns: GridColumnOrder<string>[];
  12. }
  13. export default function renderSortableHeaderCell<Key extends string>({
  14. currentSort,
  15. onClick,
  16. rightAlignedColumns,
  17. sortableColumns,
  18. makeSortLinkGenerator,
  19. }: Props<Key>) {
  20. return function (column: GridColumnOrder<Key>, _columnIndex: number) {
  21. return (
  22. <SortLink
  23. onClick={e => onClick(column, e)}
  24. align={rightAlignedColumns.includes(column) ? 'right' : 'left'}
  25. title={column.name}
  26. direction={currentSort?.field === column.key ? currentSort?.kind : undefined}
  27. canSort={sortableColumns.includes(column)}
  28. generateSortLink={makeSortLinkGenerator(column)}
  29. replace
  30. />
  31. );
  32. };
  33. }