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

perf: [antd] default placeholder for input and select components #4551

Merged
merged 5 commits into from
Oct 3, 2024

Conversation

imdap
Copy link
Contributor

@imdap imdap commented Sep 30, 2024

Description

适用于antd input和select组件默认的placeholder

image
image

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
    • Introduced higher-order components for enhanced placeholder functionality in various input components.
  • Localization Updates
    • Added placeholder text entries in English and Chinese for input and select fields, improving user guidance.

@imdap imdap requested review from anncwb, vince292007 and a team as code owners September 30, 2024 03:27
Copy link

changeset-bot bot commented Sep 30, 2024

⚠️ No Changeset found

Latest commit: e1004d2

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 30, 2024

Walkthrough

The changes introduced in this pull request enhance form components by implementing a higher-order function, withDefaultPlaceholder, to manage default placeholders for various input types in the Ant Design Vue framework. This function is applied to several components, including Input, Select, and others, within the setupVbenForm function, ensuring they receive appropriate placeholder attributes while maintaining the overall structure of the form setup.

Changes

File Change Summary
apps/web-antd/src/adapter/form.ts Added withDefaultPlaceholder function for managing default placeholders in input components. Updated component signatures in setupVbenForm to utilize this new function for Input, InputNumber, InputPassword, Mentions, Select, Textarea, and TreeSelect.
playground/src/adapter/form.ts Similar enhancements as in apps/web-antd/src/adapter/form.ts, including the addition of withDefaultPlaceholder function and updates to component usage in the form setup.

Possibly related PRs

Suggested labels

perf

Suggested reviewers

  • vince292007
  • anncwb

Poem

🐇 In the meadow where bunnies hop,
New placeholders make our forms pop!
With guidance clear, they softly say,
"Fill me in, don't delay!"
A joyful change, so bright and neat,
Our forms now dance to a happy beat! 🌼


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 6f5304c and e1004d2.

📒 Files selected for processing (2)
  • apps/web-antd/src/adapter/form.ts (3 hunks)
  • playground/src/adapter/form.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • playground/src/adapter/form.ts
🔇 Additional comments (5)
apps/web-antd/src/adapter/form.ts (5)

7-7: LGTM: Import statement updated correctly

The addition of Component and SetupContext imports from 'vue' is appropriate for the new withDefaultPlaceholder function implementation.


60-68: LGTM: Well-implemented higher-order component for default placeholders

The withDefaultPlaceholder function is a good implementation that addresses the PR objective. It's type-safe, flexible (supporting both 'input' and 'select' types), and properly uses internationalization via the $t function.


86-89: LGTM: Consistent application of withDefaultPlaceholder

The changes in setupVbenForm correctly and consistently apply the withDefaultPlaceholder HOC to all relevant input and select components. This implementation aligns well with the PR objective of adding default placeholders to these components.

Also applies to: 94-94, 97-97, 99-99


60-68: Past review comment addressed

The current implementation of withDefaultPlaceholder effectively addresses the concern raised in the past review comment. It reduces code duplication and improves type safety by using a single, generic function for both input and select components, rather than separate functions as originally suggested. This approach is even more concise and maintainable.


7-7: Overall assessment: Excellent implementation

The changes in this file successfully implement default placeholders for input and select components, meeting the PR objectives. The new withDefaultPlaceholder function is well-designed, type-safe, and flexible. Its application is consistent across all relevant components in setupVbenForm. The implementation also addresses concerns from past reviews by reducing code duplication. These changes improve the user experience and maintainability of the codebase.

Also applies to: 60-68, 86-89, 94-94, 97-97, 99-99


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

🧹 Outside diff range and nitpick comments (5)
apps/web-antd/src/adapter/form.ts (2)

60-65: Approve implementation with suggestion for type improvements

The withInputPlaceholder HOC correctly implements the placeholder logic and uses the h function for rendering. However, the use of any types could be improved for better type safety.

Consider improving type safety by replacing any with more specific types:

const withInputPlaceholder = <T extends Component>(component: T) => {
  return (props: ComponentProps<T>, { attrs, slots }: SetupContext) => {
    const placeholder = props?.placeholder || $t('placeholder.input');
    return h(component, { ...props, attrs, placeholder }, slots);
  };
};

This change requires importing ComponentProps and SetupContext from Vue, and it will provide better type inference for the wrapped components.


Line range hint 1-140: Overall feedback: Implementation meets objectives with room for improvements

The changes successfully implement default placeholders for input and select components, meeting the PR objectives. The higher-order components are well-structured and consistently applied. However, there are opportunities for improvement:

  1. Enhance type safety by replacing any types with more specific types.
  2. Reduce code duplication by refactoring the HOCs into a more generic function.
  3. Consider adding unit tests for the new HOCs to ensure their correct behavior.

These improvements would enhance the maintainability and robustness of the code without changing its core functionality.

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

226-293: LGTM! Consider adding validation rules and error handling.

The implementation of CustomLayoutForm is well-structured and consistent with the existing BaseForm. The use of Tailwind CSS classes for layout provides flexibility and maintainability.

Some suggestions for improvement:

  1. Consider adding validation rules to the schema for each field where applicable.
  2. Implement error handling and display mechanisms for form submission errors.
  3. Add comments explaining the purpose of custom layout classes for better maintainability.

