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: limit the drag range of tabs, fixed #4640 #4659

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

mynetfan
Copy link
Collaborator

@mynetfan mynetfan commented Oct 17, 2024

Description

限制标签栏的拖拽范围,只能在同类型的标签之间拖拽:固定标签不能拖拽到非固定标签中,非固定标签也不能拖拽到固定标签中。

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 styling for affixed tabs with a new affix-tab class.
    • Improved drag-and-drop functionality for tab management, preventing dragging between fixed and non-fixed tabs.
  • Bug Fixes

    • Refined logic for determining tab drag operations to ensure smoother user experience.

Copy link

changeset-bot bot commented Oct 17, 2024

⚠️ No Changeset found

Latest commit: 6b63506

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Oct 17, 2024

Walkthrough

The changes in this pull request focus on enhancing the tab components within the UI kit. Modifications include the introduction of a new class affix-tab for tab items based on the affixTab property, improving the visual representation of affixed tabs. Additionally, the drag-and-drop functionality in use-tabs-drag.ts has been refined to prevent dragging between affixed and non-affixed tabs. The overall structure and existing functionalities of the components remain unchanged.

Changes

File Path Change Summary
packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue Expanded class bindings for tab items to include affix-tab conditionally based on tab.affixTab.
packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue Added affix-tab class for tab items, updated tabsView computed property, and clarified closable tab logic.
packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts Enhanced drag-and-drop logic to prevent dragging between affixed and non-affixed tabs in the onMove event handler.

Possibly related PRs

Suggested reviewers

  • vince292007
  • anncwb

🐰 In the land where tabs do play,
Affixed ones shine in a special way.
With drag-and-drop now refined,
No mix-ups shall you find!
So hop along, and take a look,
These changes make our tabs a book! 📚✨


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.

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

🧹 Outside diff range and nitpick comments (3)
packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts (1)

84-91: Enhance robustness of tab dragging logic

The implementation successfully limits dragging between fixed and non-fixed tabs, aligning with the PR objectives. However, consider the following improvements for increased robustness:

  1. Add a fallback for cases where the affix-tab class might be missing:
- const isCurrentAffix = evt.dragged.classList.contains('affix-tab');
- const isRelatedAffix = evt.related.classList.contains('affix-tab');
+ const isCurrentAffix = evt.dragged.classList.contains('affix-tab') || false;
+ const isRelatedAffix = evt.related.classList.contains('affix-tab') || false;
  1. Consider adding logging for unexpected scenarios:
  if (parent?.classList.contains('draggable') && props.draggable) {
    const isCurrentAffix = evt.dragged.classList.contains('affix-tab') || false;
    const isRelatedAffix = evt.related.classList.contains('affix-tab') || false;
+   if (isCurrentAffix !== isRelatedAffix) {
+     console.debug('Prevented dragging between fixed and non-fixed tabs');
+   }
    // 不允许在固定的tab和非固定的tab之间互相拖拽
    return isCurrentAffix === isRelatedAffix;
  } else {
+   console.debug('Drag prevented: parent not draggable or dragging disabled');
    return false;
  }

These changes will make the code more resilient to edge cases and provide better debugging information.

packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (1)

79-79: LGTM: Correctly applies the 'affix-tab' class

The addition of the 'affix-tab' class to the tab item div is well-implemented. It correctly uses the tab.affixTab property to conditionally apply the class, which allows for distinct styling of fixed tabs.

Consider adding a CSS rule for the 'affix-tab' class in your stylesheet to visually distinguish fixed tabs. For example:

.affix-tab {
  /* Add styles to visually indicate a fixed tab */
  font-weight: bold;
  /* or */
  border-bottom: 2px solid #your-color;
}

This will enhance the user experience by making it clear which tabs are fixed.

packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (1)

72-78: LGTM! Consider a minor readability improvement.

The addition of the 'affix-tab' class based on the tab.affixTab property aligns well with the PR objective of limiting the drag range for tabs. The existing logic for 'is-active' and 'draggable' classes remains intact, ensuring consistent behavior.

For improved readability, consider destructuring tab.affixTab at the beginning of the template. This would make the code more concise and easier to understand:

<template>
  <div
    v-for="(tab, i) in tabsView"
    :key="tab.key"
    ref="tabRef"
    :class="[
      {
        'is-active': tab.key === active,
        draggable: !affixTab,
        'affix-tab': affixTab,
      },
    ]"
    ...
  >
    <VbenContextMenu
      :handler-data="tab"
      :menus="contextMenus"
      :modal="false"
      item-class="pr-6"
    >
      <!-- Destructure affixTab here -->
      <template #default="{ affixTab }">
        <!-- Rest of the template -->
      </template>
    </VbenContextMenu>
  </div>
</template>

This change would make the class binding more concise and easier to read.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between a0fbe0b and 6b63506.

📒 Files selected for processing (3)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts (1 hunks)
🧰 Additional context used
🔇 Additional comments (4)
packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts (1)

Line range hint 1-141: Overall assessment: Implementation aligns with PR objectives

The changes successfully implement the feature to limit the drag range of tabs, preventing dragging between fixed and non-fixed tabs. The implementation is efficient and aligns well with the existing codebase structure.

A few minor improvements have been suggested to enhance robustness and debugging capabilities. These suggestions do not impact the core functionality but will make the code more resilient to edge cases.

Consider running additional tests to ensure the drag-and-drop functionality works as expected across various scenarios, including edge cases where the affix-tab class might be missing or incorrectly set.

To verify the implementation, please run the following script:

This script will help ensure that the affix-tab class is used consistently across the project and that related drag-and-drop functionality is properly implemented. It will also identify potential test files where you might want to add or update tests for this new feature.

✅ Verification successful

Follow-Up: Corrected Shell Scripts for Verification

The previous shell scripts encountered an issue with unrecognized file types for vue. Please run the following corrected scripts to continue the verification process:

These corrected scripts explicitly target .vue and .ts files, ensuring that Ripgrep searches the appropriate file types for the specified patterns. Please execute these scripts and provide the output to proceed with the verification.


Verification Complete: Changes Confirmed

The search results confirm that the 'affix-tab' class and drag-and-drop related code are correctly implemented in the specified files. Additionally, relevant test files are present to ensure functionality.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of 'affix-tab' class and drag-and-drop related code

# Test 1: Check for 'affix-tab' class usage
echo "Checking for 'affix-tab' class usage:"
rg --type vue --type typescript "affix-tab"

# Test 2: Verify drag-and-drop related code
echo "\nChecking for drag-and-drop related code:"
rg --type vue --type typescript -e "draggable" -e "onMove" -e "sortable"

# Test 3: Look for potential test files
echo "\nLooking for potential test files:"
fd -e spec.ts -e test.ts

Length of output: 2528


Script:

#!/bin/bash
# Corrected shell scripts to verify 'affix-tab' usage and drag-and-drop related code

# Test 1: Check for 'affix-tab' class usage in Vue and TypeScript files
echo "Checking for 'affix-tab' class usage:"
rg -g '*.vue' -g '*.ts' "affix-tab"

# Test 2: Verify drag-and-drop related code in Vue and TypeScript files
echo "\nChecking for drag-and-drop related code:"
rg -g '*.vue' -g '*.ts' -e "draggable" -e "onMove" -e "sortable"

# Test 3: Look for potential test files
echo "\nLooking for potential test files:"
fd -e spec.ts -e test.ts

Length of output: 7748

packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (2)

79-79: LGTM: Correctly implements the affixTab property

The addition of the affixTab property to each tab object in the tabsView computed property is well-implemented. It correctly uses the meta.affixTab value to determine if a tab is fixed, which aligns with the PR objective of distinguishing between fixed and non-fixed tabs.


Line range hint 1-158: Summary: Successfully implemented tab affixing feature

The changes in this file effectively implement the feature to distinguish between fixed and non-fixed tabs. The modifications are minimal, focused, and align well with the PR objectives. Both the script and template changes work together cohesively to add the necessary functionality.

Key points:

  1. The tabsView computed property now includes an affixTab property for each tab.
  2. The template correctly applies the 'affix-tab' class based on this new property.

These changes provide a solid foundation for limiting the drag range of tabs as per the PR description. The implementation follows Vue.js best practices and integrates smoothly with the existing codebase.

packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (1)

72-78: Changes align well with PR objectives and maintain component integrity.

The addition of the 'affix-tab' class enhances the styling capabilities for affixed tabs, supporting the PR objective of limiting the drag range for tabs. This change provides a visual distinction for affixed tabs without altering the existing functionality of tab interaction and rendering.

The modifications are focused and minimal, reducing the risk of unintended side effects. The changes maintain the integrity of the component while introducing the new feature as intended.

To ensure that these changes are properly integrated and don't conflict with other parts of the codebase, please run the following verification script:

This script will help identify any potential conflicts or areas that might need additional updates to fully implement the new feature.

✅ Verification successful

Changes align well with PR objectives and maintain component integrity.

The addition of the 'affix-tab' class enhances the styling capabilities for affixed tabs, supporting the PR objective of limiting the drag range for tabs. This change provides a visual distinction for affixed tabs without altering the existing functionality of tab interaction and rendering.

The verification scripts confirmed that there are no conflicting hardcoded 'affix-tab' classes outside the targeted component and that the affixTab property is used consistently across the codebase. Additionally, drag-and-drop functionalities related to tabs are appropriately managed without introducing any conflicts.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of 'affix-tab' class and related functionality

# Test 1: Check for any hardcoded 'affix-tab' classes that might conflict
echo "Checking for hardcoded 'affix-tab' classes:"
rg --type vue --type css 'class="[^"]*affix-tab' -g '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

# Test 2: Verify that 'affixTab' property is consistently used
echo "Verifying 'affixTab' property usage:"
rg --type vue --type ts 'affixTab' -g '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

# Test 3: Check for any drag-and-drop related functions that might need updating
echo "Checking drag-and-drop related functions:"
rg --type vue --type ts 'drag|drop' -g '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

Length of output: 708


Script:

#!/bin/bash
# Description: Verify the usage of 'affix-tab' class and related functionality

# Test 1: Check for any hardcoded 'affix-tab' classes that might conflict
echo "Checking for hardcoded 'affix-tab' classes:"
rg 'class="[^"]*affix-tab' -g "*.vue" -g "*.css" --glob '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

# Test 2: Verify that 'affixTab' property is consistently used
echo "Verifying 'affixTab' property usage:"
rg 'affixTab' -g "*.vue" -g "*.ts" --glob '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

# Test 3: Check for any drag-and-drop related functions that might need updating
echo "Checking drag-and-drop related functions:"
rg 'drag|drop' -g "*.vue" -g "*.ts" --glob '!packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue'

Length of output: 11377

@vince292007 vince292007 added the bug Something isn't working label Oct 17, 2024
@vince292007 vince292007 merged commit c432e0a into vbenjs:main Oct 17, 2024
14 checks passed
@anncwb anncwb changed the title feat: limit the drag range of tabs, fixed #4640 fix: limit the drag range of tabs, fixed #4640 Oct 18, 2024
GavinLucky pushed a commit to GavinLucky/vue-vben-admin that referenced this pull request Oct 23, 2024
@mynetfan mynetfan deleted the fix/tab-drag-limit branch November 5, 2024 02:44
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.

2 participants