Refactor/context and scopes (#1602)

* Put onImport in a context

* Refactored RecoilScopeContexts

* Refactored naming

* Fix tests

---------

Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
Lucas Bordeau
2023-09-15 21:51:46 +02:00
committed by GitHub
parent d07474ece7
commit 0a7a0ac6cb
102 changed files with 639 additions and 552 deletions

View File

@ -1,25 +1,22 @@
import { Context } from 'react';
import { useFilteredSearchPeopleQuery } from '@/people/hooks/useFilteredSearchPeopleQuery';
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
import { FilterDropdownEntitySearchSelect } from '@/ui/view-bar/components/FilterDropdownEntitySearchSelect';
import { useViewBarContext } from '@/ui/view-bar/hooks/useViewBarContext';
import { filterDropdownSearchInputScopedState } from '@/ui/view-bar/states/filterDropdownSearchInputScopedState';
import { filterDropdownSelectedEntityIdScopedState } from '@/ui/view-bar/states/filterDropdownSelectedEntityIdScopedState';
export function FilterDropdownPeopleSearchSelect({
context,
}: {
context: Context<string | null>;
}) {
export function FilterDropdownPeopleSearchSelect() {
const { ViewBarRecoilScopeContext } = useViewBarContext();
const filterDropdownSearchInput = useRecoilScopedValue(
filterDropdownSearchInputScopedState,
context,
ViewBarRecoilScopeContext,
);
const [filterDropdownSelectedEntityId] = useRecoilScopedState(
filterDropdownSelectedEntityIdScopedState,
context,
ViewBarRecoilScopeContext,
);
const peopleForSelect = useFilteredSearchPeopleQuery({
@ -30,9 +27,6 @@ export function FilterDropdownPeopleSearchSelect({
});
return (
<FilterDropdownEntitySearchSelect
entitiesForSelect={peopleForSelect}
context={context}
/>
<FilterDropdownEntitySearchSelect entitiesForSelect={peopleForSelect} />
);
}

View File

@ -46,7 +46,7 @@ export function PeopleFullNameEditableField({ people }: OwnProps) {
}
return (
<RecoilScope SpecificContext={FieldRecoilScopeContext}>
<RecoilScope CustomRecoilScopeContext={FieldRecoilScopeContext}>
<DoubleTextInputEdit
firstValuePlaceholder="Empty"
secondValuePlaceholder="Empty"

View File

@ -7,7 +7,7 @@ import { numberOfTableRowsState } from '@/ui/table/states/numberOfTableRowsState
import { TableRecoilScopeContext } from '@/ui/table/states/recoil-scope-contexts/TableRecoilScopeContext';
import { tableRowIdsState } from '@/ui/table/states/tableRowIdsState';
import { currentPageLocationState } from '@/ui/utilities/loading-state/states/currentPageLocationState';
import { useContextScopeId } from '@/ui/utilities/recoil-scope/hooks/useContextScopeId';
import { useRecoilScopeId } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopeId';
import { availableFiltersScopedState } from '@/ui/view-bar/states/availableFiltersScopedState';
import { GetPeopleQuery } from '~/generated/graphql';
import { peopleFilters } from '~/pages/people/people-filters';
@ -24,7 +24,7 @@ import { peoplePhoneFamilyState } from '../states/peoplePhoneFamilyState';
export function useSetPeopleEntityTable() {
const resetTableRowSelection = useResetTableRowSelection();
const tableContextScopeId = useContextScopeId(TableRecoilScopeContext);
const tableContextScopeId = useRecoilScopeId(TableRecoilScopeContext);
const currentLocation = useLocation().pathname;

View File

@ -69,10 +69,11 @@ export function PeopleTable() {
onViewCreate: createView,
onViewEdit: updateView,
onViewRemove: deleteView,
onImport: handleImport,
ViewBarRecoilScopeContext: TableRecoilScopeContext,
}}
>
<EntityTable
onImport={handleImport}
updateEntityMutation={({
variables,
}: {