From 6076567b88fba75ed0627020fd579ff30f78b049 Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Wed, 17 Jul 2024 20:51:12 +0530 Subject: [PATCH 1/6] errorBoundary Component Signed-off-by: aayushdhiman01 --- .../sistent/components/error-boundary/code.js | 9 + .../components/error-boundary/index.js | 9 + .../error-boundary/ErrorBoundary.tsx | 106 ++++++++++ .../components/error-boundary/README.md | 85 ++++++++ .../Sistent/components/error-boundary/code.js | 189 ++++++++++++++++++ .../components/error-boundary/index.js | 159 +++++++++++++++ .../components/error-boundary/index.tsx | 6 + .../Projects/Sistent/components/index.js | 7 + 8 files changed, 570 insertions(+) create mode 100644 src/pages/projects/sistent/components/error-boundary/code.js create mode 100644 src/pages/projects/sistent/components/error-boundary/index.js create mode 100644 src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx create mode 100644 src/sections/Projects/Sistent/components/error-boundary/README.md create mode 100644 src/sections/Projects/Sistent/components/error-boundary/code.js create mode 100644 src/sections/Projects/Sistent/components/error-boundary/index.js create mode 100644 src/sections/Projects/Sistent/components/error-boundary/index.tsx diff --git a/src/pages/projects/sistent/components/error-boundary/code.js b/src/pages/projects/sistent/components/error-boundary/code.js new file mode 100644 index 000000000000..d23feaa4e6ac --- /dev/null +++ b/src/pages/projects/sistent/components/error-boundary/code.js @@ -0,0 +1,9 @@ +import React from "react"; +import ErrorBoundaryCode from "../../../../../sections/Projects/Sistent/components/error-boundary/code"; + + +const ErrorBoundaryCodePage = () => { + return ; +}; + +export default ErrorBoundaryCodePage; \ No newline at end of file diff --git a/src/pages/projects/sistent/components/error-boundary/index.js b/src/pages/projects/sistent/components/error-boundary/index.js new file mode 100644 index 000000000000..1f44e05b6b61 --- /dev/null +++ b/src/pages/projects/sistent/components/error-boundary/index.js @@ -0,0 +1,9 @@ +import React from "react"; +import SistentErrorBoundary from "../../../../../sections/Projects/Sistent/components/error-boundary"; + + +const SistentErrorBoundaryPage = () => { + return ; +}; + +export default SistentErrorBoundaryPage; \ No newline at end of file diff --git a/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx b/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx new file mode 100644 index 000000000000..5134530702d1 --- /dev/null +++ b/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx @@ -0,0 +1,106 @@ +import { styled } from '@mui/material'; +import React from 'react'; +import { FallbackProps, ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'; +import { Box } from '../../base/Box'; +import { Link } from '../../base/Link'; +import { Typography } from '../../base/Typography'; + +const ErrorMessage = styled(Typography)(({ theme }) => ({ + color: theme.palette.text.default, + fontWeight: 'normal', + marginTop: '2px', + marginBottom: '2px', + fontSize: '1.15rem' +})); + +const StyledLink = styled(Link)(({ theme }) => ({ + color: theme.palette.border.brand, + textDecoration: 'underline', + cursor: 'pointer' +})); + +const CodeMessage = styled('div')(({ theme }) => ({ + backgroundColor: theme.palette.background.code, + color: theme.palette.text.tertiary, + padding: '.85rem', + borderRadius: '.2rem', + marginBlock: '.5rem' +})); + +interface FallbackComponentProps extends FallbackProps { + resetErrorBoundary: () => void; + children?: React.ReactNode; +} + +export function Fallback({ error, children }: FallbackComponentProps): JSX.Element { + return ( +
+

Uh-oh!😔 Please pardon the mesh.

+ + {(error as Error).message} + + + We apologize for the inconvenience. The issue may be on our end. If troubleshooting doesn't + work, please check out our support channels{' '} + + Discuss Forum + {' '} + {' or '} + + Slack + + + {children} +
+ ); +} + +const reportError = (error: Error, info: React.ErrorInfo): void => { + // This is where you'd send the error to Sentry, etc + console.log('Error Caught Inside Boundary --reportError', error, 'Info', info); +}; + +interface ErrorBoundaryProps { + customFallback?: React.ComponentType; + children: React.ReactNode; +} + +export const ErrorBoundary: React.FC = ({ customFallback, children }) => { + return ( + + {children} + + ); +}; + +interface WithErrorBoundaryProps { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Component: React.ComponentType; + errorHandlingProps?: ErrorBoundaryProps; +} + +export const withErrorBoundary: React.FC = ({ + Component, + errorHandlingProps = { children: null } +}: WithErrorBoundaryProps): JSX.Element => { + return ( + + + + ); +}; + +interface WithSuppressedErrorBoundaryProps { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + Component: React.ComponentType; +} + +export const withSuppressedErrorBoundary: React.FC = ({ + Component +}: WithSuppressedErrorBoundaryProps): JSX.Element => { + return ( + null} onError={reportError}> + + + ); +}; diff --git a/src/sections/Projects/Sistent/components/error-boundary/README.md b/src/sections/Projects/Sistent/components/error-boundary/README.md new file mode 100644 index 000000000000..0fed30e1b48d --- /dev/null +++ b/src/sections/Projects/Sistent/components/error-boundary/README.md @@ -0,0 +1,85 @@ +## Error Boundary Components + +### `ErrorBoundary` + +The `ErrorBoundary` component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs. + +#### Usage + +Wrap your component with the `ErrorBoundary`: + +```tsx +import { ErrorBoundary } from '@layer5/sistent'; + +const MyComponent = () => { + // Your component logic + + return {/* Your component JSX */}; +}; +``` + +##### Custom Fallback + +You can provide a custom fallback component to `ErrorBoundary`: + +```tsx +const MyComponent = () => { + // Your component logic + + return ( + + {/* Your component JSX */} + + ); +}; +``` + +### `withErrorBoundary` + +`withErrorBoundary` is a higher-order component (HOC) that simplifies wrapping a component with ErrorBoundary. It uses default fallback component. This can be useFul to wrap child components + +#### Usage + +Wrap your component using `withErrorBoundary`: + +```tsx +import { withErrorBoundary } from '@layer5/sistent'; + +const MyComponent = withErrorBoundary(() => { + return { + /* Your component JSX */ + }; +}); +``` + +### `withSuppressedErrorBoundary` + +`withSuppressedErrorBoundary` is another HOC that suppresses the error in browser's console instead of displaying fallback component to users, this can be useFull for errors that are not critical and can be avoided. + +#### Usage + +Wrap your component using withSuppressedErrorBoundary: + +```tsx +import { withSuppressedErrorBoundary } from '@layer5/sistent'; + +const MyComponent = withSuppressedErrorBoundary(() => { + return { + /* Your component JSX */ + }; +}); +``` + +### Handling Different Levels of Errors + +#### Critical Errors + +Critical errors typically originate from parent or root components and can potentially lead to the entire page crashing. In such cases, it is recommended to use the ErrorBoundary with either the default fallback component or a custom fallback component to ensure users receive assistance. + +#### Non-critical Errors + +Non-critical errors occur in child components and may not result in a page crash or hinder users from performing other operations. In these cases, displaying the error through a toaster notification or handling it as an event can be beneficial. + +#### Errors That Can Be Avoided + +In some scenarios, a child component might encounter an error that doesn't block users and doesn't require immediate attention. Such errors can be avoided and suppressed into the browser's console for debugging purposes. The `withSuppressedErrorBoundary` higher-order component (HOC) function can be useful in this scenario. diff --git a/src/sections/Projects/Sistent/components/error-boundary/code.js b/src/sections/Projects/Sistent/components/error-boundary/code.js new file mode 100644 index 000000000000..5a6c53b09301 --- /dev/null +++ b/src/sections/Projects/Sistent/components/error-boundary/code.js @@ -0,0 +1,189 @@ +import React from "react"; +import { SistentLayout } from "../../sistent-layout"; +import { useState } from "react"; +import { + Box, + Button, + SistentThemeProvider, + ErrorBoundary, + Fallback, + withErrorBoundary, + withSuppressedErrorBoundary, + TextField, + Typography, +} from "@layer5/sistent"; +import TabButton from "../../../../../reusecore/Button"; +import { useLocation } from "@reach/router"; +import { navigate } from "gatsby"; +import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; +import { CodeBlock } from "../button/code-block"; +import { ActionBox } from "../../sistent.style"; + +const CustomInput = ({ label, text, style }) => ( + + + {label} + + + +); + +const codes = [ + `import { withErrorBoundary } from '@layer5/sistent'; + const MyComponent = () => { + // Your component logic + + return {/* Your component JSX */}; + };`, + `const MyComponent = () => { + // Your component logic + + return ( + + {/* Your component JSX */} + + ); + };`, + `import { withErrorBoundary } from '@layer5/sistent'; + const MyComponent = withErrorBoundary(() => { + return { + /* Your component JSX */ + }; + });`, + `import { withSuppressedErrorBoundary } from '@layer5/sistent'; + const MyComponent = withSuppressedErrorBoundary(() => { + return { + /* Your component JSX */ + }; + });` +]; + +export const ErrorBoundaryCode = () => { + const [open, setOpen] = useState(false); + const [actionOpen, setActionOpen] = useState(false); + const location = useLocation(); + const { isDark } = useStyledDarkMode(); + + const handleOpen = () => { + setOpen(true); + }; + + const handleClose = () => { + setOpen(false); + }; + + const handleActionOpen = () => { + setActionOpen(true); + }; + + const handleActionClose = () => { + setActionOpen(false); + }; + + return ( + +
+ +

ErrorBoundary

+
+

+ The ErrorBoundary component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs. +

+
+ navigate("/projects/sistent/components/error-boundary")} + title="Overview" + /> + {/* + navigate("/projects/sistent/components/modal/guidance") + } + title="Guidance" + /> */} + navigate("/projects/sistent/identity/color/code")} + title="Code" + /> +
+
+ + +

ErrorBoundary

+
+

Wrap your component with the ErrorBoundary:

+
+
+ +
+ +
+ +

Custom Fallback

+
+

You can provide a custom fallback component to ErrorBoundary:

+
+
+ +
+ +
+ +

withErrorBoundary

+
+

It is a higher-order component (HOC) that simplifies wrapping a component with ErrorBoundary. It uses default fallback component. This can be useFul to wrap child components.

+

Wrap your component using withErrorBoundary:

+
+
+ +
+ +
+ +

withSuppressedErrorBoundary

+
+

withSuppressedErrorBoundary is another HOC that suppresses the error in browser's console instead of displaying fallback component to users, this can be useFull for errors that are not critical and can be avoided.

+

Wrap your component using withSuppressedErrorBoundary:

+
+
+ +
+ +
+
+
+
+
+ ); +}; + +export default ErrorBoundaryCode; diff --git a/src/sections/Projects/Sistent/components/error-boundary/index.js b/src/sections/Projects/Sistent/components/error-boundary/index.js new file mode 100644 index 000000000000..df588f0c550c --- /dev/null +++ b/src/sections/Projects/Sistent/components/error-boundary/index.js @@ -0,0 +1,159 @@ +import React from "react"; +import { navigate } from "gatsby"; +import { useLocation } from "@reach/router"; + +import { SistentThemeProvider, Button } from "@layer5/sistent"; +import TabButton from "../../../../../reusecore/Button"; +import { SistentLayout } from "../../sistent-layout"; +import { Col, Row } from "../../../../../reusecore/Layout"; +import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; + +const SistentErrorBoundary = () => { + const location = useLocation(); + const { isDark } = useStyledDarkMode(); + + return ( + +
+ +

Error Boundary

+
+

+ The ErrorBoundary component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs. +

+
+ navigate("/projects/sistent/components/error-boundary")} + title="Overview" + /> + navigate("/projects/sistent/components/error-boundary/code")} + title="Code" + /> +
+
+ +

