Skip to content

Commit

Permalink
Refactor cycleSortDirection from switch to if else
Browse files Browse the repository at this point in the history
  • Loading branch information
apata committed Sep 11, 2024
1 parent 679877e commit bf3a453
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions assets/js/dashboard/hooks/use-order-by.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,18 @@ export function useOrderBy({
export function cycleSortDirection(
currentSortDirection: SortDirection | null
): { direction: SortDirection; hint: string } {
switch (currentSortDirection) {
case null:
case SortDirection.asc:
return {
direction: SortDirection.desc,
hint: 'Press to sort column in descending order'
}
case SortDirection.desc:
return {
direction: SortDirection.asc,
hint: 'Press to sort column in ascending order'
}
if (currentSortDirection === SortDirection.desc) {
return {
direction: SortDirection.asc,
hint: 'Press to sort column in ascending order'
}
}
// default sort is descending
return {
direction: SortDirection.desc,
hint: 'Press to sort column in descending order'
}

}

export function findOrderIndex(orderBy: OrderBy, metric: Pick<Metric, 'key'>) {
Expand Down

0 comments on commit bf3a453

Please sign in to comment.