Skip to content

Commit

Permalink
feat: add Object Detail page breadcrumb
Browse files Browse the repository at this point in the history
Closes #1814
  • Loading branch information
thaisguigon committed Oct 10, 2023
1 parent 5dddd77 commit 683bdde
Show file tree
Hide file tree
Showing 5 changed files with 140 additions and 43 deletions.
43 changes: 43 additions & 0 deletions front/src/modules/ui/breadcrumb/components/Breadcrumb.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Fragment } from 'react';
import { Link } from 'react-router-dom';
import styled from '@emotion/styled';

type BreadcrumbProps = {
className?: string;
links: { children: string; href?: string }[];
};

const StyledWrapper = styled.nav`
align-items: center;
color: ${({ theme }) => theme.font.color.extraLight};
display: flex;
font-size: ${({ theme }) => theme.font.size.lg};
font-weight: ${({ theme }) => theme.font.weight.semiBold};
gap: ${({ theme }) => theme.spacing(2)};
height: ${({ theme }) => theme.spacing(6)};
line-height: ${({ theme }) => theme.text.lineHeight.md};
`;

const StyledLink = styled(Link)`
color: inherit;
text-decoration: none;
`;

const StyledText = styled.span`
color: ${({ theme }) => theme.font.color.tertiary};
`;

export const Breadcrumb = ({ className, links }: BreadcrumbProps) => (
<StyledWrapper className={className}>
{links.map((link, index) => (
<Fragment key={index}>
{link.href ? (
<StyledLink to={link.href}>{link.children}</StyledLink>
) : (
<StyledText>{link.children}</StyledText>
)}
{index < links.length - 1 && '/'}
</Fragment>
))}
</StyledWrapper>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Meta, StoryObj } from '@storybook/react';

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

import { Breadcrumb } from '../Breadcrumb';

const meta: Meta<typeof Breadcrumb> = {
title: 'UI/Breadcrumb/Breadcrumb',
component: Breadcrumb,
decorators: [ComponentDecorator],
args: {
links: [
{ children: 'Objects', href: '/link-1' },
{ children: 'Companies', href: '/link-2' },
{ children: 'New' },
],
},
};

export default meta;
type Story = StoryObj<typeof Breadcrumb>;

export const Default: Story = {};
35 changes: 30 additions & 5 deletions front/src/pages/settings/SettingsObjectDetail.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
import { useEffect } from 'react';
import { useNavigate, useParams } from 'react-router-dom';
import styled from '@emotion/styled';

import { AppPath } from '@/types/AppPath';
import { Breadcrumb } from '@/ui/breadcrumb/components/Breadcrumb';
import { IconSettings } from '@/ui/icon';
import { SubMenuTopBarContainer } from '@/ui/layout/components/SubMenuTopBarContainer';
import { assertNotNull } from '~/utils/assert';

import { activeObjectItems } from './constants/mockObjects';
import { objectSettingsWidth } from './constants/objectSettings';

const StyledContainer = styled.div`
padding: ${({ theme }) => theme.spacing(8)};
width: ${objectSettingsWidth};
`;

export const SettingsObjectDetail = () => (
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
<StyledContainer />
</SubMenuTopBarContainer>
);
export const SettingsObjectDetail = () => {
const navigate = useNavigate();
const { pluralObjectName = '' } = useParams();
const activeObject = activeObjectItems.find(
(activeObject) => activeObject.name.toLowerCase() === pluralObjectName,
);

useEffect(() => {
if (!activeObject) navigate(AppPath.NotFound);
}, [activeObject, navigate]);

return (
<SubMenuTopBarContainer Icon={IconSettings} title="Settings">
<StyledContainer>
<Breadcrumb
links={[
{ children: 'Objects', href: '/settings/objects' },
{ children: activeObject?.name ?? '' },
].filter(assertNotNull)}
/>
</StyledContainer>
</SubMenuTopBarContainer>
);
};
42 changes: 4 additions & 38 deletions front/src/pages/settings/SettingsObjects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,10 @@ import styled from '@emotion/styled';

import { Button } from '@/ui/button/components/Button';
import {
IconBuildingSkyscraper,
IconChevronRight,
IconDotsVertical,
IconLuggage,
IconPlane,
IconPlus,
IconSettings,
IconUser,
} from '@/ui/icon';
import { SubMenuTopBarContainer } from '@/ui/layout/components/SubMenuTopBarContainer';
import { Table } from '@/ui/table/components/Table';
Expand All @@ -23,6 +19,10 @@ import { Tag } from '@/ui/tag/components/Tag';
import { H1Title } from '@/ui/typography/components/H1Title';
import { H2Title } from '@/ui/typography/components/H2Title';

import {
activeObjectItems,
disabledObjectItems,
} from './constants/mockObjects';
import { objectSettingsWidth } from './constants/objectSettings';

const StyledContainer = styled.div`
Expand Down Expand Up @@ -68,40 +68,6 @@ const StyledH1Title = styled(H1Title)`
margin-bottom: 0;
`;

const activeObjectItems = [
{
name: 'Companies',
Icon: IconBuildingSkyscraper,
type: 'standard',
fields: 23,
instances: 165,
},
{
name: 'People',
Icon: IconUser,
type: 'standard',
fields: 16,
instances: 462,
},
];

const disabledObjectItems = [
{
name: 'Travels',
Icon: IconLuggage,
type: 'custom',
fields: 23,
instances: 165,
},
{
name: 'Flights',
Icon: IconPlane,
type: 'custom',
fields: 23,
instances: 165,
},
];

export const SettingsObjects = () => {
const theme = useTheme();
const navigate = useNavigate();
Expand Down
40 changes: 40 additions & 0 deletions front/src/pages/settings/constants/mockObjects.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import {
IconBuildingSkyscraper,
IconLuggage,
IconPlane,
IconUser,
} from '@/ui/icon';

export const activeObjectItems = [
{
name: 'Companies',
Icon: IconBuildingSkyscraper,
type: 'standard',
fields: 23,
instances: 165,
},
{
name: 'People',
Icon: IconUser,
type: 'standard',
fields: 16,
instances: 462,
},
];

export const disabledObjectItems = [
{
name: 'Travels',
Icon: IconLuggage,
type: 'custom',
fields: 23,
instances: 165,
},
{
name: 'Flights',
Icon: IconPlane,
type: 'custom',
fields: 23,
instances: 165,
},
];

0 comments on commit 683bdde

Please sign in to comment.