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(input): [input] fix input remembers the input history and does no… #2372

Merged
merged 1 commit into from
Oct 24, 2024

Conversation

zzcr
Copy link
Member

@zzcr zzcr commented Oct 24, 2024

…t record blank characters

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: N/A

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Introduced a read-only textarea component that displays a predefined message and supports popup information for additional context.
  • Bug Fixes

    • Improved input validation to prevent empty or whitespace-only strings from being added to local storage.

Copy link

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in this pull request involve modifications to a Vue.js component and a function in the tall storage module. The <tiny-input> component has been updated to a read-only <tiny-textarea> with new attributes and a predefined message. Additionally, the input validation in the addMemory function has been improved to prevent the storage of empty or whitespace-only strings.

Changes

File Path Change Summary
examples/sites/demos/pc/app/input/... Updated <tiny-input> to <tiny-textarea> with new attributes, changed initialization of input, and modified CSS class and width.
packages/renderless/src/tall-storage/index.ts Modified addMemory function to enhance input validation by ensuring value is not just whitespace.

Possibly related PRs

Suggested labels

bug

Poem

🐰 In a field of code so bright,
A textarea now takes flight,
With messages clear, not a trace of white,
A popup to share, oh what a sight!
Validation's strong, no empty strings,
In this world of inputs, joy it brings! 🌼


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.

@github-actions github-actions bot added the bug Something isn't working label Oct 24, 2024
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: 1

🧹 Outside diff range and nitpick comments (3)
examples/sites/demos/pc/app/input/display-only-popup-more-composition-api.vue (1)

3-3: Document the popup-more behavior for maintainability.

The conversion to a read-only textarea with popup functionality looks good and aligns with the PR objectives. However, the behavior of the popup-more prop should be documented for future maintainers.

Consider adding a comment above the component explaining how the popup-more functionality works and when it triggers.

packages/renderless/src/tall-storage/index.ts (2)

132-133: LGTM! The validation logic effectively prevents storing empty entries.

The addition of trim() check is a good improvement that prevents storing whitespace-only strings in the history.

Consider these improvements for better type safety and error handling:

-export const addMemory = (props) => (value) => {
+export const addMemory = (props: { name: string; memorySpace?: number }) => (value: string | null | undefined) => {
   // input记忆历史输入不添加空白字符
-  if (props.name && value?.trim()) {
+  if (!props.name || !value?.trim()) {
+    return;
+  }
+  
+  try {
     setLocalStorageage(props.name, value, props.memorySpace)
+  } catch (error) {
+    console.warn('Failed to store input history:', error)
   }
 }

132-133: Consider implementing storage management safeguards.

The current implementation might benefit from additional storage management features:

  1. Implement storage quota monitoring
  2. Add data sanitization before storage
  3. Include cleanup mechanism for old entries
  4. Handle localStorage availability/permissions

Would you like me to provide a detailed implementation for any of these improvements?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cd290c5 and 57655e4.

📒 Files selected for processing (2)
  • examples/sites/demos/pc/app/input/display-only-popup-more-composition-api.vue (1 hunks)
  • packages/renderless/src/tall-storage/index.ts (1 hunks)
🔇 Additional comments (3)
examples/sites/demos/pc/app/input/display-only-popup-more-composition-api.vue (2)

17-18: LGTM! Styles updated correctly for textarea.

The selector and width adjustments appropriately reflect the component's transition to a textarea type.


1-20: Verify if additional changes are needed for input history fix.

While making the input read-only addresses part of the issue, we should verify if additional changes are needed in the component's logic to fully resolve the input history and blank characters problem mentioned in the PR objectives.

✅ Verification successful

Let me try a different approach to verify the input history handling code.

The first command will help us find any files related to input history handling, while the second command will help us locate the Input component's implementation to understand its behavior better.


Let's examine the input history implementation to understand if the display-only mode properly handles it.

This will help us understand how the input history feature works and if the display-only mode already handles it correctly.


After analyzing the input component's implementation, I can now provide a conclusive response:

No additional changes needed for input history in display-only mode

The implementation shows that the display-only mode is properly handled:

  • The inputDisabled computed property includes state.isDisplayOnly check, which prevents any input interactions
  • The history-related features (addMemory, searchMemory, etc.) are part of the component's API but won't be triggered in display-only mode since:
    • The input is effectively disabled when display-only is true
    • History features are triggered by user interactions (like the change event), which can't occur in display-only mode

The current implementation in the PR correctly addresses the input history concern by:

  1. Making the input read-only through display-only prop
  2. Automatically disabling all input interactions, including history features
  3. Properly handling the display-only state in the component's core logic
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for related input history handling code
rg -l "input.*history|addMemory" --type vue --type ts

Length of output: 83


Script:

#!/bin/bash
# Search for input history related code using ripgrep without file type filters
rg -l "input.*history|addMemory"

# Also search for the Input component implementation
ast-grep --pattern 'export const Input = defineComponent({
  $$$
})'

