-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
feat(explore-attr-breakdowns): Adding error and empty search state UI #104012
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
Open
Abdkhan14
wants to merge
2
commits into
master
Choose a base branch
from
abdk/explore-attr-breakdowns-states
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+108
−34
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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 |
|---|---|---|
|
|
@@ -8,8 +8,10 @@ import {Flex} from '@sentry/scraps/layout/flex'; | |
| import BaseChart from 'sentry/components/charts/baseChart'; | ||
| import {Text} from 'sentry/components/core/text'; | ||
| import Placeholder from 'sentry/components/placeholder'; | ||
| import {IconSad, IconSearch, IconTimer} from 'sentry/icons'; | ||
| import {IconMegaphone} from 'sentry/icons/iconMegaphone'; | ||
| import {t} from 'sentry/locale'; | ||
| import {t, tct} from 'sentry/locale'; | ||
| import type RequestError from 'sentry/utils/requestError/requestError'; | ||
| import {useFeedbackForm} from 'sentry/utils/useFeedbackForm'; | ||
|
|
||
| function FeedbackButton() { | ||
|
|
@@ -106,7 +108,7 @@ function LoadingCharts() { | |
| }, []); | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap="xl"> | ||
| <Flex direction="column" gap="2xl"> | ||
| {showMessage && ( | ||
| <Text size="md" variant="muted"> | ||
| {t( | ||
|
|
@@ -123,6 +125,96 @@ function LoadingCharts() { | |
| ); | ||
| } | ||
|
|
||
| function FeedbackLink() { | ||
| const openForm = useFeedbackForm(); | ||
|
|
||
| if (!openForm) { | ||
| return ( | ||
| <a href="mailto:[email protected]?subject=Attribute%20breakdowns%20failed%20to%20load"> | ||
| {t('Send us feedback')} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| return ( | ||
| <a href="#" onClick={() => openForm?.()}> | ||
| {t('Send us feedback')} | ||
| </a> | ||
| ); | ||
| } | ||
|
|
||
| const StyledIconSearch = styled(IconSearch)` | ||
| color: ${p => p.theme.subText}; | ||
| `; | ||
|
|
||
| const StyledIconSad = styled(IconSad)` | ||
| color: ${p => p.theme.subText}; | ||
| `; | ||
|
|
||
| const StyledIconTimer = styled(IconTimer)` | ||
| color: ${p => p.theme.subText}; | ||
| `; | ||
|
|
||
| const ERROR_STATE_CONFIG: Record< | ||
| number | 'default', | ||
| { | ||
| icon: React.ReactNode; | ||
| subtitle: React.ReactNode; | ||
| title: string; | ||
| } | ||
| > = { | ||
| 504: { | ||
| title: t('Query timed out'), | ||
| icon: <StyledIconTimer size="xl" />, | ||
| subtitle: tct( | ||
| 'You can try narrowing the time range. Seeing this often? [feedbackLink]', | ||
| { | ||
| feedbackLink: <FeedbackLink />, | ||
| } | ||
| ), | ||
| }, | ||
| default: { | ||
| title: t('Failed to load attribute breakdowns'), | ||
| icon: <StyledIconSad size="xl" />, | ||
| subtitle: tct('Seeing this often? [feedbackLink]', { | ||
| feedbackLink: <FeedbackLink />, | ||
| }), | ||
| }, | ||
| }; | ||
|
|
||
| function ErrorState({error}: {error: RequestError}) { | ||
| const config = | ||
| ERROR_STATE_CONFIG[error?.status ?? 'default'] ?? ERROR_STATE_CONFIG.default; | ||
|
|
||
| return ( | ||
| <Flex direction="column" gap="2xl" padding="3xl" align="center" justify="center"> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There is also the |
||
| {config.icon} | ||
| <Text size="xl" variant="muted"> | ||
| {config.title} | ||
| </Text> | ||
| <Text size="md" variant="muted"> | ||
| {config.subtitle} | ||
| </Text> | ||
| </Flex> | ||
| ); | ||
| } | ||
|
|
||
| function EmptySearchState() { | ||
| return ( | ||
| <Flex direction="column" gap="2xl" padding="3xl" align="center" justify="center"> | ||
| <StyledIconSearch size="xl" /> | ||
| <Text size="xl" variant="muted"> | ||
| {t('No matching attributes found')} | ||
| </Text> | ||
| <Text size="md" variant="muted"> | ||
| {tct('Expecting results? [feedbackLink]', { | ||
| feedbackLink: <FeedbackLink />, | ||
| })} | ||
| </Text> | ||
| </Flex> | ||
| ); | ||
| } | ||
|
|
||
| const StyledPlaceholder = styled(Placeholder)<{_height: number; _width: number}>` | ||
| border-radius: ${p => p.theme.borderRadius}; | ||
| height: ${p => p._height}px; | ||
|
|
@@ -187,4 +279,6 @@ const StyledFeedbackButton = styled(Button)` | |
| export const AttributeBreakdownsComponent = { | ||
| FeedbackButton, | ||
| LoadingCharts, | ||
| ErrorState, | ||
| EmptySearchState, | ||
| }; | ||
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.
Bug: React hook called at module scope
The
ERROR_STATE_CONFIGobject is defined at module scope and includes JSX elements that renderFeedbackLinkcomponents. SinceFeedbackLinkcalls theuseFeedbackForm()hook, this violates React's rules of hooks by executing a hook outside of a component render cycle. This will cause a runtime error when the module loads. The config object needs to be moved inside theErrorStatecomponent or use a function that returns the config dynamically during render.