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

perf: optimization of tabbar display #4169

Merged
merged 4 commits into from
Aug 16, 2024
Merged

perf: optimization of tabbar display #4169

merged 4 commits into from
Aug 16, 2024

Conversation

anncwb
Copy link
Collaborator

@anncwb anncwb commented Aug 16, 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

    • Introduced a new type EmitType for enhanced event handling.
    • Enhanced scrollbar component with customizable shadow effects based on scroll position.
    • Added drag-and-drop functionality for tabs with improved tab management.
  • Improvements

    • Streamlined lifecycle management of ResizeObserver in content styles.
    • Updated tab animation duration for a smoother user experience.
    • Enhanced tab component interfaces for better configuration and event handling.
  • Bug Fixes

    • Improved merging logic for tab metadata to preserve existing attributes during updates.
  • Documentation

    • Updated route metadata for dynamic internationalization.

@anncwb anncwb requested a review from vince292007 as a code owner August 16, 2024 13:51
Copy link

changeset-bot bot commented Aug 16, 2024

⚠️ No Changeset found

Latest commit: ecd782d

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 Aug 16, 2024

Warning

Rate limit exceeded

@anncwb has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 13 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between 4dae9a7 and ecd782d.

Walkthrough

This update enhances the functionality and maintainability of various components within the codebase. Key changes include improved type definitions, streamlined scrollbar behavior, enhanced tab management with drag-and-drop capabilities, and an internationalized routing metadata system. Overall, these modifications refine user interactions and optimize component lifecycle management, contributing to a more dynamic and responsive application.

Changes

File Path Summary of Changes
packages/@core/base/typings/src/helper.d.ts Introduced EmitType for event handling; updated export syntax for better readability.
packages/@core/composables/src/use-content-style.ts Improved ResizeObserver lifecycle management; streamlined observer setup and added cleanup on unmount.
packages/@core/composables/src/use-sortable.ts Adjusted Sortable animation duration from 100 to 300 for smoother transitions.
packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue Added props for shadow visibility based on scroll position; improved event emission for scroll states.
packages/@core/ui-kit/tabs-ui/package.json Added @vueuse/core dependency for enhanced functionality.
packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue Removed width constraints; simplified scrolling behavior; integrated context menus with tabs.
packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue Removed scrolling logic; improved transition performance; simplified template structure.
packages/@core/ui-kit/tabs-ui/src/tabs-view.vue Refactored tab management; encapsulated dragging functionality; simplified event emission logic.
packages/@core/ui-kit/tabs-ui/src/types.ts Added TabsEmits interface for event handling; modified TabsProps for flexibility; exported new types.
packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts Introduced a composable for managing draggable tabs; encapsulated drag-and-drop logic.
packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts Enhanced scrolling management; refactored function to accept TabsProps.
packages/stores/src/modules/tabbar.ts Improved merging logic for tab metadata during updates to preserve and update relevant attributes.
playground/src/router/routes/modules/demos.ts Updated route title to use a translation function for better internationalization.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant TabsComponent
    participant DragManager
    participant TabStore

    User->>TabsComponent: Selects tab
    TabsComponent->>TabStore: Update active tab
    TabStore-->>TabsComponent: Active tab updated
    TabsComponent->>DragManager: Initialize drag
    DragManager->>TabsComponent: Tab reordered
    TabsComponent->>TabStore: Update tab order
    TabStore-->>TabsComponent: Order updated
Loading

🐇 In the meadow, change does bloom,
With tabs that dance and shadows loom.
The bunnies cheer, a joyful sight,
As code transforms to pure delight!
So hop along, let’s celebrate,
New features here, let’s elevate! 🌼✨


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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

Outside diff range, codebase verification and nitpick comments (4)
packages/@core/base/typings/src/helper.d.ts (1)

110-110: Define or Import Name Type

The Name type used in the EmitType definition is neither defined nor imported in the codebase. To ensure type safety and clarity, please define the Name type or ensure it is imported where needed.

  • Location to Update: packages/@core/base/typings/src/helper.d.ts at line 110
Analysis chain

Define Name type or ensure it's imported.

