Skip to content

Comments

[WEB-2774] fix:favorites reorder#6179

Merged
pushya22 merged 2 commits intopreviewfrom
fix-favorties_reorder
Dec 11, 2024
Merged

[WEB-2774] fix:favorites reorder#6179
pushya22 merged 2 commits intopreviewfrom
fix-favorties_reorder

Conversation

@vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented Dec 10, 2024

Description

Fixed inconsistency while re-ordering favorites.
Refactored code in favorties store.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

References

WEB-2774

Summary by CodeRabbit

  • New Features

    • Enhanced drag-and-drop functionality for managing favorites.
    • Improved grouping and fetching of favorites based on workspace context.
  • Bug Fixes

    • Refined error handling for moving and reordering favorites.
  • Documentation

    • Added comments for clarity on favorite management actions.
  • Chores

    • Simplified control flow in favorite management methods, reducing complexity in error handling.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2024

Walkthrough

The changes in this pull request primarily focus on enhancing the functionality of the favorites feature within the application. Key modifications include the integration of the useFavorite hook in the FavoriteFolder component to manage grouped favorites, improvements to drag-and-drop interactions in both the FavoriteRoot and SidebarFavoritesMenu components, and adjustments to the FavoriteStore class methods for moving and reordering favorites. The overall control flow and rendering logic remain mostly intact, with a focus on refining user interactions and data management.

Changes

File Path Change Summary
web/core/components/workspace/sidebar/favorites/favorite-folder.tsx Added useFavorite hook to manage grouped favorites, updated useEffect dependencies, and enhanced drag-and-drop logic.
web/core/components/workspace/sidebar/favorites/root.tsx Enhanced drag-and-drop functionality, updated useEffect dependencies, and refined the getData function for item reordering.
web/core/components/workspace/sidebar/favorites/favorites-menu.tsx Restructured handleDrop function for better handling of moving favorites and reordering, with improved error handling and comments.
web/core/store/favorite.store.ts Simplified error handling in moveFavoriteToFolder, reOrderFavorite, and removeFromFavoriteFolder methods; modified getGroupedFavorites.

Possibly related PRs

Suggested labels

🌟improvement, 🧹chore, 🛠️refactor

Suggested reviewers

  • SatishGandham
  • rahulramesha

Poem

In the sidebar where favorites dwell,
A folder's charm casts a spell.
With drag and drop, we dance and play,
Grouping treasures in a new way.
Hops of joy, a UI delight,
Our favorites shine, so bold and bright! 🐰✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 86e1285 and 4bbf7e1.

📒 Files selected for processing (1)
  • web/core/store/favorite.store.ts (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/core/store/favorite.store.ts

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. (Experiment)
  • @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: 4

🧹 Outside diff range and nitpick comments (3)
web/core/components/workspace/sidebar/favorites/favorites-menu.tsx (1)

93-110: Improve clarity and reduce code duplication in handleDrop function

The handleDrop function contains similar logic for handling reordering and moving favorites in multiple places. Refactoring this logic can improve readability and maintainability.

Suggested refactor:

Consolidate the conditions and function calls to reduce duplication:

        if (isFolder) {
          // handle move to a new parent folder if dropped on a folder
          if (parentId && parentId !== sourceData.parentId) {
            handleMoveToFolder(sourceData.id, parentId); /** parent id */
          }
        }

        if (droppedFavId) {
          if (instruction !== "make-child") {
            handleReorder(sourceData.id, droppedFavId, instruction); /** sequence */
          }
        }

        /** Remove if dropped outside and source is a child */
        if (!parentId && sourceData.isChild) {
          handleRemoveFromFavoritesFolder(sourceData.id); /** parent null */
        }

By reorganizing the conditions, the code becomes clearer and eliminates redundant calls.

web/core/components/workspace/sidebar/favorites/favorite-folder.tsx (2)

62-66: Potential unnecessary re-renders due to favorite.children in useEffect dependencies

Including favorite.children in the dependency array of the useEffect hook may lead to unnecessary re-renders because objects and arrays can trigger the effect when their reference changes, even if their contents are the same. Consider using a derived value or a stable identifier.

Suggested fix:

Use the length of favorite.children if you want to trigger the effect when the number of children changes:

-      }, [favorite.id, favorite.children, workspaceSlug, getGroupedFavorites]);
+      }, [favorite.id, favorite.children?.length, workspaceSlug, getGroupedFavorites]);

Alternatively, memoize favorite.children if applicable.


133-133: Duplicate dependency favorite.id in useEffect dependency array

The dependency favorite.id appears twice in the useEffect dependency array. This duplication is unnecessary and can be removed.

Suggested fix:

-      }, [isDragging, favorite.id, isLastChild, favorite.id]);
+      }, [isDragging, favorite.id, isLastChild]);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 205395e and 86e1285.

📒 Files selected for processing (4)
  • web/core/components/workspace/sidebar/favorites/favorite-folder.tsx (4 hunks)
  • web/core/components/workspace/sidebar/favorites/favorite-items/root.tsx (1 hunks)
  • web/core/components/workspace/sidebar/favorites/favorites-menu.tsx (1 hunks)
  • web/core/store/favorite.store.ts (3 hunks)

);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [elementRef?.current, isDragging]);
}, [elementRef?.current, isDragging, isLastChild, favorite.id]);
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Unnecessary dependency elementRef.current in useEffect

Including elementRef.current in the dependency array of the useEffect hook may cause unnecessary re-executions since changes to elementRef.current do not trigger re-renders. Consider removing elementRef.current from the dependency array.

Suggested fix:

-      }, [elementRef?.current, isDragging, isLastChild, favorite.id]);
+      }, [isDragging, isLastChild, favorite.id]);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
}, [elementRef?.current, isDragging, isLastChild, favorite.id]);
}, [isDragging, isLastChild, favorite.id]);

@vamsikrishnamathala vamsikrishnamathala marked this pull request as draft December 10, 2024 11:33
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@vamsikrishnamathala vamsikrishnamathala marked this pull request as ready for review December 10, 2024 11:42
@pushya22 pushya22 changed the title [WEB-1412]fix:favorites reorder [WEB-2774] fix:favorites reorder Dec 11, 2024
@pushya22 pushya22 merged commit 7fca7fd into preview Dec 11, 2024
@pushya22 pushya22 deleted the fix-favorties_reorder branch December 11, 2024 10:59
nishantPFM pushed a commit to Pocket-Fm/plane that referenced this pull request Dec 12, 2024
* fix:favorites reorder

* chore: added error handling

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Mar 19, 2025
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐛bug Something isn't working 🌐frontend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants