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

fix: pinInput value synchronous update #5142

Merged
merged 1 commit into from
Dec 15, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Dec 15, 2024

Description

修复VbenPinInput的值未能实时更新的问题,该问题会导致在完整输入Pin之后,删除部分值也不能重新触发表单校验。

fix #5104

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

    • Enhanced validation for the authentication code input, requiring an exact length of 6 characters.
    • Updated error messages to reflect the required character count dynamically.
  • Bug Fixes

    • Improved synchronization between input fields and model value for better user experience.
  • Documentation

    • Localization updates for error messages in English and Chinese to specify the required character length for the security code.

@mynetfan mynetfan requested review from anncwb, vince292007 and a team as code owners December 15, 2024 06:16
Copy link
Contributor

coderabbitai bot commented Dec 15, 2024

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.

apps/web-antd/src/views/_core/authentication/code-login.vue

Oops! Something went wrong! :(

ESLint: 9.16.0

Error [ERR_MODULE_NOT_FOUND]: Cannot find module '/node_modules/@vben/eslint-config/dist/index.mjs' imported from /eslint.config.mjs
at finalizeResolution (node:internal/modules/esm/resolve:257:11)
at moduleResolve (node:internal/modules/esm/resolve:914:10)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)

Walkthrough

The pull request introduces a consistent modification across multiple components and localization files to standardize the verification code input length to 6 characters. This change involves updating the code-login.vue components in different web applications, modifying the pin-input component's input handling, and updating localization strings to reflect the new 6-digit code requirement. The changes aim to improve input validation and provide more precise user feedback across different application variants.

Changes

File Change Summary
apps/web-*/src/views/_core/authentication/code-login.vue Added CODE_LENGTH constant (6), updated validation rules to enforce exact 6-character code length, modified error messages
packages/@core/ui-kit/shadcn-ui/src/components/pin-input/input.vue Added watcher to improve two-way data binding between input fields and model value
packages/locales/src/langs/*/authentication.json Updated codeTip localization to include dynamic character count placeholder

Assessment against linked issues

Objective Addressed Explanation
Fix VbenPinInput component value retention after deletion [#5104]

Possibly related PRs

Suggested Labels

bug

Suggested Reviewers

  • anncwb
  • vince292007

Poem

🐰 Six digits dance, a code so neat,
Validation's rhythm, now complete!
Input fields sing their structured song,
No more ambiguity, nothing wrong.
A rabbit's code, precise and bright! 🔢✨

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request. This feature will be included in our Pro Plan when released.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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: 0

🧹 Nitpick comments (3)
playground/src/views/_core/authentication/code-login.vue (1)

13-13: Consider moving CODE_LENGTH to a shared configuration.

While the constant definition is good practice, consider moving it to a shared configuration file since it's used across multiple components and affects the authentication system globally.

apps/web-naive/src/views/_core/authentication/code-login.vue (1)

13-13: Consider reducing code duplication across implementations.

The identical changes across different UI framework implementations suggest an opportunity to reduce duplication. Consider:

  1. Moving the CODE_LENGTH constant to a shared authentication configuration
  2. Creating a shared form schema factory for the code login form

Example approach:

// @vben/common/config/auth.ts
export const AUTH_CONFIG = {
  CODE_LENGTH: 6,
} as const;

// @vben/common/schemas/auth.ts
export function createCodeLoginFormSchema(): VbenFormSchema[] {
  return [
    // ... common form schema logic
  ];
}

Also applies to: 34-34, 46-48

packages/@core/ui-kit/shadcn-ui/src/components/pin-input/input.vue (1)

50-52: Consider using computed property for better reactivity.

While the current implementation works, consider refactoring to use a computed property with getter/setter for better reactivity and cleaner code:

-const inputValue = ref<string[]>([]);
-
-watch(
-  () => modelValue.value,
-  () => {
-    inputValue.value = modelValue.value?.split('') ?? [];
-  },
-);
-
-watch(inputValue, (val) => {
-  modelValue.value = val.join('');
-});

+const inputValue = computed({
+  get: () => modelValue.value?.split('') ?? [],
+  set: (val: string[]) => {
+    modelValue.value = val.join('');
+  }
+});

This approach:

  • Eliminates the need for multiple watchers
  • Provides more predictable reactivity
  • Reduces the chance of sync issues
  • Makes the code more maintainable
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bedf199 and b1421a5.

📒 Files selected for processing (7)
  • apps/web-antd/src/views/_core/authentication/code-login.vue (3 hunks)
  • apps/web-ele/src/views/_core/authentication/code-login.vue (3 hunks)
  • apps/web-naive/src/views/_core/authentication/code-login.vue (3 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/components/pin-input/input.vue (1 hunks)
  • packages/locales/src/langs/en-US/authentication.json (1 hunks)
  • packages/locales/src/langs/zh-CN/authentication.json (1 hunks)
  • playground/src/views/_core/authentication/code-login.vue (3 hunks)
🔇 Additional comments (8)
packages/locales/src/langs/zh-CN/authentication.json (1)

41-41: LGTM: Improved localization message with dynamic length.

The message now properly supports dynamic verification code length, making it more specific and user-friendly.

playground/src/views/_core/authentication/code-login.vue (1)

34-34: LGTM: Improved PIN input validation.

The changes properly synchronize the PIN input length between the UI component and validation rules, which should fix the issue with form validation not triggering after partial deletion.

Let's verify the consistency of CODE_LENGTH usage across the codebase:

Also applies to: 46-48

✅ Verification successful

CODE_LENGTH constant is consistently defined and used across all UI variants

The verification shows that CODE_LENGTH is consistently defined as 6 across all UI framework variants (antd, naive, ele, and playground), and there are no hardcoded "6" values that should be using the constant instead. The changes properly maintain consistency in PIN input validation across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any hardcoded values that should use CODE_LENGTH
rg "(?:length|Length).*[\"']6[\"']" --type ts --type vue

# Search for all CODE_LENGTH usage to ensure consistency
rg "CODE_LENGTH\s*=\s*\d+" --type ts --type vue

Length of output: 168


Script:

#!/bin/bash
# Search for any hardcoded values that should use CODE_LENGTH, without file type restrictions
rg "(?:length|Length).*[\"']6[\"']"

# Search for all CODE_LENGTH usage to ensure consistency
rg "CODE_LENGTH\s*=\s*\d+"

# Find all files that might contain CODE_LENGTH constant definition
rg "CODE_LENGTH" -l

Length of output: 656

apps/web-antd/src/views/_core/authentication/code-login.vue (2)

13-13: LGTM: Good practice using a constant for code length

Using a constant for the PIN length improves maintainability and ensures consistency across the component.


34-34: Verify if this change fixes the synchronous update issue

While the code changes look correct, I don't see direct evidence that this addresses the reported issue of "input value not updating in real-time" and "inability to trigger form validation after partially deleting values". Could you please verify if additional changes are needed in the VbenPinInput component itself?

Also applies to: 46-48

✅ Verification successful

Let's search for the component implementation using different patterns to locate the file first.


The component implementation properly handles real-time updates and validation

Looking at the implementation in input.vue, the component correctly handles synchronous updates through:

  1. Two-way binding with defineModel and proper value syncing
  2. Watch handlers that update both the internal inputValue array and external modelValue
  3. Proper event handling for completion and validation

The code changes in code-login.vue are sufficient as the underlying component already has the necessary reactive behavior built-in. The reported issues about "input value not updating in real-time" and "inability to trigger form validation" would be resolved by using this implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for VbenPinInput component implementation to check value update logic
ast-grep --pattern 'const VbenPinInput = defineComponent({
  $$$
  setup($props, $context) {
    $$$
  }
  $$$
})'

Length of output: 116


Script:

#!/bin/bash
# Let's try different approaches to find the component implementation

# Search for files containing VbenPinInput
fd -t f . | xargs rg "VbenPinInput" -l

# Search for pin input related files
fd -t f "pin.*\.(vue|ts|js|tsx|jsx)$"

# Search for potential component definition patterns
rg -l "defineComponent.*Pin"

Length of output: 1329


Script:

#!/bin/bash
# Let's examine the pin input implementation in shadcn-ui since it appears to be the main component
cat packages/@core/ui-kit/shadcn-ui/src/ui/pin-input/PinInput.vue
cat packages/@core/ui-kit/shadcn-ui/src/ui/pin-input/PinInputInput.vue

# Also check how it's being used in code-login.vue
cat apps/web-antd/src/views/_core/authentication/code-login.vue

Length of output: 3481


Script:

#!/bin/bash
# Let's check the radix-vue implementation since the component is based on it
cat packages/@core/ui-kit/shadcn-ui/src/components/pin-input/index.ts

# Also check if there are any related components or types
rg -A 5 "VbenPinInput" packages/effects/common-ui/src/components/index.ts
rg -A 5 "VbenPinInput" packages/@core/ui-kit/form-ui/src/types.ts

Length of output: 575


Script:

#!/bin/bash
# Let's check the actual pin input implementation in shadcn-ui
cat packages/@core/ui-kit/shadcn-ui/src/components/pin-input/input.vue
cat packages/@core/ui-kit/shadcn-ui/src/components/pin-input/types.ts

Length of output: 3043

apps/web-ele/src/views/_core/authentication/code-login.vue (1)

13-13: LGTM: Consistent implementation across web variants

The changes mirror those in the web-antd version, maintaining consistency across different web application variants.

Also applies to: 34-34, 46-48

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

41-41: LGTM: Clear error message with dynamic length

The updated message clearly communicates the exact length requirement. However, we should verify that this change is consistently applied across all language files.

✅ Verification successful

Both language files are properly updated with dynamic length parameter

The verification shows that both English (en-US) and Chinese (zh-CN) localization files have been updated to use the {0} placeholder for the dynamic code length. The messages are consistent in their approach and grammatically correct in their respective languages.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if all language files have been updated with the new message format
fd --extension json --exec grep -l "codeTip" {} \; packages/locales/src/langs/

Length of output: 495


Script:

#!/bin/bash
# Check if all language files have been updated with the new message format
fd -e json . packages/locales/src/langs/ --exec grep -l "codeTip" {} \;

Length of output: 180


Script:

#!/bin/bash
# Check the actual content of codeTip in both language files
echo "=== English (en-US) ==="
grep -A 1 '"codeTip"' packages/locales/src/langs/en-US/authentication.json

echo -e "\n=== Chinese (zh-CN) ==="
grep -A 1 '"codeTip"' packages/locales/src/langs/zh-CN/authentication.json

Length of output: 396

packages/@core/ui-kit/shadcn-ui/src/components/pin-input/input.vue (2)

50-52: LGTM! This change fixes the synchronization issue.

The new watcher ensures that changes to individual PIN digits are immediately reflected in the modelValue, addressing the real-time update issue mentioned in PR #5104.


Line range hint 1-140: Verify form validation integration.

Since this component is used in form validation contexts (as mentioned in the PR objectives), we should verify that the real-time updates properly trigger form validation in parent components.

@mynetfan mynetfan merged commit 7581fb3 into vbenjs:main Dec 15, 2024
14 checks passed
@mynetfan mynetfan deleted the fix/pin-input-value-sync branch December 15, 2024 06:26
@coderabbitai coderabbitai bot mentioned this pull request Dec 16, 2024
16 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jan 15, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: VbenPinInput组件输入验证码后再删掉,获取到的验证码是未删除之前的
1 participant