Feat/single entity select relation picker (#345)
* - Implemented recoil scoped state - Implemented SingleEntitySelect - Implemented keyboard shortcut up/down select * Added useRecoilScopedValue * Fix storybook * Fix storybook * Fix storybook * Fix storybook --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
14
front/src/modules/ui/hooks/RecoilScope.tsx
Normal file
14
front/src/modules/ui/hooks/RecoilScope.tsx
Normal file
@ -0,0 +1,14 @@
|
||||
import { useState } from 'react';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { RecoilScopeContext } from './RecoilScopeContext';
|
||||
|
||||
export function RecoilScope({ children }: { children: React.ReactNode }) {
|
||||
const [currentScopeId] = useState(v4());
|
||||
|
||||
return (
|
||||
<RecoilScopeContext.Provider value={currentScopeId}>
|
||||
{children}
|
||||
</RecoilScopeContext.Provider>
|
||||
);
|
||||
}
|
||||
3
front/src/modules/ui/hooks/RecoilScopeContext.ts
Normal file
3
front/src/modules/ui/hooks/RecoilScopeContext.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { createContext } from 'react';
|
||||
|
||||
export const RecoilScopeContext = createContext<string | null>(null);
|
||||
17
front/src/modules/ui/hooks/useRecoilScopedState.ts
Normal file
17
front/src/modules/ui/hooks/useRecoilScopedState.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useContext } from 'react';
|
||||
import { RecoilState, useRecoilState } from 'recoil';
|
||||
|
||||
import { RecoilScopeContext } from './RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopedState<T>(
|
||||
recoilState: (param: string) => RecoilState<T>,
|
||||
) {
|
||||
const recoilScopeId = useContext(RecoilScopeContext);
|
||||
|
||||
if (!recoilScopeId)
|
||||
throw new Error(
|
||||
`Using a scoped atom without a RecoilScope : ${recoilState('').key}`,
|
||||
);
|
||||
|
||||
return useRecoilState<T>(recoilState(recoilScopeId));
|
||||
}
|
||||
17
front/src/modules/ui/hooks/useRecoilScopedValue.ts
Normal file
17
front/src/modules/ui/hooks/useRecoilScopedValue.ts
Normal file
@ -0,0 +1,17 @@
|
||||
import { useContext } from 'react';
|
||||
import { RecoilState, useRecoilValue } from 'recoil';
|
||||
|
||||
import { RecoilScopeContext } from './RecoilScopeContext';
|
||||
|
||||
export function useRecoilScopedValue<T>(
|
||||
recoilState: (param: string) => RecoilState<T>,
|
||||
) {
|
||||
const recoilScopeId = useContext(RecoilScopeContext);
|
||||
|
||||
if (!recoilScopeId)
|
||||
throw new Error(
|
||||
`Using a scoped atom without a RecoilScope : ${recoilState('').key}`,
|
||||
);
|
||||
|
||||
return useRecoilValue<T>(recoilState(recoilScopeId));
|
||||
}
|
||||
Reference in New Issue
Block a user