Skip to content
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

Merged
merged 1 commit into from
Mar 11, 2024

Conversation

erfanmoghadasi
Copy link
Collaborator

@erfanmoghadasi erfanmoghadasi commented Mar 11, 2024

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

  • New Features
    • Introduced dynamic form field and action rendering based on groupList data structure.
    • Added ActionBase and ActionSubmit components for enhanced form submission handling.
  • Enhancements
    • Updated form components to support new field types field-text and action-submit.
    • Improved dynamic component loading in the Selector component for different field types.
  • Refactor
    • Updated various import paths and type usages across form components to align with new naming conventions and data structures.

@erfanmoghadasi erfanmoghadasi linked an issue Mar 11, 2024 that may be closed by this pull request
Copy link

coderabbitai bot commented Mar 11, 2024

Walkthrough

The overall changes revolve around enhancing form functionality within a React application. This includes dynamic rendering of form fields and actions via a groupList, introduction of base and submit action components utilizing Material-UI, and updates to type definitions to support these changes. The adjustments ensure better modularity, ease of maintenance, and extendibility of form components.

Changes

Files Summary
apps/docs/src/app/app.tsx Updated to use groupList for dynamic form field rendering.
packages/components/form/src/components/actions/base/...
packages/components/form/src/components/actions/submit/...
Introduced ActionBase and ActionSubmit components with type definitions.
packages/components/form/src/components/builder/...
packages/core/src/lib/components/builder/...
Updated type definitions and imports for better modularity.
packages/components/form/src/components/fields/text/... Corrected import paths and updated type definitions.
packages/components/form/src/types/...
packages/components/form/src/utils/selector/...
packages/core/src/lib/utils/selector/...
Redefined FormTypes and updated functionality to support dynamic field type loading.

🐰✨
In the realm of code, where forms take shape,
A rabbit hopped, leaving no escape.
With dynamic fields and buttons that load,
It crafted a path, a new abode.
Through the garden of React it danced,
Ensuring every form had a chance.
🌼📝🚀

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?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@mrbadri mrbadri merged commit d724f15 into main Mar 11, 2024
1 check failed
Copy link

@coderabbitai coderabbitai bot left a 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

Commits Files that changed from the base of the PR and between 4ec8c29 and 065f0b1.
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 of FIELD_TYPE. This change aligns with the PR's objective to refactor and rename for clarity.
  • 4-4: The fieldType in BuilderProps has been updated from FIELD_TYPE to FormTypes. This change is consistent with the renaming effort and ensures type safety with the new FormTypes.
packages/components/form/src/utils/selector/selector.types.ts (2)
  • 1-1: The import statement has been updated to use FormTypes instead of FIELD_TYPE. This change is part of the refactoring effort to improve naming conventions and clarity.
  • 4-4: The fieldType in SelectorProps has been updated from FIELD_TYPE to FormTypes. This update is consistent with the renaming effort and enhances type safety with the new FormTypes.
packages/components/form/src/components/actions/base/actionBase.types.ts (1)
  • 4-6: The introduction of ActionBaseProps type is well-defined, extending LoadingButtonProps from Material-UI and including a children prop of type ReactNode. 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, extending ActionBaseProps and including FormId, 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, utilizing LoadingButton from Material-UI and spreading actionBaseProps 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 accept ActionSubmitFieldProps in addition to TextProps 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 in IFormTextBuilderProps from FIELD_TYPE to FormTypes is consistent with the renaming effort and enhances type safety with the new FormTypes. 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 of FIELD_TYPE and adjusting the corresponding usage in the SelectorProps 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 and action-submit) is a significant enhancement. This change allows for more flexible and scalable form configurations. The use of lazy for component loading and Suspense 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 the groupList prop for dynamic rendering is correctly implemented.

},
},
{
id: '4',
Copy link

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.

Comment on lines +7 to +22
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>
);
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Handle action in @mui-builder/form (submit)
2 participants