The open alternative to Salesforce, designed for AI.
TypeScript crmcrm-systemcustomergood-first-issuegraphqlhacktoberfestjavascriptmarketingmonoreponestjsopen-sourcepostgresqlreactreactjssalestypescriptweb
refacto dropdown v1>v2 in address input (#11549)
Etiennee2b2697fcc9a
diff --git a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoard.tsx b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoard.tsxindex aac8012ac89..bf9db0711e9 100644--- a/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoard.tsx+++ b/packages/twenty-front/src/modules/object-record/record-board/components/RecordBoard.tsx@@ -26,7 +26,6 @@ import { DragSelect } from '@/ui/utilities/drag-select/components/DragSelect';import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';import { useClickOutsideListener } from '@/ui/utilities/pointer-event/hooks/useClickOutsideListener';import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';import { ScrollWrapper } from '@/ui/utilities/scroll/components/ScrollWrapper';import { useRecoilComponentCallbackStateV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentCallbackStateV2';import { useRecoilComponentFamilyValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValueV2';@@ -216,7 +215,7 @@ export const RecordBoard = () => {return (<RecordBoardScope- recordBoardScopeId={getScopeIdFromComponentId(recordBoardId)}+ recordBoardScopeId={recordBoardId}onColumnsChange={() => {}}onFieldsChange={() => {}}>diff --git a/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx b/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsxindex 0279d7efb9f..dff3441e3b5 100644--- a/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx+++ b/packages/twenty-front/src/modules/ui/field/input/components/AddressInput.tsx@@ -7,7 +7,6 @@ import { FieldAddressValue } from '@/object-record/record-field/types/FieldMetadimport { CountrySelect } from '@/ui/input/components/internal/country/components/CountrySelect';import { SELECT_COUNTRY_DROPDOWN_ID } from '@/ui/input/components/internal/country/constants/SelectCountryDropdownId';import { TextInputV2 } from '@/ui/input/components/TextInputV2';-import { useDropdown } from '@/ui/layout/dropdown/hooks/useDropdown';import { activeDropdownFocusIdState } from '@/ui/layout/dropdown/states/activeDropdownFocusIdState';import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';@@ -92,10 +91,6 @@ export const AddressInput = ({const [focusPosition, setFocusPosition] =useState<keyof FieldAddressDraftValue>('addressStreet1');- const { closeDropdown: closeCountryDropdown } = useDropdown(- SELECT_COUNTRY_DROPDOWN_ID,- );-const wrapperRef = useRef<HTMLDivElement>(null);const getChangeHandler =@@ -193,7 +188,6 @@ export const AddressInput = ({event.stopImmediatePropagation();- closeCountryDropdown();onClickOutside?.(event, internalValue);},enabled: isDefined(onClickOutside),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.tsxindex dae2108433b..60ede3ed611 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@@ -7,7 +7,6 @@ import { dropdownMaxHeightComponentState } from '@/ui/layout/dropdown/states/intimport { dropdownMaxWidthComponentState } from '@/ui/layout/dropdown/states/internal/dropdownMaxWidthComponentState';import { DropdownOffset } from '@/ui/layout/dropdown/types/DropdownOffset';import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';import { useSetRecoilComponentStateV2 } from '@/ui/utilities/state/component-state/hooks/useSetRecoilComponentStateV2';import styled from '@emotion/styled';import {@@ -150,7 +149,7 @@ export const Dropdown = ({<DropdownComponentInstanceContext.Providervalue={{ instanceId: dropdownId }}>- <DropdownScope dropdownScopeId={getScopeIdFromComponentId(dropdownId)}>+ <DropdownScope dropdownScopeId={dropdownId}><>{isDefined(clickableComponent) ? (<StyledClickableComponentdiff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownContent.tsx b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownContent.tsxindex d1af4bd2737..930ee84f593 100644--- a/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownContent.tsx+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/components/DropdownContent.tsx@@ -10,7 +10,6 @@ import { HotkeyEffect } from '@/ui/utilities/hotkey/components/HotkeyEffect';import { useScopedHotkeys } from '@/ui/utilities/hotkey/hooks/useScopedHotkeys';import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';import { useListenClickOutside } from '@/ui/utilities/pointer-event/hooks/useListenClickOutside';-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';import { useRecoilComponentValueV2 } from '@/ui/utilities/state/component-state/hooks/useRecoilComponentValueV2';import styled from '@emotion/styled';import {@@ -98,7 +97,7 @@ export const DropdownContent = ({});useInternalHotkeyScopeManagement({- dropdownScopeId: getScopeIdFromComponentId(dropdownId),+ dropdownScopeId: dropdownId,dropdownHotkeyScopeFromParent: hotkeyScope,});diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdown.ts b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdown.tsindex a8cf900ba6f..393bbe56a19 100644--- a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdown.ts+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdown.ts@@ -6,7 +6,6 @@ import { useSetActiveDropdownFocusIdAndMemorizePrevious } from '@/ui/layout/dropimport { dropdownHotkeyComponentState } from '@/ui/layout/dropdown/states/dropdownHotkeyComponentState';import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { getSnapshotValue } from '@/ui/utilities/recoil-scope/utils/getSnapshotValue';import { useCallback } from 'react';import { isDefined } from 'twenty-shared/utils';@@ -14,7 +13,7 @@ import { isDefined } from 'twenty-shared/utils';export const useDropdown = (dropdownId?: string) => {const { scopeId, isDropdownOpenState, dropdownPlacementState } =useDropdownStates({- dropdownScopeId: getScopeIdOrUndefinedFromComponentId(dropdownId),+ dropdownScopeId: dropdownId,});const { setActiveDropdownFocusIdAndMemorizePrevious } =diff --git a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdownV2.ts b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdownV2.tsindex be0764caf4e..e35b2e43509 100644--- a/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdownV2.ts+++ b/packages/twenty-front/src/modules/ui/layout/dropdown/hooks/useDropdownV2.ts@@ -1,10 +1,10 @@import { useRecoilCallback } from 'recoil';+import { useGoBackToPreviousDropdownFocusId } from '@/ui/layout/dropdown/hooks/useGoBackToPreviousDropdownFocusId';import { dropdownHotkeyComponentState } from '@/ui/layout/dropdown/states/dropdownHotkeyComponentState';import { isDropdownOpenComponentState } from '@/ui/layout/dropdown/states/isDropdownOpenComponentState';import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';import { isDefined } from 'twenty-shared/utils';export const useDropdownV2 = () => {@@ -13,26 +13,36 @@ export const useDropdownV2 = () => {goBackToPreviousHotkeyScope,} = usePreviousHotkeyScope();+ const { goBackToPreviousDropdownFocusId } =+ useGoBackToPreviousDropdownFocusId();+const closeDropdown = useRecoilCallback(- ({ set }) =>+ ({ set, snapshot }) =>(specificComponentId: string) => {- const scopeId = getScopeIdFromComponentId(specificComponentId);+ const scopeId = specificComponentId;- goBackToPreviousHotkeyScope();- set(- isDropdownOpenComponentState({- scopeId,- }),- false,- );+ const isDropdownOpen = snapshot+ .getLoadable(isDropdownOpenComponentState({ scopeId }))+ .getValue();++ if (isDropdownOpen) {+ goBackToPreviousHotkeyScope();+ goBackToPreviousDropdownFocusId();+ set(+ isDropdownOpenComponentState({+ scopeId,+ }),+ false,+ );+ }},- [goBackToPreviousHotkeyScope],+ [goBackToPreviousHotkeyScope, goBackToPreviousDropdownFocusId],);const openDropdown = useRecoilCallback(({ set, snapshot }) =>(specificComponentId: string, customHotkeyScope?: HotkeyScope) => {- const scopeId = getScopeIdFromComponentId(specificComponentId);+ const scopeId = specificComponentId;const dropdownHotkeyScope = snapshot.getLoadable(dropdownHotkeyComponentState({ scopeId }))@@ -63,7 +73,7 @@ export const useDropdownV2 = () => {const toggleDropdown = useRecoilCallback(({ snapshot }) =>(specificComponentId: string, customHotkeyScope?: HotkeyScope) => {- const scopeId = getScopeIdFromComponentId(specificComponentId);+ const scopeId = specificComponentId;const isDropdownOpen = snapshot.getLoadable(isDropdownOpenComponentState({ scopeId })).getValue();diff --git a/packages/twenty-front/src/modules/ui/utilities/pointer-event/hooks/useClickOustideListenerStates.ts b/packages/twenty-front/src/modules/ui/utilities/pointer-event/hooks/useClickOustideListenerStates.tsindex 26e7ebca3ae..2cc0ea918c0 100644--- a/packages/twenty-front/src/modules/ui/utilities/pointer-event/hooks/useClickOustideListenerStates.ts+++ b/packages/twenty-front/src/modules/ui/utilities/pointer-event/hooks/useClickOustideListenerStates.ts@@ -2,11 +2,10 @@ import { clickOutsideListenerCallbacksComponentState } from '@/ui/utilities/poinimport { clickOutsideListenerIsActivatedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsActivatedComponentState';import { clickOutsideListenerIsMouseDownInsideComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerIsMouseDownInsideComponentState';import { clickOutsideListenerMouseDownHappenedComponentState } from '@/ui/utilities/pointer-event/states/clickOutsideListenerMouseDownHappenedComponentState';-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';import { extractComponentState } from '@/ui/utilities/state/component-state/utils/extractComponentState';export const useClickOustideListenerStates = (componentId: string) => {- const scopeId = getScopeIdFromComponentId(componentId);+ const scopeId = componentId;return {scopeId,diff --git a/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId.ts b/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId.tsdeleted file mode 100644index bc5ce6e96b4..00000000000--- a/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId.ts+++ /dev/null@@ -1,2 +0,0 @@-export const getScopeIdFromComponentId = (componentId: string) =>- `${componentId}`;diff --git a/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId.ts b/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId.tsdeleted file mode 100644index 3892e6afd38..00000000000--- a/packages/twenty-front/src/modules/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId.ts+++ /dev/null@@ -1,4 +0,0 @@-import { getScopeIdFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdFromComponentId';--export const getScopeIdOrUndefinedFromComponentId = (componentId?: string) =>- componentId ? getScopeIdFromComponentId(componentId) : undefined;diff --git a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useExtractedComponentFamilyStateV2.ts b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useExtractedComponentFamilyStateV2.tsindex 8bf347a2b6d..f5f05e49e57 100644--- a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useExtractedComponentFamilyStateV2.ts+++ b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useExtractedComponentFamilyStateV2.ts@@ -1,5 +1,4 @@import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';import { SerializableParam } from 'recoil';@@ -22,7 +21,7 @@ export const useExtractedComponentFamilyStateV2 = <const internalScopeId = useAvailableScopeIdOrThrow(componentContext,- getScopeIdOrUndefinedFromComponentId(componentId),+ componentId,);const extractedComponentFamilyState = (familyKey: FamilyKey) =>diff --git a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue.ts b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue.tsindex 58af1dc02e1..12654b0a5e1 100644--- a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue.ts+++ b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentFamilyValue.ts@@ -1,7 +1,6 @@import { SerializableParam, useRecoilValue } from 'recoil';import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { ComponentFamilyState } from '@/ui/utilities/state/component-state/types/ComponentFamilyState';export const useRecoilComponentFamilyValue = <@@ -24,7 +23,7 @@ export const useRecoilComponentFamilyValue = <const internalComponentId = useAvailableScopeIdOrThrow(componentContext,- getScopeIdOrUndefinedFromComponentId(componentId),+ componentId,);return useRecoilValue(diff --git a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentState.ts b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentState.tsindex c0bd5e9d53b..5c02f4df3d7 100644--- a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentState.ts+++ b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentState.ts@@ -1,5 +1,4 @@import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { RecoilComponentState } from '@/ui/utilities/state/component-state/types/RecoilComponentState';import { useRecoilState } from 'recoil';@@ -19,7 +18,7 @@ export const useRecoilComponentState = <StateType>(const internalComponentId = useAvailableScopeIdOrThrow(componentContext,- getScopeIdOrUndefinedFromComponentId(componentId),+ componentId,);return useRecoilState(diff --git a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentValue.ts b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentValue.tsindex efaa56de1ad..ed76e246dc4 100644--- a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentValue.ts+++ b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useRecoilComponentValue.ts@@ -1,7 +1,6 @@import { useRecoilValue } from 'recoil';import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { RecoilComponentState } from '@/ui/utilities/state/component-state/types/RecoilComponentState';export const useRecoilComponentValue = <StateType>(@@ -20,7 +19,7 @@ export const useRecoilComponentValue = <StateType>(const internalComponentId = useAvailableScopeIdOrThrow(componentContext,- getScopeIdOrUndefinedFromComponentId(componentId),+ componentId,);return useRecoilValue(diff --git a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useSetRecoilComponentState.ts b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useSetRecoilComponentState.tsindex 9e1ca49a418..c663801378d 100644--- a/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useSetRecoilComponentState.ts+++ b/packages/twenty-front/src/modules/ui/utilities/state/component-state/hooks/useSetRecoilComponentState.ts@@ -1,7 +1,6 @@import { useSetRecoilState } from 'recoil';import { useAvailableScopeIdOrThrow } from '@/ui/utilities/recoil-scope/scopes-internal/hooks/useAvailableScopeId';-import { getScopeIdOrUndefinedFromComponentId } from '@/ui/utilities/recoil-scope/utils/getScopeIdOrUndefinedFromComponentId';import { RecoilComponentState } from '@/ui/utilities/state/component-state/types/RecoilComponentState';export const useSetRecoilComponentState = <StateType>(@@ -20,7 +19,7 @@ export const useSetRecoilComponentState = <StateType>(const internalComponentId = useAvailableScopeIdOrThrow(componentContext,- getScopeIdOrUndefinedFromComponentId(componentId),+ componentId,);return useSetRecoilState(