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: add examples of asynchronous form verification and verification time #4559

Merged
merged 2 commits into from
Oct 3, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Oct 3, 2024

Description

close #4531

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

  • New Features

    • Updated Vben Form component documentation with enhanced type safety and a new utility function for default placeholders.
    • Introduced new form fields with specific validation properties and asynchronous validation logic in the example form.
  • Bug Fixes

    • Improved event binding and validation logic in the form field component to enhance performance and reliability.
  • Documentation

    • Enhanced documentation for form field types and properties to clarify usage and improve developer experience.

@anncwb anncwb added the feature label Oct 3, 2024
@anncwb anncwb requested review from vince292007 and a team as code owners October 3, 2024 07:00
Copy link

changeset-bot bot commented Oct 3, 2024

⚠️ No Changeset found

Latest commit: 7e46d31

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 Oct 3, 2024

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces updates to the Vben Form component documentation and related source code. Key changes include the addition of type imports and a new utility function for managing default placeholders. Additionally, the form setup configuration has been modified to disable the onChange event listener for Naive UI components. The types.ts file has been updated to refine type definitions for form field options, while new form fields with specific validation properties have been added to the rules.vue file.

Changes

File Path Change Summary
docs/src/components/common-ui/vben-form.md Updated documentation to include type imports and added withDefaultPlaceholder function for default placeholders. Modified form setup configuration.
packages/@core/ui-kit/form-ui/src/types.ts Updated import for Field to FieldOptions. Added FormFieldOptions type and replaced Partial<typeof Field> in FormCommonConfig.
packages/@core/ui-kit/form-ui/src/form-render/form-field.vue Modified logic for handling props, computed properties, event binding, and validation logic for form fields.
playground/src/views/examples/form/rules.vue Added two new form fields: input-blur with blur validation and input-async with asynchronous validation.

Assessment against linked issues

Objective Addressed Explanation
Add validation trigger options and asynchronous validation example (#4531)

Possibly related PRs

Suggested labels

enhancement, documentation

Suggested reviewers

  • vince292007

Poem

In the meadow where forms do play,
New fields and types have come to stay.
With placeholders bright and validation true,
The Vben Form shines, all fresh and new! 🌼✨
Hop along, let the changes unfold,
A tale of forms, forever told!


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: 1

🧹 Outside diff range and nitpick comments (4)
packages/@core/ui-kit/form-ui/src/types.ts (2)

36-43: LGTM: New FormFieldOptions type enhances validation control.

The introduction of FormFieldOptions type is a great addition. It extends FieldOptions with specific boolean properties for different validation triggers, providing more granular control over form field validation behavior. This aligns well with the PR objective of enhancing form validation capabilities.

Consider adding JSDoc comments for each new property to improve code documentation:

export type FormFieldOptions = Partial<
  {
    /** Trigger validation when the field loses focus */
    validateOnBlur?: boolean;
    /** Trigger validation when the field's value changes */
    validateOnChange?: boolean;
    /** Trigger validation when the user types in the field */
    validateOnInput?: boolean;
    /** Trigger validation when the field's v-model is updated */
    validateOnModelUpdate?: boolean;
  } & FieldOptions
>;

160-160: LGTM: FormCommonConfig updated to use new FormFieldOptions type.

The update of formFieldProps in FormCommonConfig to use the new FormFieldOptions type is consistent and appropriate. This change allows for more specific and granular configuration of form field properties across all form items, which aligns well with the PR objective of enhancing form validation capabilities.

Consider updating the JSDoc comment for formFieldProps to reflect its new capabilities:

/**
 * Configuration options for all form fields, including validation triggers
 * @default {}
 */
formFieldProps?: FormFieldOptions;
docs/src/components/common-ui/vben-form.md (2)

88-96: LGTM: Useful utility for default placeholders

The withDefaultPlaceholder function is a great addition that enhances form usability by automatically providing default placeholders. It's well-implemented using Vue's h function and is generic enough to be used with various form components.

Consider adding a brief comment explaining the purpose of this function for better maintainability.


131-132: LGTM: Improved compatibility with Naive UI

The addition of the disabledOnChangeListener option set to true is a good solution to prevent console errors when using the Naive UI component library. This demonstrates careful consideration of framework-specific behaviors.

Consider adding a brief comment explaining why this option is necessary for Naive UI, to help future maintainers understand the rationale behind this configuration.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 0cd865e and 71d5227.

📒 Files selected for processing (3)
  • docs/src/components/common-ui/vben-form.md (3 hunks)
  • packages/@core/ui-kit/form-ui/src/types.ts (3 hunks)
  • playground/src/views/examples/form/rules.vue (1 hunks)
🔇 Additional comments (8)
packages/@core/ui-kit/form-ui/src/types.ts (2)

2-2: LGTM: Import statement updated correctly.

The change from importing Field to FieldOptions from 'vee-validate' aligns well with the new FormFieldOptions type being introduced. This update suggests a more focused use of field options, which is a good practice for type specificity.


Line range hint 1-300: Summary: Changes enhance form validation capabilities as intended.

The modifications in this file successfully address the PR objectives by introducing more granular control over form field validation. The new FormFieldOptions type and its integration into FormCommonConfig provide a robust foundation for implementing various validation trigger methods and potentially supporting asynchronous validation.

Key improvements:

  1. Updated import statement for more specific type usage.
  2. Introduction of FormFieldOptions type with detailed validation trigger options.
  3. Integration of FormFieldOptions into FormCommonConfig for consistent usage across the form.

These changes lay the groundwork for implementing the examples of validation trigger methods and asynchronous validation as requested in the linked issue #4531. The code structure is clean and consistent with the existing codebase.

To ensure these changes don't introduce any breaking changes or inconsistencies, please run the following verification script:

This script will help identify any potential issues or inconsistencies introduced by these changes.

docs/src/components/common-ui/vben-form.md (4)

34-35: LGTM: Improved type safety with Vue imports

The addition of Component and SetupContext type imports from Vue enhances type safety in the code. This change aligns well with the PR objectives of improving the useVbenForm demonstration.


114-117: LGTM: Consistent application of default placeholders

The withDefaultPlaceholder function is now applied to multiple form components (Input, InputNumber, InputPassword, Mentions, Select, Textarea, TreeSelect). This ensures consistent behavior across different form elements and improves overall usability, aligning well with the PR objectives.

Also applies to: 122-122, 125-125, 127-127


Line range hint 135-140: LGTM: Improved model property mappings

The updates to modelPropNameMap provide clear and specific mappings for different form components (Checkbox, Radio, Switch, Upload). This enhances the flexibility of the form component, allowing it to work correctly with various types of form elements and their respective v-model bindings.


Line range hint 1-1000: Overall assessment: Excellent enhancements to Vben Form

This PR successfully addresses the objectives outlined in issue #4531 by enhancing the useVbenForm demonstration. The changes improve type safety, add useful utilities for default placeholders, ensure consistent behavior across form components, and enhance compatibility with different UI frameworks. These improvements will significantly enhance the usability and functionality of the form verification process within the Vben Admin framework.

Key improvements:

  1. Added type imports for better type safety
  2. Introduced a reusable withDefaultPlaceholder utility
  3. Applied consistent default placeholders across multiple form components
  4. Added configuration to prevent console errors with Naive UI
  5. Updated model property mappings for various form elements

The changes are well-implemented and align with best practices. Minor suggestions for additional comments have been made to improve maintainability.

playground/src/views/examples/form/rules.vue (2)

178-191: Addition of 'input-blur' field effectively demonstrates blur-triggered validation

The 'input-blur' field correctly sets up validation to trigger only on blur events by configuring validateOnChange and validateOnModelUpdate to false. This aligns well with the PR objectives to showcase different validation triggers.


192-218: Ensure the form supports asynchronous validation

The asynchronous validation for the 'input-async' field is correctly implemented using z.refine with an async function. Please verify that the form handling library supports asynchronous validations and that the form is configured to handle them properly to ensure the validation works as intended.

playground/src/views/examples/form/rules.vue Show resolved Hide resolved
@anncwb anncwb merged commit f701646 into main Oct 3, 2024
13 checks passed
@anncwb anncwb deleted the bugfix/4531 branch October 3, 2024 07:15
@coderabbitai coderabbitai bot mentioned this pull request Oct 14, 2024
16 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Nov 3, 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.

FEATURE: useVbenForm演示版本建议添加校验触发方式以及异步校验示例
1 participant