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:
@ -1,8 +1,9 @@
|
||||
import { type Context, type ReactNode, useContext } from 'react';
|
||||
import { type ReactNode, useContext } from 'react';
|
||||
import styled from '@emotion/styled';
|
||||
import { useRecoilState } from 'recoil';
|
||||
|
||||
import { BoardCardIdContext } from '@/ui/board/contexts/BoardCardIdContext';
|
||||
import { useBoardContext } from '@/ui/board/hooks/useBoardContext';
|
||||
import { useCurrentCardSelected } from '@/ui/board/hooks/useCurrentCardSelected';
|
||||
import { visibleBoardCardFieldsScopedSelector } from '@/ui/board/states/selectors/visibleBoardCardFieldsScopedSelector';
|
||||
import { EntityChipVariant } from '@/ui/chip/components/EntityChip';
|
||||
@ -19,10 +20,6 @@ import { companyProgressesFamilyState } from '../states/companyProgressesFamilyS
|
||||
|
||||
import { CompanyChip } from './CompanyChip';
|
||||
|
||||
type OwnProps = {
|
||||
scopeContext: Context<string | null>;
|
||||
};
|
||||
|
||||
const StyledBoardCard = styled.div<{ selected: boolean }>`
|
||||
background-color: ${({ theme, selected }) =>
|
||||
selected ? theme.accent.quaternary : theme.background.secondary};
|
||||
@ -103,7 +100,9 @@ const StyledFieldContainer = styled.div`
|
||||
width: 100%;
|
||||
`;
|
||||
|
||||
export function CompanyBoardCard({ scopeContext }: OwnProps) {
|
||||
export function CompanyBoardCard() {
|
||||
const { BoardRecoilScopeContext } = useBoardContext();
|
||||
|
||||
const { currentCardSelected, setCurrentCardSelected } =
|
||||
useCurrentCardSelected();
|
||||
const boardCardId = useContext(BoardCardIdContext);
|
||||
@ -115,7 +114,7 @@ export function CompanyBoardCard({ scopeContext }: OwnProps) {
|
||||
|
||||
const visibleBoardCardFields = useRecoilScopedValue(
|
||||
visibleBoardCardFieldsScopedSelector,
|
||||
scopeContext,
|
||||
BoardRecoilScopeContext,
|
||||
);
|
||||
|
||||
// boardCardId check can be moved to a wrapper to avoid unnecessary logic above
|
||||
|
||||
@ -1,26 +1,23 @@
|
||||
import { Context } from 'react';
|
||||
|
||||
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';
|
||||
|
||||
import { useFilteredSearchCompanyQuery } from '../hooks/useFilteredSearchCompanyQuery';
|
||||
|
||||
export function FilterDropdownCompanySearchSelect({
|
||||
context,
|
||||
}: {
|
||||
context: Context<string | null>;
|
||||
}) {
|
||||
export function FilterDropdownCompanySearchSelect() {
|
||||
const { ViewBarRecoilScopeContext } = useViewBarContext();
|
||||
|
||||
const filterDropdownSearchInput = useRecoilScopedValue(
|
||||
filterDropdownSearchInputScopedState,
|
||||
context,
|
||||
ViewBarRecoilScopeContext,
|
||||
);
|
||||
|
||||
const [filterDropdownSelectedEntityId] = useRecoilScopedState(
|
||||
filterDropdownSelectedEntityIdScopedState,
|
||||
context,
|
||||
ViewBarRecoilScopeContext,
|
||||
);
|
||||
|
||||
const usersForSelect = useFilteredSearchCompanyQuery({
|
||||
@ -31,9 +28,6 @@ export function FilterDropdownCompanySearchSelect({
|
||||
});
|
||||
|
||||
return (
|
||||
<FilterDropdownEntitySearchSelect
|
||||
entitiesForSelect={usersForSelect}
|
||||
context={context}
|
||||
/>
|
||||
<FilterDropdownEntitySearchSelect entitiesForSelect={usersForSelect} />
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user