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(time-select): [time-select] Fix and optimize issues with invalid … #2735

Merged
merged 4 commits into from
Jan 7, 2025

Conversation

Youyou-smiles
Copy link
Collaborator

@Youyou-smiles Youyou-smiles commented Jan 3, 2025

…input data and backfill data, and add input filtering functionality

PR

fix(time-select): [time-select] 修复了简易输入时间,回车后不补充完整时间的问题。此问题之前是没有考虑处理的,并且输入框还可以输入非法内容,属于遗漏了检验数据的功能。这次修改增加了输入时间,选择面板数据会自动过滤出相符合的时间,回车后可以进行回填补充,默认补充第一条匹配的数据。在输入非法字段后回车会清空无效数据,也增加了一个过滤为空的‘暂无匹配数据’的展示。

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: #1247

What is the new behavior?

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

Summary by CodeRabbit

  • New Features

    • Enhanced time selection component with input filtering and validation
    • Added user feedback for empty time selection results
  • Bug Fixes

    • Improved time selection UI handling and input matching
  • Style

    • Updated styling for time selection component
    • Added new classes for scrollbar and no-match scenarios
    • Adjusted component height and padding
  • Tests

    • Updated test script for time selection component with adjusted UI element indices

…input data and backfill data, and add input filtering functionality
Copy link

coderabbitai bot commented Jan 3, 2025

Walkthrough

The pull request introduces enhancements to the time-select component across multiple files. The changes include modifications to test scripts, state management, filtering logic, and styling. The updates focus on improving the time selection functionality by adding input filtering, validation mechanisms, and updating the UI to handle scenarios with no matching time options. The changes span test configurations, renderless logic, Vue components, and Less stylesheets.

Changes

File Change Summary
examples/sites/demos/pc/app/time-select/range-placeholder.spec.ts Updated test script indices for time option selection and verification
packages/renderless/src/picker/index.ts Added input handling and filtering logic for 'time-select' component
packages/renderless/src/time-panel/index.ts Implemented conditional filtering for time panel items
packages/renderless/src/time-panel/vue.ts Added isFilter and filterVal state properties
packages/theme-saas/src/time-select/index.less Added new class prefixes and styling for time-select component
packages/theme/src/time-select/index.less Updated styling for time-select scrollbar and added .noMatchHeight class
packages/vue/src/time-panel/src/pc.vue Modified template to handle empty state and add "no matches" message

Sequence Diagram

sequenceDiagram
    participant User
    participant TimeSelect
    participant Picker
    participant TimePanel

    User->>TimeSelect: Input time
    TimeSelect->>Picker: Handle input
    Picker->>TimePanel: Filter items
    TimePanel-->>Picker: Filtered items
    Picker-->>TimeSelect: Update display
Loading

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • zzcr

Poem

🕰️ Time dances, indices shift with grace,
A rabbit's code finds its perfect place
Filters bloom, options align just right
No matches? Fear not, clarity's in sight!
Tick-tock goes the renderless delight 🐰


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

Walkthrough

This pull request addresses issues with invalid input data and backfill data in the time-select component. It introduces input filtering functionality to enhance data handling and user interaction.

Changes

File Summary
examples/sites/demos/pc/app/time-select/range-placeholder.spec.ts Adjusted test cases to reflect changes in time-select options and validation.
packages/renderless/src/picker/index.ts Added logic for input filtering in time-select component, including validation and state management.
packages/renderless/src/time-panel/index.ts Implemented filtering logic for time options based on user input.
packages/renderless/src/time-panel/vue.ts Added state properties for filtering and adjusted item computation.
packages/theme-saas/src/time-select/index.less
packages/theme/src/time-select/index.less
Updated styles to accommodate new filtering functionality and UI changes.
packages/vue/src/time-panel/src/pc.vue Modified template to handle filtered time options and display appropriate UI feedback.

@github-actions github-actions bot added the bug Something isn't working label Jan 3, 2025
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 (5)
packages/renderless/src/time-panel/index.ts (1)

109-117: Conditional filtering logic introduced.
When state.isFilter is true, filtering is performed based on state.filterVal. This approach is straightforward; however, consider these minor suggestions:

  1. Confirm state.filterVal is always a non-null string (avoid runtime errors with .includes).
  2. Optionally, provide case-insensitive matching or more advanced matching rules if scenario demands.
packages/renderless/src/time-panel/vue.ts (1)

50-51: Consider adding TypeScript type definitions for new state properties

