Skip to content

Conversation

@aaryan610
Copy link
Member

@aaryan610 aaryan610 commented Mar 6, 2025

Description

This PR separates user favorites code for scalability.

Type of Change

  • Code refactoring

Summary by CodeRabbit

  • New Features

    • Enhanced sidebar favorites with dynamic icon assignments and personalized link generation.
    • Introduced a mechanism to retrieve additional details for favorite items.
  • Refactor

    • Streamlined favorites display logic by replacing static mappings with dynamic configurations.
    • Aligned favorites-related configurations across parts of the application for improved maintainability.
    • Added new exports for sidebar favorites functionality, improving accessibility across modules.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request introduces new functionality related to sidebar favorites, including new files and export statements in both the CE and EE directories. It defines constants and hooks for managing favorite item icons and links. The helper functions for retrieving icons and generating links have been refactored to utilize dynamic mappings, and hooks have been updated to provide additional details when processing favorite items.

Changes

File(s) Change Summary
web/ce/constants/index.ts, web/ee/constants/index.ts Added new export statement (export * from "./sidebar-favorites";) to centralize sidebar favorites exports.
web/ce/constants/sidebar-favorites.ts, web/ee/constants/sidebar-favorites.ts Introduced new file(s) that define/re-export constants: FAVORITE_ITEM_ICONS and FAVORITE_ITEM_LINKS for mapping favorite types to icons and link generators.
web/ce/hooks/use-additional-favorite-item-details.ts, web/ee/hooks/use-additional-favorite-item-details.ts Added new hook file(s) to export useAdditionalFavoriteItemDetails, which provides additional details for favorite items.
web/core/components/.../helper.tsx Refactored getFavoriteItemIcon and generateFavoriteItemLink to dynamically retrieve icons and generate links using the new constants, with default fallbacks.
web/core/hooks/use-favorite-item-details.tsx Refactored hook to use destructuring and integrated getAdditionalFavoriteItemDetails for enhanced favorite item detail extraction.

Sequence Diagram(s)

sequenceDiagram
    participant UI as UI Component
    participant DetailsHook as useFavoriteItemDetails
    participant AddDetails as useAdditionalFavoriteItemDetails
    participant Helper as Helper Functions
    UI->>DetailsHook: Request favorite item details
    DetailsHook->>AddDetails: Call getAdditionalFavoriteItemDetails(workspaceSlug, favorite)
    AddDetails->>Helper: Retrieve icon via getFavoriteItemIcon
    Helper-->>AddDetails: Return matching icon (or default)
    AddDetails-->>DetailsHook: Return additional details (icon, title)
    DetailsHook-->>UI: Provide enhanced favorite item details (including link)
Loading

Suggested labels

🧹chore, 🌟improvement

Suggested reviewers

  • sriramveeraghanta
  • SatishGandham
  • prateekshourya29

Poem

Hoppity hop, the code now sings,
With new hooks and links of wondrous things.
Icons and details spring to light,
A rabbit’s joy in every byte.
Celebrating change with a twitch of delight!
🐰✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5669156 and 04c42d8.

📒 Files selected for processing (1)
  • web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (4)
web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (4)

2-9: Good refactoring of imports for better code organization.

Moving from hardcoded values to centralized constants improves maintainability and scales better. The imports are well-organized with clear separation between external libraries, types, and internal constants.


11-28: Improved icon handling with dynamic mapping and fallback.

The refactored implementation now dynamically retrieves icons from constants and provides a sensible default (FileText) when no match is found. This makes the code more maintainable and extensible for new favorite item types.


30-36: Fixed potential runtime error with proper error handling.

You've properly addressed the previous review comment by adding a safety check when the entity type isn't recognized. This prevents potential runtime errors and provides a sensible fallback.


38-44: Clear and structured link generation logic.

The implementation now properly differentiates between workspace-level and project-level items with explicit conditions, making the code more readable and maintainable. The fallback case ensures the function always returns a valid URL.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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: 1

🧹 Nitpick comments (4)
web/ce/hooks/use-additional-favorite-item-details.ts (2)

6-26: Hook implementation could be enhanced

The hook creates a new function getAdditionalFavoriteItemDetails that currently only handles the default case with no specific cases in the switch statement. This suggests it's designed for extensibility, but the current implementation seems incomplete.

Consider either:

  1. Adding specific cases to the switch statement for different entity types, or
  2. Adding a comment explaining that specific cases will be handled in the future or by EE implementation.

Additionally, since the function doesn't currently use the _workspaceSlug parameter (note the underscore prefix indicating it's unused), consider removing it until needed or documenting why it's there for future use.


14-19: Empty switch statement could be simplified

The switch statement currently only has a default case with no specific cases for different entity types.

Since there are no specific cases handled, you could simplify by removing the switch statement:

-    switch (favoriteItemEntityType) {
-      default:
-        itemTitle = favoriteItemName;
-        itemIcon = getFavoriteItemIcon(favoriteItemEntityType);
-        break;
-    }
+    itemTitle = favoriteItemName;
+    itemIcon = getFavoriteItemIcon(favoriteItemEntityType);

Or add a comment indicating that specific entity type handling will be added in the future.

web/ce/constants/sidebar-favorites.ts (1)

15-41: FAVORITE_ITEM_LINKS implementation looks good but could be improved

The FAVORITE_ITEM_LINKS constant provides a mapping for generating links to favorite items based on their type. This is a good abstraction that supports the code separation objective.

A few suggestions for improvement:

  1. The project item's getLink function doesn't use the favorite parameter, unlike the others. Consider unifying the pattern:
  project: {
    itemLevel: "project",
-   getLink: () => `issues`,
+   getLink: (_favorite) => `issues`,
  },
  1. Consider adding typing to the function parameters for consistency and better type checking:
-   getLink: (favorite) => `cycles/${favorite.entity_identifier}`,
+   getLink: (favorite: IFavorite) => `cycles/${favorite.entity_identifier}`,
  1. If folder exists in FAVORITE_ITEM_ICONS, consider adding it to FAVORITE_ITEM_LINKS as well for completeness.
web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (1)

14-27: Consider consolidating repeated icon usage to reduce duplication.

You render the same <Icon> component in both the hover-visible and hover-hidden blocks. Although this is a valid pattern for showing different states on hover, you might consider encapsulating the shared <Icon> rendering into a helper function or component to reduce redundancy.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21d7a18 and 5669156.

📒 Files selected for processing (8)
  • web/ce/constants/index.ts (1 hunks)
  • web/ce/constants/sidebar-favorites.ts (1 hunks)
  • web/ce/hooks/use-additional-favorite-item-details.ts (1 hunks)
  • web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (1 hunks)
  • web/core/hooks/use-favorite-item-details.tsx (3 hunks)
  • web/ee/constants/index.ts (1 hunks)
  • web/ee/constants/sidebar-favorites.ts (1 hunks)
  • web/ee/hooks/use-additional-favorite-item-details.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • web/ee/constants/sidebar-favorites.ts
  • web/ee/constants/index.ts
  • web/ee/hooks/use-additional-favorite-item-details.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (10)
web/ce/constants/index.ts (1)

5-5: New export for sidebar-favorites constants

This change adds an export for the newly created sidebar-favorites constants, making them accessible throughout the application. The addition aligns with the PR objective of separating code related to user favorites.

web/ce/hooks/use-additional-favorite-item-details.ts (1)

1-5: Imports look good

The imports are properly organized with clear separation between Plane types and components.

web/ce/constants/sidebar-favorites.ts (2)

1-5: Imports are well-organized

Good job on organizing imports with clear separation between third-party libraries and internal Plane imports.


6-13: Constants for favorite item icons defined clearly

The FAVORITE_ITEM_ICONS constant provides a clear mapping between entity types and their respective icons, which supports the code separation objective.

web/core/hooks/use-favorite-item-details.tsx (4)

14-14: New import for additional favorite item details

Good addition of the import for the new hook that provides additional favorite item details.


17-21: Improved object destructuring

The change from individual assignments to object destructuring improves code readability and maintainability.


28-29: Additional details hook integration

Good addition of the hook that provides additional favorite item details, enhancing the modularity of the codebase.


65-69: Refactored default case with additional details hook

The default case now uses the getAdditionalFavoriteItemDetails function from the new hook, which is a good abstraction that supports the code separation objective.

web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (2)

11-12: Great fallback for undefined icon types.

Using FAVORITE_ITEM_ICONS[type] || FileText ensures there’s always a valid icon even if the type isn’t recognized. Nicely done!


33-39:

Details

❓ Verification inconclusive

Verify that favorite.project_id is defined for project-level entities.

When entityLinkDetails.itemLevel is "project", the code appends favorite.project_id in the URL. Consider verifying that favorite.project_id is indeed set for all project-level items:


🏁 Script executed:

#!/bin/bash
# Description: Search for all references to `favorite.project_id`
# to check if the code guarantees it is never null or undefined for project-level items
rg -A 5 "favorite.project_id"

Length of output: 1051


Action Required: Confirm favorite.project_id Presence for Project-Level Entities

  • In web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx, the URL for project-level items is built using favorite.project_id without an explicit fallback.
  • However, in web/core/hooks/use-favorite-item-details.tsx a fallback (favorite.project_id ?? "") is used when invoking getProjectById, suggesting that there may be cases when favorite.project_id is undefined.
  • Please verify that for every project-level entity the favorite.project_id is reliably defined. If there’s any possibility it might be undefined, consider applying a consistent fallback or an explicit validation in the URL generation logic.

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

🧹 Nitpick comments (2)
web/ce/constants/sidebar-favorites.ts (1)

6-13: Consider adding type safety for the keys in FAVORITE_ITEM_ICONS

The record definition could benefit from using a union type for the keys to ensure only valid types are used, making the code more robust against typos and future modifications.

-export const FAVORITE_ITEM_ICONS: Record<string, React.FC<ISvgIcons> | LucideIcon> = {
+type FavoriteItemType = "page" | "project" | "view" | "module" | "cycle" | "folder";
+export const FAVORITE_ITEM_ICONS: Record<FavoriteItemType, React.FC<ISvgIcons> | LucideIcon> = {
  page: FileText,
  project: Briefcase,
  view: Layers,
  module: DiceIcon,
  cycle: ContrastIcon,
  folder: FavoriteFolderIcon,
};
web/ce/hooks/use-additional-favorite-item-details.ts (1)

7-21: Simplify the switch statement and clarify unused parameter

The switch statement only has a default case, which makes it unnecessarily complex. Also, the _workspaceSlug parameter is prefixed with an underscore suggesting it's not used, but there's no indication of its intended purpose.

-  const getAdditionalFavoriteItemDetails = (_workspaceSlug: string, favorite: IFavorite) => {
+  const getAdditionalFavoriteItemDetails = (workspaceSlug: string, favorite: IFavorite) => {
    const { entity_type: favoriteItemEntityType } = favorite;
    const favoriteItemName = favorite?.entity_data?.name || favorite?.name;

    let itemIcon;
    let itemTitle;

-    switch (favoriteItemEntityType) {
-      default:
-        itemTitle = favoriteItemName;
-        itemIcon = getFavoriteItemIcon(favoriteItemEntityType);
-        break;
-    }
+    // Set default values (can be expanded with specific cases in the future)
+    itemTitle = favoriteItemName;
+    itemIcon = getFavoriteItemIcon(favoriteItemEntityType);
+    
    return { itemIcon, itemTitle };
  };

The structure is likely in place to allow for future expansion with specific entity type handling, but for now, it can be simplified.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 21d7a18 and 5669156.

📒 Files selected for processing (8)
  • web/ce/constants/index.ts (1 hunks)
  • web/ce/constants/sidebar-favorites.ts (1 hunks)
  • web/ce/hooks/use-additional-favorite-item-details.ts (1 hunks)
  • web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (1 hunks)
  • web/core/hooks/use-favorite-item-details.tsx (3 hunks)
  • web/ee/constants/index.ts (1 hunks)
  • web/ee/constants/sidebar-favorites.ts (1 hunks)
  • web/ee/hooks/use-additional-favorite-item-details.ts (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • web/ee/constants/index.ts
  • web/ee/hooks/use-additional-favorite-item-details.ts
  • web/ee/constants/sidebar-favorites.ts
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (8)
web/ce/constants/index.ts (1)

5-5: Clean export addition. Looks good!

The code adds a new export statement for the sidebar-favorites module, making the associated constants available through the main index file. This follows the established pattern of the other exports in the file.

web/core/hooks/use-favorite-item-details.tsx (3)

17-21: Good refactoring to use destructuring

The change to use destructuring for extracting properties from the favorite object makes the code cleaner and more maintainable. This is a good improvement.


28-29: Clean integration of the additional details hook

Adding the hook to handle additional favorite item details follows good separation of concerns and makes the code more extensible.


65-69: Well-structured default case

The default case is now properly enclosed in braces and uses the new hook to get additional details. This provides a clear extension point for handling new favorite item types in the future.

web/core/components/workspace/sidebar/favorites/favorite-items/common/helper.tsx (4)

2-9: Good job on improved import organization and code separation

The separation of constants into dedicated imports from @/plane-web/constants aligns perfectly with the PR objective of enhancing code scalability through separation of favorite-related code.


11-13: Well-implemented dynamic icon resolution

Good implementation of dynamic icon lookup with a fallback. Using FAVORITE_ITEM_ICONS[type] || FileText provides both flexibility and safety when handling unknown types.


14-27: Clean UI implementation with hover states

The component structure with conditional group-hover states creates a nice UI experience. The conditional logo rendering based on logo.in_use is also well implemented.


30-39: Improved link generation with clear level-based structure

The refactored link generation using the itemLevel property significantly improves code readability and maintainability. The three distinct paths (workspace, project, and default) are clearly handled with appropriate routing patterns.

@sriramveeraghanta sriramveeraghanta changed the title chore: code separation for favorites refactor: favorites sidebar implementation Mar 7, 2025
@sriramveeraghanta sriramveeraghanta merged commit cb344ea into preview Mar 7, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the refactor/sidebar-favorites branch March 7, 2025 07:47
@sriramveeraghanta sriramveeraghanta added this to the v0.25.2 milestone Mar 9, 2025
@coderabbitai coderabbitai bot mentioned this pull request Mar 19, 2025
6 tasks
lifeiscontent pushed a commit that referenced this pull request Aug 18, 2025
* chore: code separation for favorites

* chore: error handling
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants