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): add merge form functionality #4495

Merged
merged 24 commits into from
Sep 25, 2024
Merged

Conversation

Squall2017
Copy link
Contributor

@Squall2017 Squall2017 commented Sep 24, 2024

Description

在某些场景下,例如分步表单,需要合并多个表单并统一提交。默认情况下,使用 Object.assign 规则合并表单数据,如果多个表单有相同字段等需求,可以传参自行处理数据。
也可以对合并方法进行扩展。

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Please, don't make changes to pnpm-lock.yaml unless you introduce a new test example.

Checklist

ℹ️ Check all checkboxes - this will indicate that you have done everything in accordance with the rules in CONTRIBUTING.

  • If you introduce new functionality, document it. You can run documentation with pnpm run docs:dev command.
  • Run the tests with pnpm test.
  • Changes in changelog are generated from PR name. Please, make sure that it explains your changes in an understandable manner. Please, prefix changeset messages with feat:, fix:, perf:, docs:, or chore:.
  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a merge functionality in the form API, allowing users to combine multiple forms and submit them collectively.
    • Added a new multi-step form component that enables users to fill out and merge data from two separate forms seamlessly.
    • New route for the Form Merge Example added to the application for demonstration purposes.
  • Localization

    • Expanded form-related labels in English and Chinese to include "Merge Form" and its translation.
  • Enhancements

    • Added a function to clear points in the captcha hook for improved user experience.

Copy link

changeset-bot bot commented Sep 24, 2024

⚠️ No Changeset found

Latest commit: 87eeb79

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Sep 24, 2024

Walkthrough

The changes introduce enhancements to the FormApi class by adding a merge method that allows chaining multiple form instances and submitting them collectively. Additionally, a new clearPoints function is added to the useCaptchaPoints hook, and localization support is expanded with new entries in English and Chinese JSON files. A new route and a multi-step form component are also created to facilitate merging form data in a user-friendly manner.

Changes

Files Change Summary
packages/@core/ui-kit/form-ui/src/form-api.ts Added merge(formApi: FormApi) method and submitAllForm(needMerge: boolean = true) method to the FormApi class for chaining and collective submission of forms.
packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts Introduced clearPoints() method to clear all points from the points array in the useCaptchaPoints hook.
playground/src/locales/langs/en-US.json Added new key "merge": "Merge Form" to enhance form-related labels in English.
playground/src/locales/langs/zh-CN.json Added new key "merge": "合并表单" to provide a Chinese translation for the term "merge" in the context of forms.
playground/src/router/routes/modules/examples.ts Added a new route FormMergeExample with path /examples/form/merge for the new form merging feature.
playground/src/views/examples/form/merge.vue Created a multi-step form component allowing users to fill out and merge data from two forms, utilizing Vue 3, TypeScript, and Ant Design Vue for UI elements.

Possibly related PRs

Suggested labels

feature, enhancement, documentation

Suggested reviewers

  • vince292007
  • aonoa

🐰 "In the meadow where forms unite,
A merge of data feels just right.
With points cleared and routes anew,
Together we'll submit, me and you!
Hopping through fields of code so bright,
Celebrating changes, oh what a sight!" 🌼


Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 344eb5f and 87eeb79.

Files selected for processing (1)
  • playground/src/views/examples/form/merge.vue (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • playground/src/views/examples/form/merge.vue

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>, please review it.
    -- Generate unit testing code 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    -- @coderabbitai read src/utils.ts and generate unit testing code.
    -- @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    -- @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@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.

Actionable comments posted: 6

Outside diff range and nitpick comments (5)
packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts (1)

11-13: LGTM! Consider a more concise alternative.

The clearPoints() function correctly clears all points from the array. It aligns well with the PR objectives of enhancing form handling capabilities.

For a more concise implementation, consider:

  function clearPoints() {
-   points.splice(0, points.length);
+   points.length = 0;
  }

This achieves the same result but is slightly more efficient and readable.

playground/src/router/routes/modules/examples.ts (1)

102-109: LGTM! Consider a minor adjustment for consistency.

The new FormMergeExample route is well-structured and consistent with the existing routes. It correctly uses dynamic import for the component and follows the established pattern for internationalization.

For complete consistency with other form example routes, consider adding an empty line before this route definition. This would match the spacing pattern seen in the rest of the file. Here's a suggested change:

          },