Line range hint 328-340: LGTM! Consider adding an "extra" slot for consistency.

The addition of the new Card component for CustomLayoutForm is well-implemented and consistent with the existing structure. The title accurately describes its purpose, and the update to the Page component's content class improves the overall layout.

For consistency with the "基础示例" (Basic Example) Card, consider adding an "extra" slot to the new Card. This could be used for additional actions or information related to the custom layout form.

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

61-64: LGTM! Consider reorganizing for better maintainability.

The new placeholder entries are correctly implemented and align with the PR objectives. The translations for "请输入" (Please enter) and "请选择" (Please select) are accurate and idiomatic Chinese.

For better organization and maintainability, consider moving the placeholder section closer to other UI-related translations, such as near the widgets or formRules sections. This would make it easier for future maintainers to find and update related translations.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between b2c117f and 663409b.

📒 Files selected for processing (5)
  • apps/web-antd/src/adapter/form.ts (3 hunks)
  • packages/locales/src/langs/en-US.json (1 hunks)
  • packages/locales/src/langs/zh-CN.json (1 hunks)
  • playground/src/adapter/form.ts (3 hunks)
  • playground/src/views/examples/form/basic.vue (3 hunks)
🔇 Additional comments (6)
apps/web-antd/src/adapter/form.ts (2)

7-7: LGTM: Necessary import added

The import of Component type from 'vue' is correctly added and necessary for the new higher-order components.


90-93: LGTM: Consistent application of placeholder HOCs

The components have been correctly wrapped with the appropriate higher-order components to provide default placeholders. This implementation is consistent with the PR objectives.

To ensure all relevant components have been updated, let's verify the changes:

This script will help ensure that all relevant components have been properly wrapped with the placeholder HOCs.

Also applies to: 98-98, 101-101, 103-103

✅ Verification successful

Verification Successful: All components are properly wrapped with placeholder HOCs

All relevant components in apps/web-antd/src/adapter/form.ts have been confirmed to be correctly wrapped with the appropriate placeholder higher-order components.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all input and select components are wrapped with placeholder HOCs

# Test: Check for any unwrapped Input components
echo "Checking for unwrapped Input components:"
rg "Input[^:](?!.*withInputPlaceholder)" apps/web-antd/src/adapter/form.ts

# Test: Check for any unwrapped Select components
echo "Checking for unwrapped Select components:"
rg "Select[^:](?!.*withSelectPlaceholder)" apps/web-antd/src/adapter/form.ts

# Test: Verify all wrapped components
echo "Verifying wrapped components:"
rg "with(Input|Select)Placeholder" apps/web-antd/src/adapter/form.ts

Length of output: 1427


Script:

#!/bin/bash
# Description: Verify that all Input and Select components are wrapped with placeholder HOCs without using look-around

# Check for any Input components not wrapped with withInputPlaceholder
echo "Checking for unwrapped Input components:"
rg 'Input\s*:' apps/web-antd/src/adapter/form.ts | grep -v 'withInputPlaceholder(Input)'

# Check for any Select components not wrapped with withSelectPlaceholder
echo "Checking for unwrapped Select components:"
rg 'Select\s*:' apps/web-antd/src/adapter/form.ts | grep -v 'withSelectPlaceholder(Select)'

# Optionally, list all wrapped components for confirmation
echo "Listing all wrapped components:"
rg 'with(Input|Select)Placeholder' apps/web-antd/src/adapter/form.ts

Length of output: 1012

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

Line range hint 294-327: Clarify the submission process for CustomLayoutForm.

The onSubmit function remains unchanged, and it's not clear how the CustomLayoutForm is connected to the submission process. Please clarify:

  1. Is the CustomLayoutForm intended to use the same submission logic as BaseForm?
  2. If yes, consider adding a comment to explain this shared behavior.
  3. If no, implement and document the submission process for CustomLayoutForm.
packages/locales/src/langs/en-US.json (1)

61-64: LGTM! The new placeholders align well with the PR objectives.

The addition of default placeholders for input and select components is implemented correctly. The new entries are consistent with the existing translation structure and wording. This change should enhance the user experience by providing clear guidance for form interactions.

playground/src/adapter/form.ts (2)

7-7: [Approved] Importing 'Component' and 'h' from 'vue'

The import of Component for type annotations and h for rendering functional components is appropriate and necessary.


90-103: Ensure custom placeholders are properly overridden

Confirm that when a custom placeholder prop is provided, it overrides the default placeholder set by the wrapper functions.

To verify this behavior, consider adding unit tests that render the components with and without the placeholder prop to ensure the correct placeholder is displayed.

apps/web-antd/src/adapter/form.ts Outdated Show resolved Hide resolved
playground/src/adapter/form.ts Outdated Show resolved Hide resolved
playground/src/adapter/form.ts Outdated Show resolved Hide resolved
playground/src/adapter/form.ts Outdated Show resolved Hide resolved
@vince292007
Copy link
Collaborator

有冲突,机器人也有一些可以参考的建议

@imdap
Copy link
Contributor Author

imdap commented Sep 30, 2024

已经提取为公共方法

@anncwb anncwb added the perf label Oct 3, 2024
@anncwb anncwb merged commit aed31a5 into vbenjs:main Oct 3, 2024
13 checks passed
@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.

3 participants