tableRenderer.tsx 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import {LocationDescriptorObject} from 'history';
  2. import {GridColumnOrder, GridColumnSortBy} from 'sentry/components/gridEditable';
  3. import SortLink from 'sentry/components/gridEditable/sortLink';
  4. interface TableHeadProps<K> {
  5. currentSort?: GridColumnSortBy<K> | null;
  6. generateSortLink?: (column: K) => () => LocationDescriptorObject | undefined;
  7. onClick?(column: GridColumnOrder<K>, e: React.MouseEvent<HTMLAnchorElement>): void;
  8. rightAlignedColumns?: Set<K>;
  9. sortableColumns?: Set<K>;
  10. }
  11. export function renderTableHead<K>({
  12. currentSort,
  13. generateSortLink,
  14. rightAlignedColumns,
  15. sortableColumns,
  16. onClick,
  17. }: TableHeadProps<K>) {
  18. return (column: GridColumnOrder<K>, _columnIndex: number) => {
  19. return (
  20. <SortLink
  21. onClick={e => onClick?.(column, e)}
  22. align={rightAlignedColumns?.has(column.key) ? 'right' : 'left'}
  23. title={column.name}
  24. direction={currentSort?.key === column.key ? currentSort?.order : undefined}
  25. canSort={sortableColumns?.has(column.key) || false}
  26. generateSortLink={generateSortLink?.(column.key) ?? (() => undefined)}
  27. replace
  28. />
  29. );
  30. };
  31. }