-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create ESLint rule to discourage usage of navigate() and prefer Link (#…
…5642) ### Description Create ESLint rule to discourage usage of navigate() and prefer Link ### Refs #5468 ### Demo ![Capture-2024-05-29-112852](https://github.com/twentyhq/twenty/assets/140154534/28378c09-86bb-49d3-9e9a-49aa1c07ad11) ![Capture-2024-05-29-112843](https://github.com/twentyhq/twenty/assets/140154534/2c05ea92-e19b-49ae-acb9-07f6ec9182ab) Fixes #5468 --------- Co-authored-by: gitstart-twenty <[email protected]> Co-authored-by: v1b3m <[email protected]> Co-authored-by: Matheus <[email protected]> Co-authored-by: Félix Malfait <[email protected]>
- Loading branch information
1 parent
234e062
commit bb7d94a
Showing
18 changed files
with
317 additions
and
132 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
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
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
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
25 changes: 25 additions & 0 deletions
25
packages/twenty-front/src/modules/ui/navigation/link/components/UndecoratedLink.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,25 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
import styled from '@emotion/styled'; | ||
|
||
const StyledUndecoratedLink = styled(Link)` | ||
text-decoration: none; | ||
`; | ||
|
||
type UndecoratedLinkProps = { | ||
to: string | number; | ||
children: React.ReactNode; | ||
replace?: boolean; | ||
}; | ||
|
||
export const UndecoratedLink = ({ | ||
children, | ||
to, | ||
replace = false, | ||
}: UndecoratedLinkProps) => { | ||
return ( | ||
<StyledUndecoratedLink to={to as string} replace={replace}> | ||
{children} | ||
</StyledUndecoratedLink> | ||
); | ||
}; |
32 changes: 32 additions & 0 deletions
32
...y-front/src/modules/ui/navigation/link/components/__stories__/UndecoratedLink.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,32 @@ | ||
import { expect } from '@storybook/jest'; | ||
import { Meta, StoryObj } from '@storybook/react'; | ||
import { userEvent, within } from '@storybook/test'; | ||
|
||
import { UndecoratedLink } from '@/ui/navigation/link/components/UndecoratedLink'; | ||
import { ComponentWithRouterDecorator } from '~/testing/decorators/ComponentWithRouterDecorator'; | ||
|
||
const meta: Meta<typeof UndecoratedLink> = { | ||
title: 'UI/navigation/link/UndecoratedLink', | ||
component: UndecoratedLink, | ||
decorators: [ComponentWithRouterDecorator], | ||
}; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof UndecoratedLink>; | ||
|
||
export const Default: Story = { | ||
args: { | ||
children: 'Go Home', | ||
to: '/home', | ||
}, | ||
play: async ({ canvasElement }) => { | ||
const canvas = within(canvasElement); | ||
|
||
const link = canvas.getByText('Go Home'); | ||
|
||
await userEvent.click(link); | ||
|
||
const href = link.getAttribute('href'); | ||
expect(href).toBe('/home'); | ||
}, | ||
}; |
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
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
Oops, something went wrong.