tableRenderer.tsx 1.0 KB

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