-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat(form): actions (submit & base button) in form (#5) #6
Conversation
WalkthroughThe overall changes revolve around enhancing form functionality within a React application. This includes dynamic rendering of form fields and actions via a Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Review Status
Actionable comments generated: 2
Configuration used: CodeRabbit UI
Files ignored due to path filters (2)
package-lock.json
is excluded by:!**/*.json
package.json
is excluded by:!**/*.json
Files selected for processing (13)
- apps/docs/src/app/app.tsx (2 hunks)
- packages/components/form/src/components/actions/base/actionBase.tsx (1 hunks)
- packages/components/form/src/components/actions/base/actionBase.types.ts (1 hunks)
- packages/components/form/src/components/actions/submit/submit.tsx (1 hunks)
- packages/components/form/src/components/actions/submit/submit.types.ts (1 hunks)
- packages/components/form/src/components/builder/builder.types.ts (1 hunks)
- packages/components/form/src/components/fields/text/text.tsx (2 hunks)
- packages/components/form/src/components/fields/text/text.types.ts (1 hunks)
- packages/components/form/src/types/public.types.ts (1 hunks)
- packages/components/form/src/utils/selector/selector.tsx (1 hunks)
- packages/components/form/src/utils/selector/selector.types.ts (1 hunks)
- packages/core/src/lib/components/builder/builder.tsx (2 hunks)
- packages/core/src/lib/utils/selector/selector.tsx (1 hunks)
Files skipped from review due to trivial changes (2)
- packages/components/form/src/components/fields/text/text.tsx
- packages/components/form/src/components/fields/text/text.types.ts
Additional comments: 14
packages/components/form/src/components/builder/builder.types.ts (2)
- 1-1: The import statement has been updated to include
FormTypes
instead ofFIELD_TYPE
. This change aligns with the PR's objective to refactor and rename for clarity.- 4-4: The
fieldType
inBuilderProps
has been updated fromFIELD_TYPE
toFormTypes
. This change is consistent with the renaming effort and ensures type safety with the newFormTypes
.packages/components/form/src/utils/selector/selector.types.ts (2)
- 1-1: The import statement has been updated to use
FormTypes
instead ofFIELD_TYPE
. This change is part of the refactoring effort to improve naming conventions and clarity.- 4-4: The
fieldType
inSelectorProps
has been updated fromFIELD_TYPE
toFormTypes
. This update is consistent with the renaming effort and enhances type safety with the newFormTypes
.packages/components/form/src/components/actions/base/actionBase.types.ts (1)
- 4-6: The introduction of
ActionBaseProps
type is well-defined, extendingLoadingButtonProps
from Material-UI and including achildren
prop of typeReactNode
. This type definition is clear and aligns with React component prop patterns.packages/components/form/src/components/actions/submit/submit.types.ts (1)
- 4-4: The introduction of
ActionSubmitFieldProps
type, extendingActionBaseProps
and includingFormId
, is well-defined. This type definition ensures that submit actions have access to form identification, which is crucial for form management.packages/components/form/src/components/actions/base/actionBase.tsx (1)
- 5-6: The
ActionBase
component is correctly implemented, utilizingLoadingButton
from Material-UI and spreadingactionBaseProps
to pass all necessary props. This implementation ensures that the component is flexible and can handle various loading states as defined by the props.packages/components/form/src/types/public.types.ts (2)
- 10-10: The introduction of
FormTypes
with values 'field-text' and "action-submit" is a significant improvement for type safety and clarity in form field management. This change supports the dynamic rendering capabilities introduced in the PR.- 12-12: Updating
FieldProps
to acceptActionSubmitFieldProps
in addition toTextProps
is a logical step to accommodate the new action components. This update ensures that the types are correctly aligned with the components they represent.packages/core/src/lib/components/builder/builder.tsx (2)
- 8-8: Converting
GROUP_TYPE
from an enum to a type with a single value'form'
simplifies the type structure and aligns with the current use case. This change is a good example of simplifying code without losing clarity or functionality.- 17-17: Updating the
type
property inIFormTextBuilderProps
fromFIELD_TYPE
toFormTypes
is consistent with the renaming effort and enhances type safety with the newFormTypes
. This change ensures that the builder component can handle the new form field types introduced in the PR.packages/core/src/lib/utils/selector/selector.tsx (1)
- 4-4: Updating the import to use
FormTypes
instead ofFIELD_TYPE
and adjusting the corresponding usage in theSelectorProps
interface is consistent with the renaming effort and enhances type safety. This change ensures that the selector component can dynamically load components based on the new form field types.packages/components/form/src/utils/selector/selector.tsx (1)
- 10-30: The update to the
Selector
component to support dynamic loading of components based on the field type (field-text
andaction-submit
) is a significant enhancement. This change allows for more flexible and scalable form configurations. The use oflazy
for component loading andSuspense
for fallback handling is correctly implemented, ensuring a smooth user experience during component loading.apps/docs/src/app/app.tsx (1)
- 79-79: The usage of the
Builder
component with thegroupList
prop for dynamic rendering is correctly implemented.
}, | ||
}, | ||
{ | ||
id: '4', |
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.
Duplicate id
value for the entry with id: '4'
. Each entry in the groupList
should have a unique id
to avoid potential rendering issues or unintended behavior.
const ActionSubmit: FC<ActionSubmitFieldProps> = ({ | ||
formId, | ||
children, | ||
...submitFieldProps | ||
}) => { | ||
const forms = useForms((state) => state.forms); | ||
const { handleSubmit } = forms[formId]; | ||
const onSubmit = (values: FieldValues) => { | ||
console.log(values); | ||
}; | ||
|
||
return ( | ||
<Button {...submitFieldProps} onClick={handleSubmit(onSubmit)}> | ||
{children} | ||
</Button> | ||
); |
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.
The ActionSubmit
component is well-implemented, utilizing the Button
component from Material-UI and the useForms
hook for form management. The use of handleSubmit
from the form's state to wrap the onSubmit
function ensures that form submission is handled correctly. However, consider handling the submission result or errors, as logging values to the console might not be sufficient for production use.
Consider enhancing the onSubmit
function to handle submission results or errors, providing feedback to the user or further processing the form data.
Closes #5
📝 Description
actions (submit & base button) in form
⛳️ Current behavior (updates)
🚀 New behavior
💣 Is this a breaking change (Yes/No):
📝 Additional Information
Summary by CodeRabbit
groupList
data structure.ActionBase
andActionSubmit
components for enhanced form submission handling.field-text
andaction-submit
.Selector
component for different field types.