generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #502 from Yashsharma1911/yash/updateErrorBoundaries
Enhance error boundaries
- Loading branch information
Showing
8 changed files
with
201 additions
and
14 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <ErrorBoundary>{/* Your component JSX */}</ErrorBoundary>; | ||
}; | ||
``` | ||
|
||
##### Custom Fallback | ||
|
||
You can provide a custom fallback component to `ErrorBoundary`: | ||
|
||
```tsx | ||
const MyComponent = () => { | ||
// Your component logic | ||
|
||
return ( | ||
<ErrorBoundary customFallback={CustomFallbackComponent}> | ||
{/* Your component JSX */} | ||
</ErrorBoundary> | ||
); | ||
}; | ||
``` | ||
|
||
### `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. |
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 |
---|---|---|
@@ -1 +1,6 @@ | ||
export { ErrorBoundary, WithErrorBoundary, withSuppressedErrorBoundary } from './ErrorBoundary'; | ||
export { | ||
ErrorBoundary, | ||
Fallback, | ||
withErrorBoundary, | ||
withSuppressedErrorBoundary | ||
} from './ErrorBoundary'; |
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 |
---|---|---|
@@ -1,4 +1,37 @@ | ||
import helpAndSupportModalSchema from './helpAndSupportModal/schema'; | ||
import helpAndSupportModalUiSchema from './helpAndSupportModal/uiSchema'; | ||
|
||
export { helpAndSupportModalSchema, helpAndSupportModalUiSchema }; | ||
import createAndEditEnvironmentSchema from './createAndEditEnvironment/schema'; | ||
import createAndEditEnvironmentUiSchema from './createAndEditEnvironment/uiSchema'; | ||
|
||
import createAndEditWorkspaceSchema from './createAndEditWorkspace/schema'; | ||
import createAndEditWorkspaceUiSchema from './createAndEditWorkspace/uiSchema'; | ||
|
||
import helmConnectionSchema from './helmConnection/schema'; | ||
import helmConnectionUiSchema from './helmConnection/uiSchema'; | ||
|
||
import importDesignSchema from './importDesign/schema'; | ||
import importDesignUiSchema from './importDesign/uiSchema'; | ||
|
||
import importFilterSchema from './importFilter/schema'; | ||
import importFilterUiSchema from './importFilter/uiSchema'; | ||
|
||
import publishCatalogItemSchema from './publishCatalogItem/schema'; | ||
import publishCatalogItemUiSchema from './publishCatalogItem/uiSchema'; | ||
|
||
export { | ||
createAndEditEnvironmentSchema, | ||
createAndEditEnvironmentUiSchema, | ||
createAndEditWorkspaceSchema, | ||
createAndEditWorkspaceUiSchema, | ||
helmConnectionSchema, | ||
helmConnectionUiSchema, | ||
helpAndSupportModalSchema, | ||
helpAndSupportModalUiSchema, | ||
importDesignSchema, | ||
importDesignUiSchema, | ||
importFilterSchema, | ||
importFilterUiSchema, | ||
publishCatalogItemSchema, | ||
publishCatalogItemUiSchema | ||
}; |
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,51 @@ | ||
# RJSF Schemas | ||
|
||
RJSF, or React JSON Schema Form, schemas play a crucial role in defining the structure and behavior of forms. These schemas, written in JSON format, provide a blueprint for rendering forms dynamically and handling user input effectively. | ||
|
||
### What are RJSF Schemas? | ||
|
||
RJSF Schemas, based on the React JSON Schema Form library, define the structure, validation rules, and UI elements of dynamic forms in a standardized way. They enable the creation of consistent and flexible forms across our applications. | ||
|
||
### How to Use RJSF Schemas | ||
|
||
1. **Importing Schemas:** | ||
Include the required schema in your React component by importing it. For example: | ||
|
||
```javascript | ||
import MyFormSchema from '@layer5/sistent'; | ||
``` | ||
|
||
1. **Rendering Forms:** | ||
Integrate the schema into your component to render the form dynamically. Use already created generic RJSF components or use RJSF Form component directly. | ||
|
||
```javascript | ||
import { sampleSchema, sampleUiSchema } from '@layer5/sistent'; | ||
<Form schema={sampleSchema} uiSchema={sampleUiSchema} onSubmit={handleFormSubmission} />; | ||
``` | ||
|
||
1. **Customization:** | ||
Adjust the schema properties to tailor the form's appearance and behavior. Refer to the specific schema's documentation for customization options. | ||
|
||
### File Conventions for Schemas | ||
|
||
Follow a consistent file structure convention to enhance clarity and organization when adding new schema: | ||
|
||
1. Use the same name as the schema for the directory. | ||
1. Use CamelCase for multi-word schema names, e.g., UserRegistrationFormSchema. | ||
1. Create two separate files, schema.tsx and uiSchema.tsx, to store both schemas separately. | ||
|
||
### Naming Conventions for Schemas | ||
|
||
Follow a consistent naming convention to enhance clarity and organization when adding new schema: | ||
|
||
1. Use descriptive names that convey the purpose of the form. | ||
1. CamelCase for multi-word schema names, e.g., UserRegistrationFormSchema. | ||
1. Include "Schema" in the name to explicitly indicate that it's a schema, e.g., ProfileSettingsSchema. | ||
1. Include "UiSchema" in the name to explicitly indicate that it's a UI schema, e.g., ProfileSettingsUiSchema. | ||
|
||
### Custom Properties | ||
|
||
In addition to the properties offered by the JSON schema, we have introduced the following custom properties that you can include in new schema: | ||
|
||
1. `x-rjsf-grid-area:` This property accepts an integer that defines the width of the field. For instance, specifying 6 means it will take up half of the parent width, while 12 signifies full width. | ||
1. `x-encode-in-uri:` When set to true, this property enables RJSF to encode data in URI format and return it. |