-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
ref(ui): decouple scraps/link from sentry specific code #102644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e136ad0
ref(ui): decouple scraps/link from sentry specific code
TkDodo 40dd7ce
fix: scrapsTestingProviders
TkDodo d036136
Merge branch 'master' into tkdodo/ref/link-behaviour-context
TkDodo 3c8612c
Merge branch 'master' into tkdodo/ref/link-behaviour-context
TkDodo 7c0cb6b
fix: move ScrapsProvider down the tree into RouterProvider
TkDodo f1625c5
fix: we only need to fall back to 'a' tags for when we don't have a L…
TkDodo 5678cea
Merge branch 'master' into tkdodo/ref/link-behaviour-context
TkDodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,19 @@ | ||
| import {createContext, useContext, type FunctionComponent} from 'react'; | ||
|
|
||
| import type {LinkProps} from './link'; | ||
|
|
||
| const LinkBehaviorContext = createContext<{ | ||
| behavior: (props: LinkProps) => LinkProps; | ||
| component: FunctionComponent<LinkProps> | 'a'; | ||
| }>({ | ||
| component: 'a', | ||
| behavior: props => props, | ||
| }); | ||
|
|
||
| export const LinkBehaviorContextProvider = LinkBehaviorContext.Provider; | ||
|
|
||
| export const useLinkBehavior = (props: LinkProps) => { | ||
| const {component, behavior} = useContext(LinkBehaviorContext); | ||
|
|
||
| return {Component: component, behavior: () => behavior(props)}; | ||
| }; |
This file contains hidden or 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 hidden or 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 hidden or 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,10 @@ | ||
| import {SentryLinkBehaviorProvider} from './link'; | ||
| import {SentryTrackingProvider} from './tracking'; | ||
|
|
||
| export function ScrapsProviders({children}: {children: React.ReactNode}) { | ||
| return ( | ||
| <SentryTrackingProvider> | ||
| <SentryLinkBehaviorProvider>{children}</SentryLinkBehaviorProvider> | ||
| </SentryTrackingProvider> | ||
| ); | ||
| } |
This file contains hidden or 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,34 @@ | ||
| import {useMemo} from 'react'; | ||
| import {Link as RouterLink} from 'react-router-dom'; | ||
|
|
||
| import type {LinkProps} from '@sentry/scraps/link'; | ||
| import {LinkBehaviorContextProvider} from '@sentry/scraps/link/linkBehaviorContext'; | ||
|
|
||
| import {locationDescriptorToTo} from 'sentry/utils/reactRouter6Compat/location'; | ||
| import normalizeUrl from 'sentry/utils/url/normalizeUrl'; | ||
| import {useLocation} from 'sentry/utils/useLocation'; | ||
|
|
||
| export function SentryLinkBehaviorProvider({children}: {children: React.ReactNode}) { | ||
| const location = useLocation(); | ||
|
|
||
| return ( | ||
| <LinkBehaviorContextProvider | ||
| value={useMemo( | ||
| () => ({ | ||
| component: RouterLink, | ||
| behavior: ({to, ...props}: LinkProps) => { | ||
| const normalizedTo = locationDescriptorToTo(normalizeUrl(to, location)); | ||
|
|
||
| return { | ||
| to: normalizedTo, | ||
| ...props, | ||
| }; | ||
| }, | ||
| }), | ||
| [location] | ||
| )} | ||
| > | ||
| {children} | ||
| </LinkBehaviorContextProvider> | ||
| ); | ||
| } |
File renamed without changes.
This file contains hidden or 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 hidden or 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,5 @@ | ||
| import {SentryLinkBehaviorProvider} from 'sentry/scrapsProviders/link'; | ||
|
|
||
| export function ScrapsTestingProviders({children}: {children: React.ReactNode}) { | ||
| return <SentryLinkBehaviorProvider>{children}</SentryLinkBehaviorProvider>; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@evanpurkhiser do you maybe know why we have this “fall back to
<a>if there is no router present. When would that trigger? DoesuseLocationever return null / undefined?I would honestly love to just remove that if possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this actually dies at runtime so why do we have it 😅 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is probably pretty legacy. This might have been needed at one point for one of these things
sentry/static/app/bootstrap/processInitQueue.tsx
Lines 22 to 37 in 4ffd2a0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubt we need this yeah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, I think this is what we want then: f1625c5
the design-system uses
’a’per default unless specified by the context, which both the sentry app and our tests are doing.