The new state properties look good, but consider adding type definitions to improve type safety and documentation.

 const state = reactive({
-    isFilter: false,
-    filterVal: '',
+    isFilter: false as boolean,
+    filterVal: '' as string,
packages/vue/src/time-panel/src/pc.vue (1)

22-37: Consider extracting the item template to a separate component

The item rendering logic is correct, but it could be extracted to improve maintainability and reusability.

Consider creating a new component like TimeSelectItem.vue:

<!-- TimeSelectItem.vue -->
<template>
  <div
    class="tiny-time-select__item"
    :class="{
      selected: selected,
      disabled: disabled,
      default: isDefault
    }"
    :disabled="disabled"
    @click="$emit('click', item)"
  >
    {{ item.value }}
  </div>
</template>

<script>
export default {
  props: {
    item: { type: Object, required: true },
    selected: { type: Boolean, default: false },
    disabled: { type: Boolean, default: false },
    isDefault: { type: Boolean, default: false }
  }
}
</script>
packages/theme/src/time-select/index.less (2)

23-25: Consider using min-height instead of fixed height

The fixed height of 36px might be too rigid. Using min-height would allow the container to grow if needed while maintaining the minimum space required.

 &.noMatchHeight {
-    height: 36px;
+    min-height: 36px;
 }

61-63: Consider adding vertical padding for better spacing

The centered text looks good, but consider adding some vertical padding for better visual balance when there are no matches.

 .noMatch {
   text-align: center;
+  padding: 8px 0;
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 08970be and 0ca06b1.

📒 Files selected for processing (7)
  • examples/sites/demos/pc/app/time-select/range-placeholder.spec.ts (1 hunks)
  • packages/renderless/src/picker/index.ts (3 hunks)
  • packages/renderless/src/time-panel/index.ts (1 hunks)
  • packages/renderless/src/time-panel/vue.ts (1 hunks)
  • packages/theme-saas/src/time-select/index.less (2 hunks)
  • packages/theme/src/time-select/index.less (2 hunks)
  • packages/vue/src/time-panel/src/pc.vue (1 hunks)
🔇 Additional comments (15)
examples/sites/demos/pc/app/time-select/range-placeholder.spec.ts (4)

11-11: Adjustment of maximum time index seems correct.
Increasing the index from 43 to 44 likely aligns with the newly computed list size of time options.


13-13: Updated selection index for start time.
Switching the click action from options.nth(9) to options.nth(10) reflects the added option in the list.


20-20: Adjustment of end-time maximum index is consistent.
Increasing the index to 44 ensures alignment with the newly lengthened time list.


22-23: Disabled check and selection of subsequent time slot.
Verifies that options.nth(10) is disabled before clicking nth(11) for selection. This helps ensure correct time boundaries.

packages/renderless/src/picker/index.ts (3)

548-552: User input filtering for time-select.
Setting isFilter to true and assigning filterVal to userInput dynamically adjusts the time panel items. This is a clean approach; ensure large data sets remain performant if time options are numerous.


995-999: Validating time-select user input upon Enter key.
This regex check restricts user entries to 0-24, and if valid, uses the first matching item. Consider clarifying edge cases like "24:00" or partially entered times ("2").


1024-1027: Resetting filter state on picker hide.
Clearing state.isFilter prevents stale filtering on the next open, which is good. Keep in mind potential scenarios if the user reopens shortly and expects the prior filter — but logically, this reset is consistent with typical UX patterns.

packages/theme-saas/src/time-select/index.less (5)

4-5: New prefix variables defined.
The introduction of @picker-panel-prefix-cls and @time-select-scrollbar-cls keeps naming consistent and flexible.


9-11: .noMatchHeight class addition.
Setting a height of 36px for the no-match scenario helps maintain a consistent layout.


12-13: Height and top padding for time-select container.
A 242px height with 8px top padding likely ensures correct spacing for the new item listing.


14-16: Scrollbar height adjustment.
Ensuring the scrollbar takes full height is a neat improvement for usability.


53-59: Styling for .noMatch state.
Centering text for the no-match condition (text-align: center) is good for user feedback.

packages/vue/src/time-panel/src/pc.vue (2)

18-18: LGTM! Good use of dynamic class binding

The conditional class binding is well implemented, providing appropriate styling feedback based on the items state.


38-38: LGTM! Good use of internationalization

The "no match" message is properly internationalized using the translation system.

packages/theme/src/time-select/index.less (1)

27-27: LGTM! Good improvements to layout flexibility

The use of CSS variables for padding and changing scrollbar height to 100% improves the component's flexibility and maintainability.

Also applies to: 29-29

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.

3 participants