Skip to content

Commit

Permalink
fix twentyhq#7085 breadcrumb fix for mobile viewport (twentyhq#7419)
Browse files Browse the repository at this point in the history
  • Loading branch information
NitinPSingh and lucasbordeau authored Oct 31, 2024
1 parent 74291e5 commit e5641c5
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCommandMenu } from '@/command-menu/hooks/useCommandMenu';
import { isCommandMenuOpenedState } from '@/command-menu/states/isCommandMenuOpenedState';
import { useOpenSettingsMenu } from '@/navigation/hooks/useOpenSettings';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { useRecoilState } from 'recoil';
import {
Expand All @@ -23,6 +24,8 @@ export const MobileNavigationBar = () => {
const [currentMobileNavigationDrawer, setCurrentMobileNavigationDrawer] =
useRecoilState(currentMobileNavigationDrawerState);

const { openSettingsMenu } = useOpenSettingsMenu();

const activeItemName = isNavigationDrawerExpanded
? currentMobileNavigationDrawer
: isCommandMenuOpened
Expand Down Expand Up @@ -62,10 +65,7 @@ export const MobileNavigationBar = () => {
Icon: IconSettings,
onClick: () => {
closeCommandMenu();
setIsNavigationDrawerExpanded(
(previousIsOpen) => activeItemName !== 'settings' || !previousIsOpen,
);
setCurrentMobileNavigationDrawer('settings');
openSettingsMenu();
},
},
];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { currentMobileNavigationDrawerState } from '@/navigation/states/currentMobileNavigationDrawerState';
import { isNavigationDrawerExpandedState } from '@/ui/navigation/states/isNavigationDrawerExpanded';
import { useRecoilState } from 'recoil';

export const useOpenSettingsMenu = () => {
const [, setIsNavigationDrawerExpanded] = useRecoilState(
isNavigationDrawerExpandedState,
);
const [, setCurrentMobileNavigationDrawer] = useRecoilState(
currentMobileNavigationDrawerState,
);

const openSettingsMenu = () => {
setIsNavigationDrawerExpanded(true);
setCurrentMobileNavigationDrawer('settings');
};

return { openSettingsMenu };
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import { SettingsIntegrationDatabaseTablesListCard } from '@/settings/integratio
import { useDatabaseConnection } from '@/settings/integrations/database-connection/hooks/useDatabaseConnection';
import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { Section } from '@react-email/components';
import { useNavigate } from 'react-router-dom';
import { Breadcrumb, H2Title } from 'twenty-ui';
import { H2Title } from 'twenty-ui';

export const SettingsIntegrationDatabaseConnectionShowContainer = () => {
const navigate = useNavigate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import { getSettingsPagePath } from '@/settings/utils/getSettingsPagePath';
import { SettingsPath } from '@/types/SettingsPath';
import { SnackBarVariant } from '@/ui/feedback/snack-bar-manager/components/SnackBar';
import { useSnackBar } from '@/ui/feedback/snack-bar-manager/hooks/useSnackBar';
import { Breadcrumb } from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import { zodResolver } from '@hookform/resolvers/zod';
import { Section } from '@react-email/components';
import pick from 'lodash.pick';
import { FormProvider, useForm } from 'react-hook-form';
import { useNavigate } from 'react-router-dom';
import { Breadcrumb, H2Title, Info } from 'twenty-ui';
import { H2Title, Info } from 'twenty-ui';
import { z } from 'zod';
import {
RemoteServer,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { InformationBannerWrapper } from '@/information-banner/components/InformationBannerWrapper';
import {
Breadcrumb,
BreadcrumbProps,
} from '@/ui/navigation/bread-crumb/components/Breadcrumb';
import styled from '@emotion/styled';
import { JSX, ReactNode } from 'react';
import { Breadcrumb, BreadcrumbProps } from 'twenty-ui';
import { PageBody } from './PageBody';
import { PageHeader } from './PageHeader';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { MobileBreadcrumb } from '@/ui/navigation/bread-crumb/components/MobileBreadcrumb';
import { useIsMobile } from '@/ui/utilities/responsive/hooks/useIsMobile';
import styled from '@emotion/styled';
import { Fragment, ReactNode } from 'react';
import { Link } from 'react-router-dom';
Expand Down Expand Up @@ -39,6 +41,12 @@ const StyledDivider = styled.span`
`;

export const Breadcrumb = ({ className, links }: BreadcrumbProps) => {
const isMobile = useIsMobile();

if (isMobile && links.length > 0) {
return <MobileBreadcrumb className={className} links={links} />;
}

return (
<StyledWrapper className={className}>
{links.map((link, index) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useOpenSettingsMenu } from '@/navigation/hooks/useOpenSettings';
import { useTheme } from '@emotion/react';
import styled from '@emotion/styled';
import { isNonEmptyString } from '@sniptt/guards';
import { ReactNode } from 'react';
import { Link } from 'react-router-dom';
import { IconChevronLeft } from 'twenty-ui';

export type MobileBreadcrumbProps = {
className?: string;
links: { children: string | ReactNode; href?: string }[];
};

const StyledWrapper = styled.nav`
align-items: center;
color: ${({ theme }) => theme.font.color.tertiary};
display: grid;
font-size: ${({ theme }) => theme.font.size.md};
grid-auto-flow: column;
grid-column-gap: ${({ theme }) => theme.spacing(1)};
max-width: 100%;
min-width: 0;
height: ${({ theme }) => theme.spacing(8)};
`;

const StyledLink = styled(Link)`
color: inherit;
text-decoration: none;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

const StyledText = styled.span`
color: inherit;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
`;

export const MobileBreadcrumb = ({
className,
links,
}: MobileBreadcrumbProps) => {
const theme = useTheme();

const { openSettingsMenu } = useOpenSettingsMenu();

const handleBackToSettingsClick = () => {
openSettingsMenu();
};

const previousLink = links[links.length - 2];
const shouldRedirectToSettings = links.length === 2;

const text = isNonEmptyString(previousLink.children)
? previousLink.children
: '';

return (
<StyledWrapper className={className}>
{shouldRedirectToSettings ? (
<>
<IconChevronLeft size={theme.icon.size.md} />
<StyledText onClick={handleBackToSettingsClick}>
Back to Settings
</StyledText>
</>
) : previousLink?.href ? (
<>
<IconChevronLeft size={theme.icon.size.md} />
<StyledLink title={text} to={previousLink.href}>
Back to {previousLink.children}
</StyledLink>
</>
) : (
<StyledText title={text}>{previousLink?.children}</StyledText>
)}
</StyledWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Meta, StoryObj } from '@storybook/react';
import { ComponentDecorator, Breadcrumb } from 'twenty-ui';
import { ComponentDecorator } from 'twenty-ui';
import { Breadcrumb } from '../Breadcrumb';

import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator';

Expand Down
1 change: 0 additions & 1 deletion packages/twenty-ui/src/navigation/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './breadcrumb/components/Breadcrumb';
export * from './link/components/ActionLink';
export * from './link/components/AdvancedSettingsToggle';
export * from './link/components/ContactLink';
Expand Down

0 comments on commit e5641c5

Please sign in to comment.