From f7c53dbdeb2328b2bcb00ba0cc119a76c2f9c542 Mon Sep 17 00:00:00 2001 From: Sammy Teillet Date: Mon, 24 Apr 2023 18:17:01 +0200 Subject: [PATCH] feature: set the right sort on click --- .../table/table-header/DropdownButton.tsx | 6 +----- .../table/table-header/SortDropdownButton.tsx | 14 +++----------- .../components/table/table-header/TableHeader.tsx | 12 ++---------- 3 files changed, 6 insertions(+), 26 deletions(-) diff --git a/front/src/components/table/table-header/DropdownButton.tsx b/front/src/components/table/table-header/DropdownButton.tsx index 16eac92b4..75469b77e 100644 --- a/front/src/components/table/table-header/DropdownButton.tsx +++ b/front/src/components/table/table-header/DropdownButton.tsx @@ -2,13 +2,10 @@ import styled from '@emotion/styled'; import { useRef, ReactNode } from 'react'; import { useOutsideAlerter } from '../../../hooks/useOutsideAlerter'; import { modalBackground } from '../../../layout/styles/themes'; -import { SortType } from './SortAndFilterBar'; type OwnProps = { label: string; - options: Array; isActive: boolean; - onSortSelect?: (id: string) => void; children?: ReactNode; isUnfolded?: boolean; setIsUnfolded?: React.Dispatch>; @@ -92,7 +89,6 @@ const StyledIcon = styled.div` function DropdownButton({ label, - options, isActive, children, isUnfolded = false, @@ -118,7 +114,7 @@ function DropdownButton({ > {label} - {isUnfolded && options.length > 0 && ( + {isUnfolded && ( {children} )} diff --git a/front/src/components/table/table-header/SortDropdownButton.tsx b/front/src/components/table/table-header/SortDropdownButton.tsx index c0695dd8b..35d1dcb2d 100644 --- a/front/src/components/table/table-header/SortDropdownButton.tsx +++ b/front/src/components/table/table-header/SortDropdownButton.tsx @@ -17,14 +17,8 @@ export function SortDropdownButton({ const [isUnfolded, setIsUnfolded] = useState(false); const onSortItemSelect = useCallback( - (sortId: string) => { - const newSorts = [ - { - label: 'Created at', - order: 'asc', - id: sortId, - } satisfies SortType, - ]; + (sort: SortType) => { + const newSorts = [sort]; setSorts(newSorts); }, [setSorts], @@ -33,8 +27,6 @@ export function SortDropdownButton({ return ( 0} isUnfolded={isUnfolded} setIsUnfolded={setIsUnfolded} @@ -44,7 +36,7 @@ export function SortDropdownButton({ key={index} onClick={() => { setIsUnfolded(false); - onSortItemSelect(option.id); + onSortItemSelect(option); }} > diff --git a/front/src/components/table/table-header/TableHeader.tsx b/front/src/components/table/table-header/TableHeader.tsx index 98aa5d74e..97f5a7384 100644 --- a/front/src/components/table/table-header/TableHeader.tsx +++ b/front/src/components/table/table-header/TableHeader.tsx @@ -80,22 +80,14 @@ function TableHeader({ {viewName} - + - + {sorts.length > 0 && (