-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1182 from Chia-Network/refactor/table-column-sort
feat: add table column sort
- Loading branch information
Showing
11 changed files
with
151 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './useUrlHash'; | ||
export * from './useQueryParamState'; | ||
export * from './useQueryParamState'; | ||
export * from './useColumnOrder'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useCallback } from 'react'; | ||
|
||
/** | ||
* A custom hook to manage table column sorting order logic. | ||
* It provides a function to update the order based on user interaction. | ||
* The order cycles through 'ASC', 'DESC', and no order ('') when the same column is clicked. | ||
* Clicking a new column sets the order to 'ASC'. | ||
* | ||
* @param {string} order The current sorting order. | ||
* @param {Function} setOrder The function to update the sorting order. | ||
* @returns {Function} The function to handle updating the order based on column clicks. | ||
*/ | ||
function useColumnOrderHandler(order, setOrder) { | ||
const handleSetOrder = useCallback((column) => { | ||
const currentColumn = order.split(':')[0]; | ||
const currentDirection = order.split(':')[1]; | ||
|
||
if (currentColumn === column) { | ||
// Cycle through 'ASC', 'DESC', and no order ('') | ||
switch (currentDirection) { | ||
case 'ASC': | ||
setOrder(`${column}:DESC`); | ||
break; | ||
case 'DESC': | ||
setOrder(''); | ||
break; | ||
default: | ||
setOrder(`${column}:ASC`); | ||
break; | ||
} | ||
} else { | ||
// Default to ascending order for a new column | ||
setOrder(`${column}:ASC`); | ||
} | ||
}, [order, setOrder]); | ||
|
||
return handleSetOrder; | ||
} | ||
|
||
export { useColumnOrderHandler }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.