-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
feat: Filter panel improvements (#447)
Showing
7 changed files
with
244 additions
and
26 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,5 @@ | ||
--- | ||
'@hyperdx/app': patch | ||
--- | ||
|
||
Filter Panel improvements |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import type { Meta } from '@storybook/react'; | ||
|
||
import { ErrorBoundary } from './ErrorBoundary'; | ||
|
||
const meta: Meta = { | ||
title: 'ErrorBoundary', | ||
component: ErrorBoundary, | ||
}; | ||
|
||
const BadComponent = () => { | ||
throw new Error('Error message'); | ||
}; | ||
|
||
export const Default = () => ( | ||
<ErrorBoundary> | ||
<BadComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
export const WithRetry = () => ( | ||
<ErrorBoundary onRetry={() => {}}> | ||
<BadComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
export const WithMessage = () => ( | ||
<ErrorBoundary | ||
onRetry={() => {}} | ||
message="An error occurred while rendering the event details. Contact support | ||
for more help." | ||
> | ||
<BadComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
export const WithErrorMessage = () => ( | ||
<ErrorBoundary onRetry={() => {}} message="Don't panic" showErrorMessage> | ||
<BadComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
export default meta; |
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,59 @@ | ||
import React from 'react'; | ||
import { ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'; | ||
import { Alert, Button, Stack, Text } from '@mantine/core'; | ||
|
||
import { Icon } from './Icon'; | ||
|
||
type ErrorBoundaryProps = { | ||
children: React.ReactNode; | ||
message?: string; | ||
showErrorMessage?: boolean; | ||
allowReset?: boolean; | ||
onRetry?: () => void; | ||
}; | ||
|
||
/** | ||
* A `react-error-boundary` wrapper with a predefined fallback component | ||
*/ | ||
export const ErrorBoundary = ({ | ||
children, | ||
onRetry, | ||
allowReset, | ||
showErrorMessage, | ||
message, | ||
}: ErrorBoundaryProps) => { | ||
const showRetry = allowReset || !!onRetry; | ||
|
||
return ( | ||
<ReactErrorBoundary | ||
onError={error => { | ||
console.error(error); | ||
}} | ||
fallbackRender={({ error, resetErrorBoundary }) => ( | ||
<Alert | ||
p="xs" | ||
color="orange" | ||
icon={<Icon name="info-circle-fill" />} | ||
title={message || 'Something went wrong'} | ||
> | ||
{(showErrorMessage || showRetry) && ( | ||
<Stack align="flex-start" gap="xs"> | ||
{showErrorMessage && <Text size="xs">{error.message}</Text>} | ||
{showRetry && ( | ||
<Button | ||
onClick={onRetry || resetErrorBoundary} | ||
size="compact-xs" | ||
color="orange" | ||
> | ||
Retry | ||
</Button> | ||
)} | ||
</Stack> | ||
)} | ||
</Alert> | ||
)} | ||
> | ||
{children} | ||
</ReactErrorBoundary> | ||
); | ||
}; |
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