From e5004512213febeb7d31b8d09dc57ab2b33fdb7f Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Thu, 21 Nov 2024 16:40:40 +0100 Subject: [PATCH 1/5] add border bottom --- .../ui/layout/dropdown/components/DropdownMenuSearchInput.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx index 00edc11cea1a..21f6cdbbd969 100644 --- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx +++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx @@ -13,6 +13,7 @@ const StyledDropdownMenuSearchInputContainer = styled.div` flex-direction: row; height: calc(36px - 2 * var(--vertical-padding)); padding: var(--vertical-padding) 0; + border-bottom: 1px solid ${({ theme }) => theme.border.color.light}; width: 100%; `; From 1aa57c1244bb774a0710a15e713daf9108e16e41 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Thu, 21 Nov 2024 16:50:19 +0100 Subject: [PATCH 2/5] add DropdownMenuSeparator --- .../components/ObjectFilterDropdownFilterInput.tsx | 2 ++ .../ui/layout/dropdown/components/DropdownMenuSearchInput.tsx | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx index 7d5bcf561cc5..50def03fa643 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx @@ -84,6 +84,7 @@ export const ObjectFilterDropdownFilterInput = ({ {filterDefinitionUsedInDropdown.type === 'RELATION' && ( <> + )} @@ -98,6 +99,7 @@ export const ObjectFilterDropdownFilterInput = ({ ) && ( <> + )} diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx index 21f6cdbbd969..00edc11cea1a 100644 --- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx +++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuSearchInput.tsx @@ -13,7 +13,6 @@ const StyledDropdownMenuSearchInputContainer = styled.div` flex-direction: row; height: calc(36px - 2 * var(--vertical-padding)); padding: var(--vertical-padding) 0; - border-bottom: 1px solid ${({ theme }) => theme.border.color.light}; width: 100%; `; From eb44d305ece5d4a661af9be11701db3941f178be Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Fri, 22 Nov 2024 12:01:35 +0100 Subject: [PATCH 3/5] add a new dropdown to select the operand --- .../ObjectFilterDropdownFilterInput.tsx | 9 +--- ...bjectFilterDropdownFilterOperandSelect.tsx | 38 -------------- .../ObjectFilterDropdownOperandButton.tsx | 39 -------------- .../ObjectFilterDropdownOperandDropdown.tsx | 51 +++++++++++++++++++ .../ObjectFilterDropdownOperandSelect.tsx | 28 +++++----- .../ObjectFilterOperandSelectAndInput.tsx | 4 +- .../types/FiltersHotkeyScope.ts | 1 + .../components/DropdownMenuHeader.tsx | 10 +++- .../components/DropdownMenuItemsContainer.tsx | 7 ++- 9 files changed, 82 insertions(+), 105 deletions(-) delete mode 100644 packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterOperandSelect.tsx delete mode 100644 packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandButton.tsx create mode 100644 packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandDropdown.tsx diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx index 50def03fa643..c795f4ee51c9 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput.tsx @@ -28,13 +28,8 @@ export const ObjectFilterDropdownFilterInput = ({ const { filterDefinitionUsedInDropdownState, selectedOperandInDropdownState, - isObjectFilterDropdownOperandSelectUnfoldedState, } = useFilterDropdown({ filterDropdownId }); - const isObjectFilterDropdownOperandSelectUnfolded = useRecoilValue( - isObjectFilterDropdownOperandSelectUnfoldedState, - ); - const filterDefinitionUsedInDropdown = useRecoilValue( filterDefinitionUsedInDropdownState, ); @@ -58,9 +53,7 @@ export const ObjectFilterDropdownFilterInput = ({ ViewFilterOperand.IsRelative, ].includes(selectedOperandInDropdown); - const shouldHide = isObjectFilterDropdownOperandSelectUnfolded; - - if (shouldHide || !isDefined(filterDefinitionUsedInDropdown)) { + if (!isDefined(filterDefinitionUsedInDropdown)) { return null; } diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterOperandSelect.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterOperandSelect.tsx deleted file mode 100644 index 4aad6ec39d47..000000000000 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterOperandSelect.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import { ObjectFilterDropdownOperandButton } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandButton'; -import { ObjectFilterDropdownOperandSelect } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect'; -import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown'; -import styled from '@emotion/styled'; -import { useRecoilValue } from 'recoil'; - -const StyledOperandSelectContainer = styled.div` - background: ${({ theme }) => theme.background.secondary}; - box-shadow: ${({ theme }) => theme.boxShadow.light}; - border-radius: ${({ theme }) => theme.border.radius.md}; - - width: 100%; - z-index: 1000; -`; - -export const ObjectFilterDropdownFilterOperandSelect = ({ - filterDropdownId, -}: { - filterDropdownId?: string; -}) => { - const { isObjectFilterDropdownOperandSelectUnfoldedState } = - useFilterDropdown({ filterDropdownId }); - - const isObjectFilterDropdownOperandSelectUnfolded = useRecoilValue( - isObjectFilterDropdownOperandSelectUnfoldedState, - ); - - return ( - <> - - {isObjectFilterDropdownOperandSelectUnfolded && ( - - - - )} - - ); -}; diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandButton.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandButton.tsx deleted file mode 100644 index 1e21d36b1ac9..000000000000 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandButton.tsx +++ /dev/null @@ -1,39 +0,0 @@ -import { useRecoilValue } from 'recoil'; -import { IconChevronDown } from 'twenty-ui'; - -import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown'; -import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader'; - -import { getOperandLabel } from '../utils/getOperandLabel'; - -export const ObjectFilterDropdownOperandButton = () => { - const { - selectedOperandInDropdownState, - setIsObjectFilterDropdownOperandSelectUnfolded, - isObjectFilterDropdownOperandSelectUnfoldedState, - } = useFilterDropdown(); - - const selectedOperandInDropdown = useRecoilValue( - selectedOperandInDropdownState, - ); - - const isObjectFilterDropdownOperandSelectUnfolded = useRecoilValue( - isObjectFilterDropdownOperandSelectUnfoldedState, - ); - - const handleButtonClick = () => { - setIsObjectFilterDropdownOperandSelectUnfolded( - !isObjectFilterDropdownOperandSelectUnfolded, - ); - }; - - return ( - - {getOperandLabel(selectedOperandInDropdown)} - - ); -}; diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandDropdown.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandDropdown.tsx new file mode 100644 index 000000000000..4d8df76aaa30 --- /dev/null +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandDropdown.tsx @@ -0,0 +1,51 @@ +import { useRecoilValue } from 'recoil'; +import { IconChevronDown } from 'twenty-ui'; + +import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown'; +import { DropdownMenuHeader } from '@/ui/layout/dropdown/components/DropdownMenuHeader'; + +import { ObjectFilterDropdownOperandSelect } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect'; +import { FiltersHotkeyScope } from '@/object-record/object-filter-dropdown/types/FiltersHotkeyScope'; +import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; +import { useTheme } from '@emotion/react'; +import styled from '@emotion/styled'; +import { getOperandLabel } from '../utils/getOperandLabel'; + +const StyledDropdownMenuHeader = styled(DropdownMenuHeader)` + cursor: pointer; +`; + +export const ObjectFilterDropdownOperandDropdown = ({ + filterDropdownId, +}: { + filterDropdownId?: string; +}) => { + const { selectedOperandInDropdownState } = useFilterDropdown(); + + const selectedOperandInDropdown = useRecoilValue( + selectedOperandInDropdownState, + ); + + const theme = useTheme(); + + return ( + + {getOperandLabel(selectedOperandInDropdown)} + + } + dropdownComponents={} + dropdownHotkeyScope={{ + scope: FiltersHotkeyScope.ObjectFilterDropdownOperandDropdown, + }} + dropdownOffset={{ + x: parseInt(theme.spacing(2)), + }} + /> + ); +}; diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect.tsx index ec90ebe931a1..3dfd6d6203ee 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandSelect.tsx @@ -2,33 +2,35 @@ import { useRecoilValue } from 'recoil'; import { v4 } from 'uuid'; import { useFilterDropdown } from '@/object-record/object-filter-dropdown/hooks/useFilterDropdown'; +import { getInitialFilterValue } from '@/object-record/object-filter-dropdown/utils/getInitialFilterValue'; import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; +import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown'; import { ViewFilterOperand } from '@/views/types/ViewFilterOperand'; +import styled from '@emotion/styled'; import { MenuItem } from 'twenty-ui'; import { isDefined } from '~/utils/isDefined'; - -import { getInitialFilterValue } from '@/object-record/object-filter-dropdown/utils/getInitialFilterValue'; import { getOperandLabel } from '../utils/getOperandLabel'; import { getOperandsForFilterDefinition } from '../utils/getOperandsForFilterType'; +const StyledDropdownMenuItemsContainer = styled(DropdownMenuItemsContainer)` + background-color: ${({ theme }) => theme.background.primary}; + border-radius: ${({ theme }) => theme.border.radius.md}; +`; + export const ObjectFilterDropdownOperandSelect = () => { const { filterDefinitionUsedInDropdownState, setSelectedOperandInDropdown, - isObjectFilterDropdownOperandSelectUnfoldedState, - setIsObjectFilterDropdownOperandSelectUnfolded, selectedFilterState, selectFilter, } = useFilterDropdown(); + const { closeDropdown } = useDropdown(); + const filterDefinitionUsedInDropdown = useRecoilValue( filterDefinitionUsedInDropdownState, ); - const isObjectFilterDropdownOperandSelectUnfolded = useRecoilValue( - isObjectFilterDropdownOperandSelectUnfoldedState, - ); - const selectedFilter = useRecoilValue(selectedFilterState); const operandsForFilterType = isDefined(filterDefinitionUsedInDropdown) @@ -45,7 +47,6 @@ export const ObjectFilterDropdownOperandSelect = () => { ].includes(newOperand); setSelectedOperandInDropdown(newOperand); - setIsObjectFilterDropdownOperandSelectUnfolded(false); if (isValuelessOperand && isDefined(filterDefinitionUsedInDropdown)) { selectFilter?.({ @@ -81,21 +82,18 @@ export const ObjectFilterDropdownOperandSelect = () => { } }; - if (!isObjectFilterDropdownOperandSelectUnfolded) { - return <>; - } - return ( - + {operandsForFilterType.map((filterOperand, index) => ( { handleOperandChange(filterOperand); + closeDropdown(); }} text={getOperandLabel(filterOperand)} /> ))} - + ); }; diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterOperandSelectAndInput.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterOperandSelectAndInput.tsx index ec814a21a490..bf4e75e33f48 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterOperandSelectAndInput.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/ObjectFilterOperandSelectAndInput.tsx @@ -1,5 +1,5 @@ import { ObjectFilterDropdownFilterInput } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterInput'; -import { ObjectFilterDropdownFilterOperandSelect } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownFilterOperandSelect'; +import { ObjectFilterDropdownOperandDropdown } from '@/object-record/object-filter-dropdown/components/ObjectFilterDropdownOperandDropdown'; type ObjectFilterOperandSelectAndInputProps = { filterDropdownId?: string; @@ -10,7 +10,7 @@ export const ObjectFilterOperandSelectAndInput = ({ }: ObjectFilterOperandSelectAndInputProps) => { return ( <> - diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FiltersHotkeyScope.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FiltersHotkeyScope.ts index 69f8806ff47f..c1f3a4112940 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FiltersHotkeyScope.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/types/FiltersHotkeyScope.ts @@ -1,4 +1,5 @@ export enum FiltersHotkeyScope { ObjectFilterDropdownButton = 'filter-dropdown-button', ObjectSortDropdownButton = 'sort-dropdown-button', + ObjectFilterDropdownOperandDropdown = 'filter-dropdown-operand-dropdown', } diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuHeader.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuHeader.tsx index ff71e0f9a2af..911d8d520d03 100644 --- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuHeader.tsx +++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownMenuHeader.tsx @@ -49,6 +49,7 @@ type DropdownMenuHeaderProps = ComponentProps<'li'> & { EndIcon?: IconComponent; onClick?: (event: MouseEvent) => void; testId?: string; + className?: string; }; export const DropdownMenuHeader = ({ @@ -57,12 +58,17 @@ export const DropdownMenuHeader = ({ EndIcon, onClick, testId, + className, }: DropdownMenuHeaderProps) => { const theme = useTheme(); return ( <> {EndIcon && ( - + {children} @@ -70,7 +76,7 @@ export const DropdownMenuHeader = ({ )} {StartIcon && ( - + { return ( - + {hasMaxHeight ? ( From 995db175329564d9f27fff0fc4544f9bd1d53064 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Fri, 22 Nov 2024 12:28:42 +0100 Subject: [PATCH 4/5] refactor and introduce DropdownUnmountEffect --- .../AdvancedFilterViewFilterValueInput.tsx | 2 - .../MultipleFiltersDropdownButton.tsx | 6 +- .../ObjectFilterDropdownDateInput.tsx | 5 -- .../__tests__/useFilterDropdown.test.tsx | 58 -------------- .../hooks/useFilterDropdown.ts | 15 +--- .../hooks/useFilterDropdownStates.ts | 15 ---- .../layout/dropdown/components/Dropdown.tsx | 80 ++++++++++--------- .../components/DropdownUnmountEffect.tsx | 18 +++++ .../EditableFilterDropdownButton.tsx | 6 -- 9 files changed, 63 insertions(+), 142 deletions(-) create mode 100644 packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownUnmountEffect.tsx diff --git a/packages/twenty-front/src/modules/object-record/advanced-filter/components/AdvancedFilterViewFilterValueInput.tsx b/packages/twenty-front/src/modules/object-record/advanced-filter/components/AdvancedFilterViewFilterValueInput.tsx index fdfb17f59f96..8fdd693bd909 100644 --- a/packages/twenty-front/src/modules/object-record/advanced-filter/components/AdvancedFilterViewFilterValueInput.tsx +++ b/packages/twenty-front/src/modules/object-record/advanced-filter/components/AdvancedFilterViewFilterValueInput.tsx @@ -22,7 +22,6 @@ export const AdvancedFilterViewFilterValueInput = ({ const { setFilterDefinitionUsedInDropdown, setSelectedOperandInDropdown, - setIsObjectFilterDropdownOperandSelectUnfolded, setSelectedFilter, } = useFilterDropdown(); @@ -53,7 +52,6 @@ export const AdvancedFilterViewFilterValueInput = ({ onOpen={() => { setFilterDefinitionUsedInDropdown(filter.definition); setSelectedOperandInDropdown(filter.operand); - setIsObjectFilterDropdownOperandSelectUnfolded(true); setSelectedFilter(filter); }} dropdownComponents={ diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownButton.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownButton.tsx index b88f421c9857..0ba1d9146069 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownButton.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/components/MultipleFiltersDropdownButton.tsx @@ -14,13 +14,11 @@ type MultipleFiltersDropdownButtonProps = { export const MultipleFiltersDropdownButton = ({ hotkeyScope, }: MultipleFiltersDropdownButtonProps) => { - const { resetFilter, setIsObjectFilterDropdownOperandSelectUnfolded } = - useFilterDropdown(); + const { resetFilter } = useFilterDropdown(); const handleDropdownClose = useCallback(() => { resetFilter(); - setIsObjectFilterDropdownOperandSelectUnfolded(false); - }, [resetFilter, setIsObjectFilterDropdownOperandSelectUnfolded]); + }, [resetFilter]); return ( { filterDefinitionUsedInDropdownState, selectedOperandInDropdownState, selectedFilterState, - setIsObjectFilterDropdownUnfolded, selectFilter, } = useFilterDropdown(); @@ -65,8 +64,6 @@ export const ObjectFilterDropdownDateInput = () => { definition: filterDefinitionUsedInDropdown, viewFilterGroupId: selectedFilter?.viewFilterGroupId, }); - - setIsObjectFilterDropdownUnfolded(false); }; const handleRelativeDateChange = ( @@ -95,8 +92,6 @@ export const ObjectFilterDropdownDateInput = () => { definition: filterDefinitionUsedInDropdown, viewFilterGroupId: selectedFilter?.viewFilterGroupId, }); - - setIsObjectFilterDropdownUnfolded(false); }; const isRelativeOperand = diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/__tests__/useFilterDropdown.test.tsx b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/__tests__/useFilterDropdown.test.tsx index 1c15c498ed90..2d77ce2b840a 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/__tests__/useFilterDropdown.test.tsx +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/__tests__/useFilterDropdown.test.tsx @@ -259,64 +259,6 @@ describe('useFilterDropdown', () => { }); }); - it('should set isObjectFilterDropdownOperandSelectUnfolded', async () => { - const { result } = renderHook(() => { - useFilterDropdown({ filterDropdownId }); - const { isObjectFilterDropdownOperandSelectUnfoldedState } = - useFilterDropdownStates(filterDropdownId); - - const [ - isObjectFilterDropdownOperandSelectUnfolded, - setIsObjectFilterDropdownOperandSelectUnfolded, - ] = useRecoilState(isObjectFilterDropdownOperandSelectUnfoldedState); - return { - isObjectFilterDropdownOperandSelectUnfolded, - setIsObjectFilterDropdownOperandSelectUnfolded, - }; - }, renderHookConfig); - - expect(result.current.isObjectFilterDropdownOperandSelectUnfolded).toBe( - false, - ); - - act(() => { - result.current.setIsObjectFilterDropdownOperandSelectUnfolded(true); - }); - - await waitFor(() => { - expect(result.current.isObjectFilterDropdownOperandSelectUnfolded).toBe( - true, - ); - }); - }); - - it('should set isObjectFilterDropdownUnfolded', async () => { - const { result } = renderHook(() => { - useFilterDropdown({ filterDropdownId }); - const { isObjectFilterDropdownUnfoldedState } = - useFilterDropdownStates(filterDropdownId); - - const [ - isObjectFilterDropdownUnfolded, - setIsObjectFilterDropdownUnfolded, - ] = useRecoilState(isObjectFilterDropdownUnfoldedState); - return { - isObjectFilterDropdownUnfolded, - setIsObjectFilterDropdownUnfolded, - }; - }, renderHookConfig); - - expect(result.current.isObjectFilterDropdownUnfolded).toBe(false); - - act(() => { - result.current.setIsObjectFilterDropdownUnfolded(true); - }); - - await waitFor(() => { - expect(result.current.isObjectFilterDropdownUnfolded).toBe(true); - }); - }); - it('should reset filter', async () => { const { result } = renderHook(() => { const { resetFilter, selectFilter } = useFilterDropdown({ diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdown.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdown.ts index 9efd3cfa40f1..e492f5eb24a8 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdown.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdown.ts @@ -28,8 +28,6 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => { objectFilterDropdownSearchInputState, objectFilterDropdownSelectedRecordIdsState, objectFilterDropdownSelectedOptionValuesState, - isObjectFilterDropdownOperandSelectUnfoldedState, - isObjectFilterDropdownUnfoldedState, selectedFilterState, selectedOperandInDropdownState, onFilterSelectState, @@ -121,12 +119,7 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => { const setObjectFilterDropdownSelectedOptionValues = useSetRecoilState( objectFilterDropdownSelectedOptionValuesState, ); - const setIsObjectFilterDropdownOperandSelectUnfolded = useSetRecoilState( - isObjectFilterDropdownOperandSelectUnfoldedState, - ); - const setIsObjectFilterDropdownUnfolded = useSetRecoilState( - isObjectFilterDropdownUnfoldedState, - ); + const setOnFilterSelect = useSetRecoilState(onFilterSelectState); const setAdvancedFilterViewFilterGroupId = useSetRecoilState( advancedFilterViewFilterGroupIdState, @@ -143,22 +136,16 @@ export const useFilterDropdown = (props?: UseFilterDropdownProps) => { setSelectedOperandInDropdown, setFilterDefinitionUsedInDropdown, setObjectFilterDropdownSearchInput, - // setObjectFilterDropdownSelectedEntityId, setObjectFilterDropdownSelectedRecordIds, setObjectFilterDropdownSelectedOptionValues, - setIsObjectFilterDropdownOperandSelectUnfolded, - setIsObjectFilterDropdownUnfolded, setOnFilterSelect, setAdvancedFilterViewFilterGroupId, setAdvancedFilterViewFilterId, emptyFilterButKeepDefinition, filterDefinitionUsedInDropdownState, objectFilterDropdownSearchInputState, - // objectFilterDropdownSelectedEntityIdState, objectFilterDropdownSelectedRecordIdsState, objectFilterDropdownSelectedOptionValuesState, - isObjectFilterDropdownOperandSelectUnfoldedState, - isObjectFilterDropdownUnfoldedState, selectedFilterState, selectedOperandInDropdownState, onFilterSelectState, diff --git a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdownStates.ts b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdownStates.ts index 069e29a4cb1f..9068c113edd4 100644 --- a/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdownStates.ts +++ b/packages/twenty-front/src/modules/object-record/object-filter-dropdown/hooks/useFilterDropdownStates.ts @@ -1,8 +1,6 @@ import { advancedFilterViewFilterGroupIdComponentState } from '@/object-record/object-filter-dropdown/states/advancedFilterViewFilterGroupIdComponentState'; import { advancedFilterViewFilterIdComponentState } from '@/object-record/object-filter-dropdown/states/advancedFilterViewFilterIdComponentState'; import { filterDefinitionUsedInDropdownComponentState } from '@/object-record/object-filter-dropdown/states/filterDefinitionUsedInDropdownComponentState'; -import { isObjectFilterDropdownOperandSelectUnfoldedComponentState } from '@/object-record/object-filter-dropdown/states/isObjectFilterDropdownOperandSelectUnfoldedComponentState'; -import { isObjectFilterDropdownUnfoldedComponentState } from '@/object-record/object-filter-dropdown/states/isObjectFilterDropdownUnfoldedComponentState'; import { objectFilterDropdownSearchInputComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSearchInputComponentState'; import { objectFilterDropdownSelectedOptionValuesComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSelectedOptionValuesComponentState'; import { objectFilterDropdownSelectedRecordIdsComponentState } from '@/object-record/object-filter-dropdown/states/objectFilterDropdownSelectedRecordIdsComponentState'; @@ -32,17 +30,6 @@ export const useFilterDropdownStates = (scopeId: string) => { scopeId, ); - const isObjectFilterDropdownOperandSelectUnfoldedState = - extractComponentState( - isObjectFilterDropdownOperandSelectUnfoldedComponentState, - scopeId, - ); - - const isObjectFilterDropdownUnfoldedState = extractComponentState( - isObjectFilterDropdownUnfoldedComponentState, - scopeId, - ); - const selectedFilterState = extractComponentState( selectedFilterComponentState, scopeId, @@ -73,8 +60,6 @@ export const useFilterDropdownStates = (scopeId: string) => { objectFilterDropdownSearchInputState, objectFilterDropdownSelectedRecordIdsState, objectFilterDropdownSelectedOptionValuesState, - isObjectFilterDropdownOperandSelectUnfoldedState, - isObjectFilterDropdownUnfoldedState, selectedFilterState, selectedOperandInDropdownState, onFilterSelectState, diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/Dropdown.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/Dropdown.tsx index 134b59686ce9..1e6484e853f7 100644 --- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/Dropdown.tsx +++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/Dropdown.tsx @@ -21,6 +21,7 @@ import { isDefined } from '~/utils/isDefined'; import { useDropdown } from '../hooks/useDropdown'; import { useInternalHotkeyScopeManagement } from '../hooks/useInternalHotkeyScopeManagement'; +import { DropdownUnmountEffect } from '@/ui/layout/dropdown/components/DropdownUnmountEffect'; import { useListenClickOutsideV2 } from '@/ui/utilities/pointer-event/hooks/useListenClickOutsideV2'; import { DropdownMenu } from './DropdownMenu'; import { DropdownOnToggleEffect } from './DropdownOnToggleEffect'; @@ -149,25 +150,38 @@ export const Dropdown = ({ ); return ( - -
- {clickableComponent && ( -
- {clickableComponent} -
- )} - {hotkey && ( - - )} - {isDropdownOpen && usePortal && ( - + <> + +
+ {clickableComponent && ( +
+ {clickableComponent} +
+ )} + {hotkey && ( + + )} + {isDropdownOpen && usePortal && ( + + + {dropdownComponents} + + + )} + {isDropdownOpen && !usePortal && ( {dropdownComponents} - - )} - {isDropdownOpen && !usePortal && ( - - {dropdownComponents} - - )} - -
-
+ )} + +
+
+ + ); }; diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownUnmountEffect.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownUnmountEffect.tsx new file mode 100644 index 000000000000..83d67d83306c --- /dev/null +++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownUnmountEffect.tsx @@ -0,0 +1,18 @@ +import { useDropdownV2 } from '@/ui/layout/dropdown/hooks/useDropdownV2'; +import { useEffect } from 'react'; + +export const DropdownUnmountEffect = ({ + dropdownId, +}: { + dropdownId: string; +}) => { + const { closeDropdown } = useDropdownV2(); + + useEffect(() => { + return () => { + closeDropdown(dropdownId); + }; + }, [closeDropdown, dropdownId]); + + return null; +}; diff --git a/packages/twenty-front/src/modules/views/components/EditableFilterDropdownButton.tsx b/packages/twenty-front/src/modules/views/components/EditableFilterDropdownButton.tsx index 67d068a16138..7424ce73b4dc 100644 --- a/packages/twenty-front/src/modules/views/components/EditableFilterDropdownButton.tsx +++ b/packages/twenty-front/src/modules/views/components/EditableFilterDropdownButton.tsx @@ -30,7 +30,6 @@ export const EditableFilterDropdownButton = ({ setFilterDefinitionUsedInDropdown, setSelectedOperandInDropdown, setSelectedFilter, - setIsObjectFilterDropdownOperandSelectUnfolded, } = useFilterDropdown({ filterDropdownId: viewFilterDropdownId, }); @@ -87,10 +86,6 @@ export const EditableFilterDropdownButton = ({ } }, [viewFilter, deleteCombinedViewFilter]); - const handleDropdownClose = useCallback(() => { - setIsObjectFilterDropdownOperandSelectUnfolded(false); - }, [setIsObjectFilterDropdownOperandSelectUnfolded]); - return ( ); }; From 9150df7202740521996555948f323ce9a70d98f0 Mon Sep 17 00:00:00 2001 From: bosiraphael Date: Fri, 22 Nov 2024 14:55:45 +0100 Subject: [PATCH 5/5] fix parseInt radix --- .../action-menu/components/RightDrawerActionMenuDropdown.tsx | 2 +- .../components/ObjectFilterDropdownOperandDropdown.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/twenty-front/src/modules/action-menu/components/RightDrawerActionMenuDropdown.tsx b/packages/twenty-front/src/modules/action-menu/components/RightDrawerActionMenuDropdown.tsx index 2eeba819042c..e4bd94c3f87f 100644 --- a/packages/twenty-front/src/modules/action-menu/components/RightDrawerActionMenuDropdown.tsx +++ b/packages/twenty-front/src/modules/action-menu/components/RightDrawerActionMenuDropdown.tsx @@ -61,7 +61,7 @@ export const RightDrawerActionMenuDropdown = () => { clickableComponent={