The EmitType definition uses Name, which should be defined or imported to ensure type safety and clarity.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if `Name` type is defined or imported in the codebase.

# Test: Search for the definition or import of `Name`. Expect: Definition or import statement.
rg --type typescript 'type Name|import {.*Name.*} from'

Length of output: 190


Script:

#!/bin/bash
# Description: Verify if `Name` type is defined or imported in the codebase.

# Test: Search for the definition or import of `Name`. Expect: Definition or import statement.
rg --type typescript 'type Name|import \{.*Name.*\} from'

Length of output: 94


Script:

#!/bin/bash
# Description: Verify if `Name` type is defined or imported in the codebase.

# Test: Search for the definition or import of `Name`. Expect: Definition or import statement.
rg --glob '*.ts' --glob '*.d.ts' 'type Name|import \{.*Name.*\} from'

Length of output: 464

packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts (1)

9-15: Clarify the purpose of findParentElement.

The function findParentElement is designed to find the nearest parent element with the class group. Ensure that this logic aligns with the intended DOM structure and that the class name is not too generic, which might lead to unexpected results if used in a broader context.

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

64-126: Evaluate the impact of removing automatic scrolling.

The removal of the scrollIntoView function and related watch logic may affect user experience. Consider whether manual navigation is sufficient or if alternative solutions should be explored.

Consider implementing a manual scroll button or indicator to guide users when navigating through tabs.

playground/src/router/routes/modules/demos.ts (1)

164-164: Missing translation key in locale files.

The translation key page.demos.features.hideChildrenInMenu is used in the code but is not defined in any locale files. Ensure that this key is added to all necessary locale files to support internationalization.

  • Verify the presence of page.demos.features.hideChildrenInMenu in all locale files.
Analysis chain

Internationalization enhancement approved.

The change to use the translation function $t('page.demos.features.hideChildrenInMenu') for the route title improves the application's internationalization capabilities.

Ensure that the translation key page.demos.features.hideChildrenInMenu is correctly defined in all necessary locale files.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the translation key is defined in all locale files.

# Test: Search for the translation key in locale files. Expect: The key should be present in all locale files.
rg --type json --type yaml $'"page.demos.features.hideChildrenInMenu"'

Length of output: 71


Script:

#!/bin/bash
# Description: Perform a comprehensive search for the translation key in all files to ensure it is defined somewhere in the codebase.

# Test: Search for the translation key in all files. Expect: The key should be found in some file.
rg 'page\.demos\.features\.hideChildrenInMenu'

Length of output: 286

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8987067 and 4dae9a7.

Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
Files selected for processing (13)
  • packages/@core/base/typings/src/helper.d.ts (1 hunks)
  • packages/@core/composables/src/use-content-style.ts (3 hunks)
  • packages/@core/composables/src/use-sortable.ts (1 hunks)
  • packages/@core/ui-kit/shadcn-ui/src/components/scrollbar/scrollbar.vue (4 hunks)
  • packages/@core/ui-kit/tabs-ui/package.json (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs-chrome/tabs.vue (5 hunks)
  • packages/@core/ui-kit/tabs-ui/src/components/tabs/tabs.vue (3 hunks)
  • packages/@core/ui-kit/tabs-ui/src/tabs-view.vue (2 hunks)
  • packages/@core/ui-kit/tabs-ui/src/types.ts (2 hunks)
  • packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts (1 hunks)
  • packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts (3 hunks)
  • packages/stores/src/modules/tabbar.ts (1 hunks)
  • playground/src/router/routes/modules/demos.ts (1 hunks)
Additional comments not posted (21)
packages/@core/composables/src/use-sortable.ts (1)

21-21: Increased animation duration in useSortable.

The animation property has been increased from 100 to 300, which will make the sorting animation appear slower and potentially smoother. This change can enhance user experience by making element movements more perceptible.

packages/@core/ui-kit/tabs-ui/src/types.ts (3)

4-8: Enhanced event handling with TabsEmits.

The new TabsEmits interface introduces events for close, sortTabs, and unpin, allowing more granular control over tab interactions. This enhancement improves the flexibility and responsiveness of the tab component.


10-11: Improved state management with active property in TabsProps.

The addition of the optional active property to TabsProps allows for better management of the currently active tab, enhancing the component's flexibility and usability.


58-58: Explicit export of TabConfig interface.

The TabConfig interface is now explicitly exported, which facilitates its use in other modules. This change promotes better integration and reuse of tab configurations across the application.

packages/@core/ui-kit/tabs-ui/package.json (1)

44-44: Added @vueuse/core dependency.

The addition of @vueuse/core with version ^10.11.1 indicates the use of VueUse utilities, which can enhance functionality or improve the development experience within the UI components.

packages/@core/base/typings/src/helper.d.ts (1)

112-128: Consolidate export statements for readability.

The use of export type { ... } improves readability by consolidating all exported types into a single statement. This is a good practice for maintaining clean and manageable code.

packages/@core/ui-kit/tabs-ui/src/tabs-view.vue (3)

24-24: Update emit function to use TabsEmits.

The change to use TabsEmits in defineEmits enhances type safety for emitted events. Ensure that TabsEmits accurately reflects the events being emitted.


37-37: Utilize useTabsDrag for drag-and-drop functionality.

The introduction of useTabsDrag modularizes the drag-and-drop logic, improving maintainability and readability. Ensure that useTabsDrag is correctly implemented and tested.


2-2: Ensure TabsEmits and TabsProps are correctly defined.

The imports of TabsEmits and TabsProps are crucial for type safety. Verify that these are correctly defined and imported from the appropriate module.

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

14-17: Add default values for new shadow props.

The new shadow props (shadowBottom, shadowLeft, shadowRight, shadowTop) are added to the Props interface. Ensure that these props have appropriate default values set in withDefaults to prevent undefined behavior.


31-33: Verify the new scrollAt event usage.

The scrollAt event emits the scroll position details. Ensure that this event is handled correctly in the parent components and that the emitted data is used as expected.

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

24-27: Confirm event signature changes.

The emit function's signature has been slightly reformatted. Ensure that this change does not affect the event handling logic in parent components.

packages/@core/ui-kit/tabs-ui/src/use-tabs-view-scroll.ts (5)

20-28: Function getScrollClientWidth is correctly implemented.

The function accurately calculates and returns the scrollbar and scroll view widths.


Line range hint 29-47:
Function scrollDirection is correctly implemented.

The function provides smooth scrolling in the specified direction with a default distance.


Line range hint 48-105:
Function initScrollbar is correctly implemented.

The function effectively initializes the scrollbar and sets up observers for dynamic updates.


106-123: Function scrollToActiveIntoView is correctly implemented.

The function efficiently scrolls the active tab into view using requestAnimationFrame.


11-19: LGTM! Verify usage of the new function signature.

The transition to using TabsProps enhances configurability. Ensure that all instances where useTabsViewScroll is used are updated to match the new signature.

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

Line range hint 6-29:
Script section changes are correctly implemented.

The removal of maxWidth and minWidth props suggests a shift to a more flexible layout. The computed properties are well-defined.


59-147: Template section changes are correctly implemented.

The integration of VbenContextMenu and the use of utility classes improve flexibility and user interaction.


Line range hint 153-187:
Style section changes are correctly implemented.

The use of utility classes and scoped styles ensures consistent styling and maintainability.

packages/stores/src/modules/tabbar.ts (1)

127-141: Function addTab is correctly implemented.

The new approach to merging meta properties ensures that existing metadata is preserved and updated correctly.

packages/@core/composables/src/use-content-style.ts Outdated Show resolved Hide resolved
packages/@core/composables/src/use-content-style.ts Outdated Show resolved Hide resolved
packages/@core/ui-kit/tabs-ui/src/use-tabs-drag.ts Outdated Show resolved Hide resolved
@anncwb anncwb requested a review from a team as a code owner August 16, 2024 14:06
@anncwb anncwb merged commit 0faf781 into main Aug 16, 2024
15 checks passed
@anncwb anncwb deleted the perf/tabs-scroll branch August 16, 2024 14:20
@anncwb anncwb added the perf label Aug 16, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant