queryBasedSortLinkGenerator.tsx 710 B

1234567891011121314151617181920212223242526
  1. import type {ReactText} from 'react';
  2. import type {Location, LocationDescriptorObject} from 'history';
  3. import type {GridColumnOrder} from 'sentry/components/gridEditable';
  4. import type {Sort} from 'sentry/utils/discover/fields';
  5. export default function queryBasedSortLinkGenerator<Key extends ReactText>(
  6. location: Location,
  7. column: GridColumnOrder<Key>,
  8. currentSort: Sort
  9. ): () => LocationDescriptorObject {
  10. const direction =
  11. currentSort.field !== column.key
  12. ? 'desc'
  13. : currentSort.kind === 'desc'
  14. ? 'asc'
  15. : 'desc';
  16. return () => ({
  17. ...location,
  18. query: {
  19. ...location.query,
  20. sort: `${direction === 'desc' ? '-' : ''}${column.key}`,
  21. },
  22. });
  23. }