+
          {
            name: 'FormMergeExample',
            path: '/examples/form/merge',
            component: () => import('#/views/examples/form/merge.vue'),
            meta: {
              title: $t('page.examples.form.merge'),
            },
          },
playground/src/views/examples/form/merge.vue (1)

53-78: Specify Submit Button Text for SecondForm

In SecondForm, the submitButtonOptions are not specified. To maintain consistency and improve user experience, consider specifying the submit button text.

Example:

 const [SecondForm, secondFormApi] = useVbenForm({
   // ...existing configurations
+  submitButtonOptions: {
+    text: '提交',
+  },
   schema: [
     // ...existing schema
   ],
 });
packages/@core/ui-kit/form-ui/src/form-api.ts (2)

127-159: Specify proper types for proxy handler parameters

In the proxy's get handler, the parameters target and prop are currently typed as any. To improve type safety and leverage TypeScript's capabilities, consider specifying more precise types for these parameters.

Apply this diff to specify types:

        const proxy = new Proxy(formApi, {
-         get(target: any, prop: any) {
+         get(target: FormApi, prop: string | symbol) {

124-163: Prevent potential memory leaks from unbounded chain growth

The merge method creates a closure over the chain array and returns a proxy that allows chaining FormApi instances indefinitely. If not managed carefully, this could lead to memory leaks due to the chain array retaining references to all merged FormApi instances.

Consider implementing a mechanism to manage the size of the chain array or provide a way to dispose of it when it's no longer needed.

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 79c87c9 and 344eb5f.

Files selected for processing (6)
  • packages/@core/ui-kit/form-ui/src/form-api.ts (1 hunks)
  • packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts (1 hunks)
  • playground/src/locales/langs/en-US.json (1 hunks)
  • playground/src/locales/langs/zh-CN.json (1 hunks)
  • playground/src/router/routes/modules/examples.ts (1 hunks)
  • playground/src/views/examples/form/merge.vue (1 hunks)
Additional comments not posted (5)
packages/effects/common-ui/src/components/captcha/hooks/useCaptchaPoints.ts (2)

Line range hint 14-18: LGTM! Proper exposure of the new function.

The addition of clearPoints to the return statement is correct. It properly exposes the new functionality to consumers of this hook, which is consistent with the PR objectives.


Line range hint 1-18: Overall assessment: Good to merge

The changes in this file are minimal, focused, and align well with the PR objectives. The new clearPoints() function enhances the hook's functionality by allowing users to reset the points array. The implementation is correct and non-breaking.

A minor optimization suggestion was provided for the clearPoints() function, but it's not critical for merging this PR.

The changes successfully introduce the ability to merge multiple forms into a single submission, as described in the PR summary, by providing a way to clear existing points when needed.

playground/src/locales/langs/zh-CN.json (1)

82-83: LGTM! The translation aligns with the PR objectives.

The addition of "merge": "合并表单" is correct and appropriate. It accurately translates "merge form" to Chinese, which is consistent with the PR's goal of introducing form merging functionality. The placement and formatting of this new entry are also correct within the existing structure.

playground/src/locales/langs/en-US.json (1)

82-83: LGTM! The new localization entry aligns with the PR objectives.

The addition of "merge": "Merge Form" is structurally correct and consistent with the existing entries. It properly introduces the localization for the new merge form feature described in the PR objectives.

playground/src/views/examples/form/merge.vue (1)

11-16: FirstForm Submission Handler Works Correctly

The onFirstSubmit function correctly handles the form submission by displaying a success message and updating currentTab to proceed to the next form.

playground/src/views/examples/form/merge.vue Show resolved Hide resolved
playground/src/views/examples/form/merge.vue Outdated Show resolved Hide resolved
playground/src/views/examples/form/merge.vue Show resolved Hide resolved
packages/@core/ui-kit/form-ui/src/form-api.ts Show resolved Hide resolved
packages/@core/ui-kit/form-ui/src/form-api.ts Show resolved Hide resolved
packages/@core/ui-kit/form-ui/src/form-api.ts Show resolved Hide resolved
@Squall2017 Squall2017 changed the title feat: 添加合并表单功能 feat(form): 添加合并表单功能 Sep 24, 2024
@vince292007 vince292007 changed the title feat(form): 添加合并表单功能 feat(form): add merge form functionality Sep 25, 2024
@vince292007 vince292007 merged commit fdc5b02 into vbenjs:main Sep 25, 2024
18 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Oct 14, 2024
16 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Oct 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants