Files
twenty/front/src/modules/ui/input/relation-picker/hooks/useEntitySelectSearch.ts
T
Abhishek Thory c397619100 441/fix/clear cell while opening it by typing and delete value when I hit delete / backspace. (#2021)
- Use initial values when opening table cells and pass them to fields

---------

Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
2023-11-03 16:43:54 +01:00

38 lines
1.2 KiB
TypeScript

import debounce from 'lodash.debounce';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
import { RelationPickerRecoilScopeContext } from '../states/recoil-scope-contexts/RelationPickerRecoilScopeContext';
import { relationPickerPreselectedIdScopedState } from '../states/relationPickerPreselectedIdScopedState';
import { relationPickerSearchFilterScopedState } from '../states/relationPickerSearchFilterScopedState';
export const useEntitySelectSearch = () => {
const [, setRelationPickerPreselectedId] = useRecoilScopedState(
relationPickerPreselectedIdScopedState,
RelationPickerRecoilScopeContext,
);
const [relationPickerSearchFilter, setRelationPickerSearchFilter] =
useRecoilScopedState(relationPickerSearchFilterScopedState);
const debouncedSetSearchFilter = debounce(
setRelationPickerSearchFilter,
100,
{
leading: true,
},
);
const handleSearchFilterChange = (
event: React.ChangeEvent<HTMLInputElement>,
) => {
debouncedSetSearchFilter(event.currentTarget.value);
setRelationPickerPreselectedId('');
};
return {
searchFilter: relationPickerSearchFilter,
handleSearchFilterChange,
};
};