Skip to content

Conversation

@gweesin
Copy link
Contributor

@gweesin gweesin commented Mar 7, 2025

PR

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our Commit Message Guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Issue Number: #3055

What is the new behavior?

IPv6 input displays normally

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • Refactor
    • Enhanced IP address input handling by streamlining validation and defaulting behavior for both IPv4 and IPv6 formats.
  • Tests
    • Expanded test coverage for the IP Address component to verify delimiter options, size variants, disabled states, and proper handling of default and invalid values.

@coderabbitai
Copy link

coderabbitai bot commented Mar 7, 2025

Walkthrough

This pull request revises the IP address handling logic and enhances the test coverage for the IpAddress component. The core function now inverts its validation logic—initially checking for falsy or invalid IPs to initialize default empty segments—and then processes valid IPv6 addresses with streamlined segmentation, while maintaining the original IPv4 splitting. Tests have been reorganized and expanded to cover delimiter configurations (including custom delimiters and icon rendering), size settings, disabled states, and validations for both IPv4 and IPv6 formats.

Changes

File(s) Change Summary
packages/renderless/.../ip-address/index.ts Refactored the setValue logic: inverted initial validation to check for falsy/invalid values and initialize empty segments; streamlined IPv6 segmentation; IPv4 handling remains unchanged.
packages/vue/.../ip-address.test.tsx Added and restructured tests for the IpAddress component: updated delimiter tests (default, custom, icon), added size tests, and covered disabled, default, and invalid IP scenarios.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant setValue
    participant Validator as ipValidator
    participant State as state

    Caller->>setValue: call setValue(value)
    setValue->>Validator: Validate value
    alt Value is falsy or invalid
        setValue->>State: Initialize empty segments (IPv6: 8, IPv4: 4)
        setValue-->>Caller: Return early
    else Value is valid
        alt IPv6 address
            setValue->>State: Process IPv6 (split by colon, fill missing segments)
        else IPv4 address
            setValue->>State: Process IPv4 (split by dots)
        end
        setValue-->>Caller: Return processed address
    end
Loading

Suggested labels

bug

Suggested reviewers

  • zzcr

Poem

I'm a rabbit hopping through the code,
Digit by digit, on a curious road.
IPv6 and IPv4 now dance in line,
As tests ensure every dot will shine.
With whiskers twitching at each new fix,
I celebrate our changes with cute ASCII tricks!
Hop on, and let these changes mix!

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/vue/src/ip-address/__tests__/ip-address.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

packages/renderless/src/ip-address/index.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the plugin "eslint-plugin-vue".

(The package "eslint-plugin-vue" was not found when loaded as a Node module from the directory "".)

It's likely that the plugin isn't installed correctly. Try reinstalling by running the following:

npm install eslint-plugin-vue@latest --save-dev

The plugin "eslint-plugin-vue" was referenced from the config file in ".eslintrc.js » @antfu/eslint-config » @antfu/eslint-config-vue".

If you still can't figure out the problem, please stop by https://eslint.org/chat/help to chat with the team.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

@github-actions github-actions bot added the bug Something isn't working label Mar 7, 2025
@petercat-assistant
Copy link

Walkthrough

This pull request addresses a bug related to the display of IPv6 addresses when the ipValidator is not true. The changes ensure that IPv6 inputs are displayed correctly by adjusting the logic for setting the address value.

Changes

File Summary
packages/renderless/src/ip-address/index.ts Refactored the logic for setting IPv6 and IPv4 address values, ensuring correct display even when ipValidator is false.
packages/vue/src/ip-address/__tests__/ip-address.test.tsx Added comprehensive tests for IPv6 and IPv4 address handling, including cases for invalid values and different delimiters.

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.

Actionable comments posted: 0

🧹 Nitpick comments (3)
packages/renderless/src/ip-address/index.ts (2)

101-114: Enhanced IPv6 address handling with proper segment management

The IPv6 address handling has been improved to correctly process addresses with missing segments. However, there's a potential issue with the array initialization.

The current implementation uses Array.fill({ value: '0000' }) which makes all array elements reference the same object. If any of those objects are modified later, all of them will change. Consider creating unique objects for each element:

-const newItems = Array(missingCount).fill({ value: '0000' })
+const newItems = Array.from({ length: missingCount }, () => ({ value: '0000' }))

307-307: Consider translating Chinese comments to English

The comment "NEXT 屏蔽选中时,替换值大于255" is in Chinese while most of the codebase is in English. Consider translating it to maintain consistency.

packages/vue/src/ip-address/__tests__/ip-address.test.tsx (1)

60-74: Invalid input handling tests

These tests are crucial for validating the fix for the IPv6 display issue, confirming that:

  1. An IPv4 address in IPv6 mode results in empty fields
  2. An IPv6 address in IPv4 mode results in empty fields

Consider adding more edge cases like partially valid addresses or malformed inputs.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd468ac and 58ba9c9.

📒 Files selected for processing (2)
  • packages/renderless/src/ip-address/index.ts (1 hunks)
  • packages/vue/src/ip-address/__tests__/ip-address.test.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: PR E2E Test (pnpm test:e2e3)
🔇 Additional comments (7)
packages/renderless/src/ip-address/index.ts (2)

92-99: Improved input validation with early return pattern

The code now properly handles invalid IP addresses by checking for falsy values or validation failures upfront. This is a cleaner approach that follows the early return pattern and fixes the IPv6 display issues.


115-117: Simplified IPv4 address parsing

The IPv4 handling logic has been simplified while maintaining the same functionality.

packages/vue/src/ip-address/__tests__/ip-address.test.tsx (5)

5-5: Added icon import for delimiter testing

The import of iconBoat is appropriately added to support the new tests for icon delimiters.


18-38: Comprehensive delimiter configuration tests

Good addition of tests that verify different delimiter configurations (default dot, custom text, and icon-based delimiters), ensuring the component renders the expected number of delimiters.


40-47: Component size variation tests

Efficient use of parameterized testing to verify that all supported sizes (medium, small, mini) apply the correct CSS classes.


49-52: Disabled state verification

Simple and effective test to verify the disabled attribute is properly applied to the input elements.


54-58: Default value display test

This test confirms that a valid IPv4 address is correctly split and displayed across input fields.

@zzcr zzcr linked an issue Mar 10, 2025 that may be closed by this pull request
@James-9696 James-9696 assigned James-9696 and unassigned James-9696 Mar 14, 2025
@zzcr zzcr merged commit c4522ce into opentiny:dev Mar 17, 2025
16 checks passed
@gweesin gweesin deleted the fix/ipv6 branch March 17, 2025 04:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 [Bug]: IpAddress Ipv6 模式下 传入 Ipv4 地址后输入框消失

3 participants