-
Notifications
You must be signed in to change notification settings - Fork 5
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 #310 from itenium-be/sorting-tables
Sorting tables
- Loading branch information
Showing
13 changed files
with
145 additions
and
10 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
5 changes: 5 additions & 0 deletions
5
frontend/src/components/consultant/ConsultantProjectsList.scss
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,5 @@ | ||
table.table-consultants { | ||
td:nth-child(1) { width: 30%; } | ||
td:nth-child(2) { min-width: 110px; } | ||
td:nth-child(3) { min-width: 110px; } | ||
} |
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import useHover from "../../hooks/useHover"; | ||
import { t } from "../../utils"; | ||
import { SortIcon } from "../Icon"; | ||
import { ListFilters, SortDirection, SortDirections } from "./table-models"; | ||
|
||
type ListHeaderCellProps = { | ||
width: string | undefined | number | ||
columnName: string, | ||
header:string, | ||
filter: ListFilters | ||
onSort?: (asc: boolean | undefined) => void | ||
} | ||
|
||
export const ListHeaderCell = ({width, columnName, header, filter, onSort}: ListHeaderCellProps) => { | ||
const [hovered, eventHandlers] = useHover(); | ||
//showing sort icon when hovering or having a direction and dealing with the same column | ||
const showSortIcon = hovered || (filter?.sort?.direction !== undefined && filter?.sort?.columnName === columnName) | ||
return ( | ||
<th style={{width}} {...eventHandlers}> | ||
{header ? t(header) : <> </>} | ||
{onSort && showSortIcon ? <SortIcon | ||
fa={filter.sort?.columnName !== columnName || filter.sort?.direction === SortDirections.ASC ? "fa fa-arrow-up" : "fa fa-arrow-down"} | ||
onClick={() => { | ||
let isAsc :boolean | undefined; | ||
//only change direction is we are dealing with same column | ||
//otherwise always begin sorting ascending order | ||
if(filter.sort?.columnName === columnName){ | ||
isAsc = switchDirection(filter.sort?.direction) | ||
}else{ | ||
isAsc = true | ||
} | ||
onSort(isAsc); | ||
}} | ||
style={{marginLeft: "3px"}} | ||
size={1}/> : <> </>} | ||
</th> | ||
) | ||
} | ||
|
||
const switchDirection = (direction: SortDirection) : boolean | undefined => { | ||
if(direction === SortDirections.DESC){ | ||
return undefined; | ||
}else if (direction === undefined){ | ||
return true; | ||
}else { | ||
return false; | ||
} | ||
} |
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,14 @@ | ||
import { useState, useMemo } from 'react'; | ||
|
||
const useHover = () : [boolean, { onMouseOver(): void, onMouseOut(): void}] => { | ||
const [hovered, setHovered] = useState<boolean>(false); | ||
|
||
const eventHandlers = useMemo(() => ({ | ||
onMouseOver() { setHovered(true); }, | ||
onMouseOut() { setHovered(false); } | ||
}), []); | ||
|
||
return [hovered, eventHandlers]; | ||
} | ||
|
||
export default useHover; |
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