-
Notifications
You must be signed in to change notification settings - Fork 487
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sortable header for component list in web UI (#5642)
Signed-off-by: hainenber <[email protected]> Co-authored-by: William Dumont <[email protected]> Co-authored-by: Paulin Todev <[email protected]> Co-authored-by: Paschalis Tsilias <[email protected]>
- Loading branch information
1 parent
0a23b6d
commit d27f011
Showing
10 changed files
with
129 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { useState } from 'react'; | ||
|
||
import { SortOrder } from './types'; | ||
|
||
interface Props { | ||
headers: string[]; | ||
handleSorting?: (header: string, sortOrder: SortOrder) => void; | ||
} | ||
|
||
const TableHead = ({ headers, handleSorting }: Props) => { | ||
const [sortField, setSortField] = useState('ID'); | ||
const [order, setOrder] = useState(SortOrder.ASC); | ||
|
||
const handleSortingChange = (header: string) => { | ||
// User clicks on the new header, use default ASC sort order | ||
let sortOrder = SortOrder.ASC; | ||
|
||
// User clicks again on the header, we toggle the previous sort order | ||
if (header === sortField) { | ||
sortOrder = order === SortOrder.ASC ? SortOrder.DESC : SortOrder.ASC; | ||
} | ||
|
||
if (handleSorting !== undefined) { | ||
setSortField(header); | ||
setOrder(sortOrder); | ||
handleSorting(header, sortOrder); | ||
} | ||
}; | ||
|
||
return ( | ||
<tr> | ||
{headers.map((header) => { | ||
return ( | ||
<th | ||
key={header} | ||
onClick={() => handleSortingChange(header)} | ||
data-sort-order={handleSorting && sortField === header ? order : undefined} | ||
> | ||
{header} | ||
</th> | ||
); | ||
})} | ||
</tr> | ||
); | ||
}; | ||
|
||
export default TableHead; |
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