Length of output: 683


Script:

#!/bin/bash
# Check the input component's history implementation
cat packages/renderless/src/input/vue.ts

# Check the demo implementation of addMemory
cat examples/sites/demos/pc/app/input/method-addMemory.vue

# Check if display-only mode affects history
rg "display.*only.*history|history.*display.*only" -A 5 -B 5

Length of output: 12789

packages/renderless/src/tall-storage/index.ts (1)

132-133: Verify consistent validation across related components.

Let's ensure this validation pattern is consistently applied across related components.

✅ Verification successful

Let me gather more specific information about the validation patterns in these components.

This will help us understand how values are validated before being stored in localStorage across different components.


Let me check the broader context of the validation patterns, particularly focusing on the tall-storage component where the change is being made.

This will help us understand the complete validation flow and context around the trim operation.


Based on the gathered information, I can now provide the final response:

The trim validation is correctly implemented and unique to this use case

The validation pattern value?.trim() in the tall-storage component is specifically designed for input memory history and is appropriately implemented. The investigation reveals:

  • The validation is part of the addMemory function which specifically handles input history storage
  • Other localStorage operations in the codebase (multiple-history, memorize) handle different types of data with their own appropriate validation patterns
  • This trim check is intentionally unique to input history to prevent storing whitespace-only entries
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for similar patterns in other components
echo "Searching for other localStorage operations..."
rg "localStorage\.setItem" --type ts

echo "\nSearching for other input history implementations..."
ast-grep --pattern 'if ($value) {
  $$$
  localStorage.$method($$$)
  $$$
}'

Length of output: 1453


Script:

#!/bin/bash
# Check the validation patterns in components that use localStorage
echo "Checking validation in tall-storage component..."
rg -B 2 -A 2 "localStorage\.setItem" packages/renderless/src/tall-storage/index.ts

echo "\nChecking validation in multiple-history component..."
rg -B 2 -A 2 "localStorage\.setItem" packages/vue/src/grid-toolbar/src/multiple-history.ts

echo "\nChecking memorize implementation..."
rg -B 2 -A 2 "localStorage\.setItem" packages/renderless/src/common/deps/memorize.ts

Length of output: 1014


Script:

#!/bin/bash
# Get more context around the validation in tall-storage
echo "Checking the full addMemory function in tall-storage..."
ast-grep --pattern 'function addMemory($_) {
  $$$
}'

echo "\nChecking the value validation patterns..."
rg -B 5 -A 5 "value\?\." packages/renderless/src/tall-storage/index.ts

Length of output: 559

Comment on lines +11 to +13
const input = ref(
'表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏'
)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider internationalization for the demo text.

While the demo text effectively describes the component's behavior, consider using i18n translations to make the demo more accessible to non-Chinese speakers and maintain consistency with internationalization practices.

Example approach:

-const input = ref(
-  '表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏。表单文本域开启只读模式,文本内容超过5行自动隐藏'
-)
+import { useI18n } from 'vue-i18n'
+const { t } = useI18n()
+const input = ref(t('demo.input.readonly_description'))

Committable suggestion was skipped due to low confidence.

@zzcr zzcr merged commit 56aa27c into dev Oct 24, 2024
7 checks passed
@kagol kagol deleted the fix-input-error-1024 branch November 4, 2024 06:16
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.

1 participant