mirror of
https://github.com/hanzoai/sentinel.git
synced 2026-09-29 22:34:33 +00:00
27 lines
710 B
TypeScript
27 lines
710 B
TypeScript
import type {ReactText} from 'react';
|
|
import type {Location, LocationDescriptorObject} from 'history';
|
|
|
|
import type {GridColumnOrder} from 'sentry/components/gridEditable';
|
|
import type {Sort} from 'sentry/utils/discover/fields';
|
|
|
|
export default function queryBasedSortLinkGenerator<Key extends ReactText>(
|
|
location: Location,
|
|
column: GridColumnOrder<Key>,
|
|
currentSort: Sort
|
|
): () => LocationDescriptorObject {
|
|
const direction =
|
|
currentSort.field !== column.key
|
|
? 'desc'
|
|
: currentSort.kind === 'desc'
|
|
? 'asc'
|
|
: 'desc';
|
|
|
|
return () => ({
|
|
...location,
|
|
query: {
|
|
...location.query,
|
|
sort: `${direction === 'desc' ? '-' : ''}${column.key}`,
|
|
},
|
|
});
|
|
}
|