Refactor Views by cleaning the code, relying on apolloCache and improving performances (#4516)
* Wip refactoring view * Post merge conflicts * Fix review * Add create view capability * Fix create object missing view * Fix tests
This commit is contained in:
@ -36,9 +36,9 @@ const StyledContainer = styled.div`
|
||||
export const TabList = ({ tabs, tabListId }: TabListProps) => {
|
||||
const initialActiveTabId = tabs[0].id;
|
||||
|
||||
const { getActiveTabIdState, setActiveTabId } = useTabList(tabListId);
|
||||
const { activeTabIdState, setActiveTabId } = useTabList(tabListId);
|
||||
|
||||
const activeTabId = useRecoilValue(getActiveTabIdState());
|
||||
const activeTabId = useRecoilValue(activeTabIdState);
|
||||
|
||||
React.useEffect(() => {
|
||||
setActiveTabId(initialActiveTabId);
|
||||
|
||||
@ -8,12 +8,11 @@ describe('useTabList', () => {
|
||||
it('Should update the activeTabId state', async () => {
|
||||
const { result } = renderHook(
|
||||
() => {
|
||||
const { getActiveTabIdState, setActiveTabId } =
|
||||
const { activeTabIdState, setActiveTabId } =
|
||||
useTabList('TEST_TAB_LIST_ID');
|
||||
const activeTabId = useRecoilValue(getActiveTabIdState());
|
||||
const activeTabId = useRecoilValue(activeTabIdState);
|
||||
|
||||
return {
|
||||
getActiveTabIdState: getActiveTabIdState,
|
||||
activeTabId,
|
||||
setActiveTabId: setActiveTabId,
|
||||
};
|
||||
@ -22,7 +21,6 @@ describe('useTabList', () => {
|
||||
wrapper: RecoilRoot,
|
||||
},
|
||||
);
|
||||
expect(result.current.getActiveTabIdState).toBeInstanceOf(Function);
|
||||
expect(result.current.setActiveTabId).toBeInstanceOf(Function);
|
||||
expect(result.current.activeTabId).toBeNull();
|
||||
|
||||
|
||||
@ -15,9 +15,6 @@ export const useTabListStates = ({ tabListScopeId }: useTabListStatesProps) => {
|
||||
|
||||
return {
|
||||
scopeId,
|
||||
getActiveTabIdState: extractComponentState(
|
||||
activeTabIdComponentState,
|
||||
scopeId,
|
||||
),
|
||||
activeTabIdState: extractComponentState(activeTabIdComponentState, scopeId),
|
||||
};
|
||||
};
|
||||
|
||||
@ -3,14 +3,14 @@ import { useSetRecoilState } from 'recoil';
|
||||
import { useTabListStates } from '@/ui/layout/tab/hooks/internal/useTabListStates';
|
||||
|
||||
export const useTabList = (tabListId?: string) => {
|
||||
const { getActiveTabIdState } = useTabListStates({
|
||||
const { activeTabIdState } = useTabListStates({
|
||||
tabListScopeId: `${tabListId}-scope`,
|
||||
});
|
||||
|
||||
const setActiveTabId = useSetRecoilState(getActiveTabIdState());
|
||||
const setActiveTabId = useSetRecoilState(activeTabIdState);
|
||||
|
||||
return {
|
||||
getActiveTabIdState,
|
||||
activeTabIdState,
|
||||
setActiveTabId,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user