Skip to content

Commit

Permalink
Add standard object to left pannel when required
Browse files Browse the repository at this point in the history
  • Loading branch information
martmull committed May 27, 2024
1 parent f1d778a commit bc4f87e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import styled from '@emotion/styled';
import { Avatar } from 'twenty-ui';

import { useIsLogged } from '@/auth/hooks/useIsLogged';
import { FavoritesSkeletonLoader } from '@/favorites/components/FavoritesSkeletonLoader';
import { useIsMockedDrawerPage } from '@/navigation/hooks/useIsMockedDrawerPage';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { DraggableItem } from '@/ui/layout/draggable-list/components/DraggableItem';
import { DraggableList } from '@/ui/layout/draggable-list/components/DraggableList';
Expand Down Expand Up @@ -36,9 +36,11 @@ const StyledNavigationDrawerItem = styled(NavigationDrawerItem)`
export const Favorites = () => {
const { favorites, handleReorderFavorite } = useFavorites();
const loading = useIsPrefetchLoading();
const isLogged = useIsLogged();
const isMockedDrawerPage = useIsMockedDrawerPage();

if (loading && isLogged) {
const displayLoader = loading && !isMockedDrawerPage;

if (displayLoader) {
return <FavoritesSkeletonLoader />;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { renderHook } from '@testing-library/react';
import { RecoilRoot } from 'recoil';

import { useIsMockedDrawerPage } from '@/navigation/hooks/useIsMockedDrawerPage';
import { AppPath } from '@/types/AppPath';
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';

jest.mock('~/hooks/useIsMatchingLocation');
const mockUseIsMatchingLocation = jest.mocked(useIsMatchingLocation);

const setupMockIsMatchingLocation = (pathname: string) => {
mockUseIsMatchingLocation.mockReturnValueOnce(
(path: string) => path === pathname,
);
};

const getResult = () =>
renderHook(
() => {
return useIsMockedDrawerPage();
},
{
wrapper: RecoilRoot,
},
);

const shouldReturnTrueLocations = [
AppPath.Verify,
AppPath.Invite,
AppPath.SignInUp,
AppPath.ResetPassword,
AppPath.CreateWorkspace,
AppPath.PlanRequired,
AppPath.PlanRequiredSuccess,
];

describe('useIsMockedDrawerPage', () => {
Object.values(AppPath).forEach((location) => {
const expectedResult = shouldReturnTrueLocations.includes(location);
it(`should return ${
expectedResult ? 'true' : 'false'
} for location ${location}`, () => {
setupMockIsMatchingLocation(location);
const { result } = getResult();
if (expectedResult) {
expect(result.current).toBeTruthy();
} else {
expect(result.current).toBeFalsy();
}
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AppPath } from '@/types/AppPath';
import { useIsMatchingLocation } from '~/hooks/useIsMatchingLocation';

export const useIsMockedDrawerPage = () => {
const isMatchingLocation = useIsMatchingLocation();
return (
isMatchingLocation(AppPath.Verify) ||
isMatchingLocation(AppPath.SignInUp) ||
isMatchingLocation(AppPath.Invite) ||
isMatchingLocation(AppPath.ResetPassword) ||
isMatchingLocation(AppPath.CreateWorkspace) ||
isMatchingLocation(AppPath.PlanRequired) ||
isMatchingLocation(AppPath.PlanRequiredSuccess)
);
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useLocation } from 'react-router-dom';
import { useIcons } from 'twenty-ui';

import { useIsLogged } from '@/auth/hooks/useIsLogged';
import { useIsMockedDrawerPage } from '@/navigation/hooks/useIsMockedDrawerPage';
import { ObjectMetadataNavItemsSkeletonLoader } from '@/object-metadata/components/ObjectMetadataNavItemsSkeletonLoader';
import { useFilteredObjectMetadataItems } from '@/object-metadata/hooks/useFilteredObjectMetadataItems';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
Expand All @@ -18,9 +18,11 @@ export const ObjectMetadataNavItems = () => {

const { records: views } = usePrefetchedData<View>(PrefetchKey.AllViews);
const loading = useIsPrefetchLoading();
const isLogged = useIsLogged();
const isMockedDrawerPage = useIsMockedDrawerPage();

if (loading && isLogged) {
const displayLoader = loading && !isMockedDrawerPage;

if (displayLoader) {
return <ObjectMetadataNavItemsSkeletonLoader />;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import styled from '@emotion/styled';

import { useIsLogged } from '@/auth/hooks/useIsLogged';
import { useIsMockedDrawerPage } from '@/navigation/hooks/useIsMockedDrawerPage';
import { useIsPrefetchLoading } from '@/prefetch/hooks/useIsPrefetchLoading';
import { NavigationDrawerSectionTitleSkeletonLoader } from '@/ui/navigation/navigation-drawer/components/NavigationDrawerSectionTitleSkeletonLoader';

Expand All @@ -21,9 +21,11 @@ export const NavigationDrawerSectionTitle = ({
label,
}: NavigationDrawerSectionTitleProps) => {
const loading = useIsPrefetchLoading();
const isLogged = useIsLogged();
const isMockedDrawerPage = useIsMockedDrawerPage();

if (loading && isLogged) {
const displayLoader = loading && !isMockedDrawerPage;

if (displayLoader) {
return <NavigationDrawerSectionTitleSkeletonLoader />;
}
return <StyledTitle>{label}</StyledTitle>;
Expand Down

0 comments on commit bc4f87e

Please sign in to comment.