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

refactor(transfer): [transfer] refactor transfer by checkbox #2396

Merged
merged 2 commits into from
Oct 25, 2024

Conversation

shenjunjian
Copy link
Collaborator

@shenjunjian shenjunjian commented Oct 25, 2024

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

Release Notes

  • New Features

    • Updated the titles in the transfer component for improved clarity: "所有数据列表" to "数据列表" and "已选数据列表" to "已选列表".
    • Introduced a new <tiny-checkbox> component for enhanced checkbox functionality within the transfer panel.
  • Bug Fixes

    • Adjusted Playwright tests to reflect the updated checkbox labels.
  • Style

    • Simplified checkbox styles for better layout consistency and readability.

Copy link

coderabbitai bot commented Oct 25, 2024

Walkthrough

The changes in this pull request involve modifications to the titles displayed in the <tiny-transfer> component and its associated tests. The titles have been updated for conciseness, and the rendering of checkboxes has been simplified by replacing the previous structure with a <tiny-checkbox> component, enhancing maintainability. Additionally, CSS styles related to checkbox presentation have been altered, focusing on layout consistency.

Changes

File Path Change Summary
examples/sites/demos/pc/app/transfer/custom-titles-composition-api.vue Updated titles from ['所有数据列表', '已选数据列表'] to ['数据列表', '已选列表'].
examples/sites/demos/pc/app/transfer/custom-titles.spec.ts Adjusted expected text in Playwright tests to match new titles.
examples/sites/demos/pc/app/transfer/custom-titles.vue Updated titles from ['所有数据列表', '已选数据列表'] to ['数据列表', '已选列表'].
packages/theme/src/transfer/index.less Removed nested styles for @{checkbox-prefix-cls} and adjusted styles for &__filter.
packages/vue/src/transfer-panel/src/pc.vue Replaced checkbox structure with <tiny-checkbox>, simplifying rendering and state management.

Possibly related PRs

Suggested labels

refactoring

Suggested reviewers

  • zzcr
  • kagol

Poem

In the meadow where titles bloom,
We changed the names to lift the gloom.
Checkboxes now dance with ease,
Simplified styles, a gentle breeze.
Hopping along, we celebrate,
A transfer component that's truly great! 🐇✨


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 refactoring Refactoring (重构) label Oct 25, 2024
Copy link

[e2e-test-warn]
The component to be tested is missing.

The title of the Pull request should look like "fix(vue-renderless): [action-menu, alert] fix xxx bug".

Please make sure you've read our contributing guide

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

🧹 Outside diff range and nitpick comments (2)
examples/sites/demos/pc/app/transfer/custom-titles.spec.ts (1)

12-14: LGTM! Consider extracting expected texts as constants.

The test changes correctly reflect the new, more concise titles while maintaining proper validation of both title text and selection counts.

Consider extracting the expected texts as constants for better maintainability:

+ const LEFT_PANEL_TITLE = '数据列表'
+ const RIGHT_PANEL_TITLE = '已选列表'

- await expect(leftPanel.locator('.tiny-checkbox__label').first()).toHaveText(/数据列表/)
+ await expect(leftPanel.locator('.tiny-checkbox__label').first()).toHaveText(new RegExp(LEFT_PANEL_TITLE))
  await expect(leftPanel.locator('.tiny-checkbox__label').first()).toHaveText(/未勾选 \/ 共14/)
- await expect(rightPanel.locator('.tiny-checkbox__label').first()).toHaveText(/已选列表/)
+ await expect(rightPanel.locator('.tiny-checkbox__label').first()).toHaveText(new RegExp(RIGHT_PANEL_TITLE))
packages/vue/src/transfer-panel/src/pc.vue (1)

59-59: Consider using a more descriptive event handler name.

The event handler name 'checkedEvent' could be more descriptive.

- @change="checkedEvent(item[state.keyProp], item[state.disabledProp])"
+ @change="handleItemCheckChange(item[state.keyProp], item[state.disabledProp])"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d3c8944 and 446da7e.

📒 Files selected for processing (5)
  • examples/sites/demos/pc/app/transfer/custom-titles-composition-api.vue (1 hunks)
  • examples/sites/demos/pc/app/transfer/custom-titles.spec.ts (1 hunks)
  • examples/sites/demos/pc/app/transfer/custom-titles.vue (1 hunks)
  • packages/theme/src/transfer/index.less (0 hunks)
  • packages/vue/src/transfer-panel/src/pc.vue (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/theme/src/transfer/index.less
🔇 Additional comments (3)
examples/sites/demos/pc/app/transfer/custom-titles-composition-api.vue (1)

5-5: LGTM! The simplified titles improve UI conciseness.

The change from ['所有数据列表', '已选数据列表'] to ['数据列表', '已选列表'] makes the UI labels more concise while maintaining clarity.

Let's verify the consistency of these title changes across other transfer-related files:

✅ Verification successful

Title changes are consistently applied across transfer components

The verification shows that both transfer components using custom titles (custom-titles-composition-api.vue and custom-titles.vue) have been updated to use the new concise titles ['数据列表', '已选列表']. No instances of the old titles ['所有数据列表', '已选数据列表'] were found, confirming consistent implementation across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for consistent title usage across transfer components
# Expected: All transfer components should use the new concise titles

# Search for transfer title definitions
rg -l "tiny-transfer.*titles" --type vue

# Check the actual title content in these files
rg "titles=.*['\"]数据列表['\"].*['\"]已选列表['\"]" --type vue

Length of output: 164


Script:

#!/bin/bash
# Search for transfer title definitions without file type restriction
rg -l "tiny-transfer.*titles"

# Check the actual title content in these files
rg "titles=.*['\"]数据列表['\"].*['\"]已选列表['\"]"

# Also search for the old titles to compare
rg "titles=.*['\"]所有数据列表['\"].*['\"]已选数据列表['\"]"

Length of output: 333

examples/sites/demos/pc/app/transfer/custom-titles.vue (1)

5-5: LGTM! The title changes improve conciseness.

The simplified titles maintain clarity while being more concise, which aligns well with documentation best practices. The change preserves the semantic meaning while making the UI labels more user-friendly.

packages/vue/src/transfer-panel/src/pc.vue (1)

53-62: LGTM! Clean component-based checkbox implementation.

The refactor to use <tiny-checkbox> component improves code maintainability and follows Vue.js best practices.

Comment on lines +58 to +59
:checked="state.checked.length > 0 && state.checked.indexOf(item[state.keyProp]) > -1"
@change="checkedEvent(item[state.keyProp], item[state.disabledProp])"
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 optimizing checked state lookup performance.

The current implementation uses array indexOf for checking item state, which could be inefficient for large datasets.

Consider using a Set or Map for O(1) lookup:

- :checked="state.checked.length > 0 && state.checked.indexOf(item[state.keyProp]) > -1"
+ :checked="state.checkedSet.has(item[state.keyProp])"

You'll need to maintain a Set alongside the array in your component's state:

const checkedSet = computed(() => new Set(state.checked))

<option-content :option="optionRender(item)"></option-content>
</span>
</label>
<option-content :option="optionRender(item)"></option-content>
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 memoizing option rendering.

The direct call to optionRender in the template could cause unnecessary re-renders.

Consider memoizing the option render result:

- <option-content :option="optionRender(item)"></option-content>
+ <option-content :option="getMemoizedOption(item)"></option-content>

Add a computed or cached method:

const getMemoizedOption = computed(() => {
  const cache = new Map()
  return (item) => {
    if (!cache.has(item[state.keyProp])) {
      cache.set(item[state.keyProp], optionRender(item))
    }
    return cache.get(item[state.keyProp])
  }
})

@shenjunjian shenjunjian changed the title refactor(transfer): refactor transfer by checkbox refactor(transfer): [transfer] refactor transfer by checkbox Oct 25, 2024
@zzcr zzcr merged commit 1fa5c04 into opentiny:dev Oct 25, 2024
7 of 8 checks passed
@shenjunjian shenjunjian deleted the refactor-transfer-checkbox branch November 7, 2024 02:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Refactoring (重构)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants