diff --git a/front/src/components/table/table-header/SortDropdownButton.tsx b/front/src/components/table/table-header/SortDropdownButton.tsx new file mode 100644 index 000000000..0f6cbffb2 --- /dev/null +++ b/front/src/components/table/table-header/SortDropdownButton.tsx @@ -0,0 +1,38 @@ +import { useCallback } from 'react'; +import DropdownButton from './DropdownButton'; +import { SortType } from './SortAndFilterBar'; + +type OwnProps = { + sorts: SortType[]; + setSorts: any; + sortsAvailable: any; +}; + +export function SortDropdownButton({ + sortsAvailable, + setSorts, + sorts, +}: OwnProps) { + const onSortItemSelect = useCallback( + (sortId: string) => { + const newSorts = [ + { + label: 'Created at', + order: 'asc', + id: sortId, + } satisfies SortType, + ]; + setSorts(newSorts); + }, + [setSorts], + ); + + return ( + 0} + /> + ); +} diff --git a/front/src/components/table/table-header/TableHeader.tsx b/front/src/components/table/table-header/TableHeader.tsx index 7c7c4620e..a3ba9ac36 100644 --- a/front/src/components/table/table-header/TableHeader.tsx +++ b/front/src/components/table/table-header/TableHeader.tsx @@ -4,6 +4,7 @@ import DropdownButton from './DropdownButton'; import { IconProp } from '@fortawesome/fontawesome-svg-core'; import SortAndFilterBar, { SortType } from './SortAndFilterBar'; import { useCallback, useState } from 'react'; +import { SortDropdownButton } from './SortDropdownButton'; type OwnProps = { viewName: string; @@ -50,19 +51,12 @@ function TableHeader({ onSortsUpdate, sortsAvailable, }: OwnProps) { - const [sorts, setSorts] = useState([] as Array); + const [sorts, innerSetSorts] = useState([] as Array); - const onSortItemSelect = useCallback( - (sortId: string) => { - const newSorts = [ - { - label: 'Created at', - order: 'asc', - id: sortId, - } satisfies SortType, - ]; - setSorts(newSorts); - onSortsUpdate && onSortsUpdate(newSorts); + const setSorts = useCallback( + (sorts: SortType[]) => { + innerSetSorts(sorts); + onSortsUpdate && onSortsUpdate(sorts); }, [onSortsUpdate], ); @@ -70,7 +64,7 @@ function TableHeader({ const onSortItemUnSelect = useCallback( (sortId: string) => { const newSorts = [] as SortType[]; - setSorts(newSorts); + innerSetSorts(newSorts); onSortsUpdate && onSortsUpdate(newSorts); }, [onSortsUpdate], @@ -87,12 +81,12 @@ function TableHeader({ - 0} + +