Error Boundary Components

+
+

ErrorBoundary

+

+ The ErrorBoundary component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs. +

+
Usage
+

Outlined

+

+ Outlined buttons are buttons that do not have a fill, but have a + border or stroke to define its bounding box as well as a text label + to convey a thought for users to take action upon. Colors can also + be used to style these buttons in order to fit into the theme align + with brand guidelines. +

+ + +
+
+
+ ); +}; + +export default SistentErrorBoundary; diff --git a/src/sections/Projects/Sistent/components/error-boundary/index.tsx b/src/sections/Projects/Sistent/components/error-boundary/index.tsx new file mode 100644 index 000000000000..f4b09c8c0aa5 --- /dev/null +++ b/src/sections/Projects/Sistent/components/error-boundary/index.tsx @@ -0,0 +1,6 @@ +export { + ErrorBoundary, + Fallback, + withErrorBoundary, + withSuppressedErrorBoundary +} from './ErrorBoundary'; diff --git a/src/sections/Projects/Sistent/components/index.js b/src/sections/Projects/Sistent/components/index.js index ce9cb2768f06..6792f53df0aa 100644 --- a/src/sections/Projects/Sistent/components/index.js +++ b/src/sections/Projects/Sistent/components/index.js @@ -29,6 +29,13 @@ const componentsData = [ "A text input is made up of multiple elements that combine to form a component that helps users to read, write, and edit text in an interface.", url: "/projects/sistent/components/modal", }, + { + id: 4, + name: "Error Boundary", + description: + "The ErrorBoundary component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs.", + url: "/projects/sistent/components/error-boundary" + } ]; const SistentComponents = () => { From 8d8c2936b71e65d50d9615270b922fe236982840 Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Wed, 17 Jul 2024 20:55:12 +0530 Subject: [PATCH 2/6] added errorBoundaryComponent --- .../Sistent/components/error-boundary/code.js | 2 +- .../components/error-boundary/index.js | 103 +----------------- 2 files changed, 3 insertions(+), 102 deletions(-) diff --git a/src/sections/Projects/Sistent/components/error-boundary/code.js b/src/sections/Projects/Sistent/components/error-boundary/code.js index 5a6c53b09301..3bc4af764e1c 100644 --- a/src/sections/Projects/Sistent/components/error-boundary/code.js +++ b/src/sections/Projects/Sistent/components/error-boundary/code.js @@ -149,7 +149,7 @@ export const ErrorBoundaryCode = () => {
+
diff --git a/src/sections/Projects/Sistent/components/error-boundary/index.js b/src/sections/Projects/Sistent/components/error-boundary/index.js index df588f0c550c..87b1b7feda84 100644 --- a/src/sections/Projects/Sistent/components/error-boundary/index.js +++ b/src/sections/Projects/Sistent/components/error-boundary/index.js @@ -41,7 +41,7 @@ const SistentErrorBoundary = () => { title="Code" /> -
+

Error Boundary Components

@@ -50,106 +50,7 @@ const SistentErrorBoundary = () => { The ErrorBoundary component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs.

Usage
-

Outlined

-

- Outlined buttons are buttons that do not have a fill, but have a - border or stroke to define its bounding box as well as a text label - to convey a thought for users to take action upon. Colors can also - be used to style these buttons in order to fit into the theme align - with brand guidelines. -

- - -
From cb84d8615e157af66fb3a7d9a49282f625481340 Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Sat, 20 Jul 2024 17:01:09 +0530 Subject: [PATCH 3/6] removed action box --- .../error-boundary/ErrorBoundary.tsx | 106 ------------------ .../components/error-boundary/README.md | 85 -------------- .../Sistent/components/error-boundary/code.js | 27 ----- .../components/error-boundary/index.tsx | 6 - 4 files changed, 224 deletions(-) delete mode 100644 src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx delete mode 100644 src/sections/Projects/Sistent/components/error-boundary/README.md delete mode 100644 src/sections/Projects/Sistent/components/error-boundary/index.tsx diff --git a/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx b/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx deleted file mode 100644 index 5134530702d1..000000000000 --- a/src/sections/Projects/Sistent/components/error-boundary/ErrorBoundary.tsx +++ /dev/null @@ -1,106 +0,0 @@ -import { styled } from '@mui/material'; -import React from 'react'; -import { FallbackProps, ErrorBoundary as ReactErrorBoundary } from 'react-error-boundary'; -import { Box } from '../../base/Box'; -import { Link } from '../../base/Link'; -import { Typography } from '../../base/Typography'; - -const ErrorMessage = styled(Typography)(({ theme }) => ({ - color: theme.palette.text.default, - fontWeight: 'normal', - marginTop: '2px', - marginBottom: '2px', - fontSize: '1.15rem' -})); - -const StyledLink = styled(Link)(({ theme }) => ({ - color: theme.palette.border.brand, - textDecoration: 'underline', - cursor: 'pointer' -})); - -const CodeMessage = styled('div')(({ theme }) => ({ - backgroundColor: theme.palette.background.code, - color: theme.palette.text.tertiary, - padding: '.85rem', - borderRadius: '.2rem', - marginBlock: '.5rem' -})); - -interface FallbackComponentProps extends FallbackProps { - resetErrorBoundary: () => void; - children?: React.ReactNode; -} - -export function Fallback({ error, children }: FallbackComponentProps): JSX.Element { - return ( -
-

Uh-oh!😔 Please pardon the mesh.

- - {(error as Error).message} - - - We apologize for the inconvenience. The issue may be on our end. If troubleshooting doesn't - work, please check out our support channels{' '} - - Discuss Forum - {' '} - {' or '} - - Slack - - - {children} -
- ); -} - -const reportError = (error: Error, info: React.ErrorInfo): void => { - // This is where you'd send the error to Sentry, etc - console.log('Error Caught Inside Boundary --reportError', error, 'Info', info); -}; - -interface ErrorBoundaryProps { - customFallback?: React.ComponentType; - children: React.ReactNode; -} - -export const ErrorBoundary: React.FC = ({ customFallback, children }) => { - return ( - - {children} - - ); -}; - -interface WithErrorBoundaryProps { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - Component: React.ComponentType; - errorHandlingProps?: ErrorBoundaryProps; -} - -export const withErrorBoundary: React.FC = ({ - Component, - errorHandlingProps = { children: null } -}: WithErrorBoundaryProps): JSX.Element => { - return ( - - - - ); -}; - -interface WithSuppressedErrorBoundaryProps { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - Component: React.ComponentType; -} - -export const withSuppressedErrorBoundary: React.FC = ({ - Component -}: WithSuppressedErrorBoundaryProps): JSX.Element => { - return ( - null} onError={reportError}> - - - ); -}; diff --git a/src/sections/Projects/Sistent/components/error-boundary/README.md b/src/sections/Projects/Sistent/components/error-boundary/README.md deleted file mode 100644 index 0fed30e1b48d..000000000000 --- a/src/sections/Projects/Sistent/components/error-boundary/README.md +++ /dev/null @@ -1,85 +0,0 @@ -## Error Boundary Components - -### `ErrorBoundary` - -The `ErrorBoundary` component is designed to catch errors that occur within its child components and provide a customizable fallback UI when an error occurs. - -#### Usage - -Wrap your component with the `ErrorBoundary`: - -```tsx -import { ErrorBoundary } from '@layer5/sistent'; - -const MyComponent = () => { - // Your component logic - - return {/* Your component JSX */}; -}; -``` - -##### Custom Fallback - -You can provide a custom fallback component to `ErrorBoundary`: - -```tsx -const MyComponent = () => { - // Your component logic - - return ( - - {/* Your component JSX */} - - ); -}; -``` - -### `withErrorBoundary` - -`withErrorBoundary` is a higher-order component (HOC) that simplifies wrapping a component with ErrorBoundary. It uses default fallback component. This can be useFul to wrap child components - -#### Usage - -Wrap your component using `withErrorBoundary`: - -```tsx -import { withErrorBoundary } from '@layer5/sistent'; - -const MyComponent = withErrorBoundary(() => { - return { - /* Your component JSX */ - }; -}); -``` - -### `withSuppressedErrorBoundary` - -`withSuppressedErrorBoundary` is another HOC that suppresses the error in browser's console instead of displaying fallback component to users, this can be useFull for errors that are not critical and can be avoided. - -#### Usage - -Wrap your component using withSuppressedErrorBoundary: - -```tsx -import { withSuppressedErrorBoundary } from '@layer5/sistent'; - -const MyComponent = withSuppressedErrorBoundary(() => { - return { - /* Your component JSX */ - }; -}); -``` - -### Handling Different Levels of Errors - -#### Critical Errors - -Critical errors typically originate from parent or root components and can potentially lead to the entire page crashing. In such cases, it is recommended to use the ErrorBoundary with either the default fallback component or a custom fallback component to ensure users receive assistance. - -#### Non-critical Errors - -Non-critical errors occur in child components and may not result in a page crash or hinder users from performing other operations. In these cases, displaying the error through a toaster notification or handling it as an event can be beneficial. - -#### Errors That Can Be Avoided - -In some scenarios, a child component might encounter an error that doesn't block users and doesn't require immediate attention. Such errors can be avoided and suppressed into the browser's console for debugging purposes. The `withSuppressedErrorBoundary` higher-order component (HOC) function can be useful in this scenario. diff --git a/src/sections/Projects/Sistent/components/error-boundary/code.js b/src/sections/Projects/Sistent/components/error-boundary/code.js index 3bc4af764e1c..281eb19085bf 100644 --- a/src/sections/Projects/Sistent/components/error-boundary/code.js +++ b/src/sections/Projects/Sistent/components/error-boundary/code.js @@ -17,22 +17,7 @@ import { useLocation } from "@reach/router"; import { navigate } from "gatsby"; import { useStyledDarkMode } from "../../../../../theme/app/useStyledDarkMode"; import { CodeBlock } from "../button/code-block"; -import { ActionBox } from "../../sistent.style"; -const CustomInput = ({ label, text, style }) => ( - - - {label} - - - -); const codes = [ `import { withErrorBoundary } from '@layer5/sistent'; @@ -74,18 +59,6 @@ export const ErrorBoundaryCode = () => { setOpen(true); }; - const handleClose = () => { - setOpen(false); - }; - - const handleActionOpen = () => { - setActionOpen(true); - }; - - const handleActionClose = () => { - setActionOpen(false); - }; - return (
diff --git a/src/sections/Projects/Sistent/components/error-boundary/index.tsx b/src/sections/Projects/Sistent/components/error-boundary/index.tsx deleted file mode 100644 index f4b09c8c0aa5..000000000000 --- a/src/sections/Projects/Sistent/components/error-boundary/index.tsx +++ /dev/null @@ -1,6 +0,0 @@ -export { - ErrorBoundary, - Fallback, - withErrorBoundary, - withSuppressedErrorBoundary -} from './ErrorBoundary'; From 4aa6644679a90d739702449b0104a026cb5f1f6f Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Mon, 22 Jul 2024 13:16:52 +0530 Subject: [PATCH 4/6] added error boundary code --- .../Sistent/components/error-boundary/code.js | 64 +++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/src/sections/Projects/Sistent/components/error-boundary/code.js b/src/sections/Projects/Sistent/components/error-boundary/code.js index 281eb19085bf..3a02628a29af 100644 --- a/src/sections/Projects/Sistent/components/error-boundary/code.js +++ b/src/sections/Projects/Sistent/components/error-boundary/code.js @@ -2,14 +2,12 @@ import React from "react"; import { SistentLayout } from "../../sistent-layout"; import { useState } from "react"; import { - Box, Button, SistentThemeProvider, ErrorBoundary, Fallback, withErrorBoundary, withSuppressedErrorBoundary, - TextField, Typography, } from "@layer5/sistent"; import TabButton from "../../../../../reusecore/Button"; @@ -20,7 +18,7 @@ import { CodeBlock } from "../button/code-block"; const codes = [ - `import { withErrorBoundary } from '@layer5/sistent'; + `import { ErrorBoundary } from '@layer5/sistent'; const MyComponent = () => { // Your component logic @@ -49,16 +47,37 @@ const codes = [ });` ]; +function trigerError(){ + throw new Error("This is a deliberate error!"); +} + +const ErrorThrowingComponent = () => { + const triggerError = () => { + throw new Error("This is a deliberate error!"); + }; + + return ( +
+ +
+ ); +}; + +const CustomFallbackComponent = () => { + return ( +
+

Custom Fallback Component

+
+ ); +}; + + export const ErrorBoundaryCode = () => { - const [open, setOpen] = useState(false); - const [actionOpen, setActionOpen] = useState(false); const location = useLocation(); const { isDark } = useStyledDarkMode(); - const handleOpen = () => { - setOpen(true); - }; - return (
@@ -108,9 +127,15 @@ export const ErrorBoundaryCode = () => {

Wrap your component with the ErrorBoundary:

- + {/* { + + } */} + + + + {/* */}
@@ -120,9 +145,11 @@ export const ErrorBoundaryCode = () => {

You can provide a custom fallback component to ErrorBoundary:

- + { + + }
@@ -133,9 +160,8 @@ export const ErrorBoundaryCode = () => {

Wrap your component using withErrorBoundary:

- + {/* */} +
@@ -146,7 +172,7 @@ export const ErrorBoundaryCode = () => {

Wrap your component using withSuppressedErrorBoundary:

-
From b8e865f09cf575b832abb66d31f200b3174973c5 Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Mon, 22 Jul 2024 23:16:38 +0530 Subject: [PATCH 5/6] showing errorBoundaryComponent --- .../Sistent/components/error-boundary/code.js | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/sections/Projects/Sistent/components/error-boundary/code.js b/src/sections/Projects/Sistent/components/error-boundary/code.js index 3a02628a29af..e58687f0ba1d 100644 --- a/src/sections/Projects/Sistent/components/error-boundary/code.js +++ b/src/sections/Projects/Sistent/components/error-boundary/code.js @@ -5,10 +5,8 @@ import { Button, SistentThemeProvider, ErrorBoundary, - Fallback, withErrorBoundary, withSuppressedErrorBoundary, - Typography, } from "@layer5/sistent"; import TabButton from "../../../../../reusecore/Button"; import { useLocation } from "@reach/router"; @@ -47,15 +45,20 @@ const codes = [ });` ]; -function trigerError(){ - throw new Error("This is a deliberate error!"); +function MyComponent() { + // Simulate an error for demonstration purposes + if (Math.random() > 0.5) { + throw new Error("An error occurred in MyComponent"); + } + + // Component logic here + return
This is MyComponent
; } const ErrorThrowingComponent = () => { const triggerError = () => { throw new Error("This is a deliberate error!"); }; - return (
- } */} - + - {/* */}
@@ -145,11 +143,9 @@ export const ErrorBoundaryCode = () => {

You can provide a custom fallback component to ErrorBoundary:

- { - - } + + +
@@ -160,8 +156,7 @@ export const ErrorBoundaryCode = () => {

Wrap your component using withErrorBoundary:

- {/* */} - + {/* */}
@@ -172,9 +167,9 @@ export const ErrorBoundaryCode = () => {

Wrap your component using withSuppressedErrorBoundary:

- + */}
From 6ea6b70026aa8437a3363d9d73d11e3f6b187d1b Mon Sep 17 00:00:00 2001 From: aayushdhiman01 Date: Mon, 22 Jul 2024 23:43:16 +0530 Subject: [PATCH 6/6] fix-indent --- src/sections/Projects/Sistent/components/button/code-block.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sections/Projects/Sistent/components/button/code-block.js b/src/sections/Projects/Sistent/components/button/code-block.js index e3831a70b6b0..b3e4945c40e5 100644 --- a/src/sections/Projects/Sistent/components/button/code-block.js +++ b/src/sections/Projects/Sistent/components/button/code-block.js @@ -11,7 +11,7 @@ export const CodeBlock = ({ name, code }) => { - {showCode && ( + {showCode && ( )}