-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Object Detail page breadcrumb
Closes #1814
- Loading branch information
1 parent
5dddd77
commit 44c53fe
Showing
5 changed files
with
139 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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> | ||
); |
23 changes: 23 additions & 0 deletions
23
front/src/modules/ui/breadcrumb/components/__stories__/Breadcrumb.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
]; |