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: manage widgets integrations #6331

Merged
merged 24 commits into from
Jan 7, 2025
Merged

fix: manage widgets integrations #6331

merged 24 commits into from
Jan 7, 2025

Conversation

gakshita
Copy link
Collaborator

@gakshita gakshita commented Jan 6, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced home dashboard widget system with new widget types.
    • Added support for dynamic widget ordering and configuration.
    • Improved data fetching for home dashboard widgets using SWR.
    • Introduced a new header component for the home page.
  • Improvements

    • Refined widget management with more precise type definitions.
    • Updated widget rendering logic to support enabling/disabling widgets.
    • Streamlined home dashboard component structure.
  • Technical Updates

    • Updated type definitions for home widget keys.
    • Implemented a more flexible widget reordering mechanism.
    • Enhanced state management for home dashboard widgets.

@gakshita gakshita marked this pull request as draft January 6, 2025 15:53
Copy link
Contributor

coderabbitai bot commented Jan 6, 2025

Walkthrough

This pull request introduces comprehensive changes to the home dashboard widget system across multiple files. The modifications primarily focus on enhancing the type safety and flexibility of widget management, introducing new widget keys, and refactoring the widget rendering and reordering logic. The changes span type definitions, component implementations, and store management, creating a more robust and extensible widget ecosystem.

Changes

File Change Summary
packages/types/src/home.d.ts Updated THomeWidgetKeys type with new widget keys and enforced stricter typing for TWidgetEntityData
web/core/components/home/home-dashboard-widgets.tsx Modified WIDGETS_LIST structure, added support for null components, and updated rendering logic
web/core/components/home/root.tsx Refactored data fetching using useSWR and simplified rendering logic
web/core/store/workspace/home.ts Enhanced HomeStore with typed widgets, added orderedWidgets computed property, and improved widget reordering logic
web/core/components/home/widgets/manage/* Updated drag-and-drop functionality, widget toggling, and list rendering
web/ee/components/home/header.tsx Introduced new HomePageHeader component

Possibly related PRs

Suggested Labels

🐛bug, 🌟improvement, ⚙️backend, 🧹chore

Suggested Reviewers

  • sriramveeraghanta
  • SatishGandham
  • rahulramesha

Poem

🐰 Widgets dance, keys align just right,
Reordering magic takes playful flight!
Types now strict, components so neat,
A dashboard symphony, oh so sweet!
CodeRabbit's touch makes interfaces bright! 🌈


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. (Beta)
  • @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.

@gakshita gakshita marked this pull request as ready for review January 6, 2025 16:16
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: 3

🧹 Nitpick comments (7)
web/core/components/home/widgets/manage/widget-list.tsx (3)

6-7: Leverage import compactness or named re-exports.

MobX’s observer and your custom setToast are well organized. If other modules also need these, consider a centralized re-export to simplify import statements across files.


30-43: Include error information in catch block.

You're showing a generic error toast if something goes wrong. Including the actual error message or logging it may help troubleshooting. For example:

} catch (error) {
  setToast({
    type: TOAST_TYPE.ERROR,
    title: "Error!",
-   message: "Error occurred while reordering widget.",
+   message: error instanceof Error ? error.message : "Error occurred while reordering widget.",
  });
}

60-60: Consider returning the component for non-React usage cases.

If there's a possibility of reusing WidgetList logic or data outside of React, you might factor out the reorder/toggle logic into a helper or store method for better modularity.

web/core/components/home/widgets/manage/widget.helpers.ts (2)

14-14: Docstring Tautology.
"the dragging widget data that is being dragged" is slightly repetitive. Consider simplifying this string.

- * @param source the dragging widget data that is being dragged on the dropTarget
+ * @param source the widget data currently being dragged onto the dropTarget

40-40: Typographical error in comment.
"cannon" should be "cannot."

- // if source that is being dragged is a group. A group cannon be a child of any other widget,
+ // if source that is being dragged is a group. A group cannot be a child of any other widget,
web/core/store/workspace/home.ts (1)

93-100: Debugging logs for reorder flow.
The log statements can be helpful for debugging. Consider removing them once stable.

web/core/components/home/widgets/manage/widget-item.tsx (1)

114-114: Reassess the disabled exhaustive-deps rule
You’ve disabled react-hooks/exhaustive-deps. Confirm that re-running this effect only when widget.key, isDragging, and isLastChild change is intended. If so, document the reason or restructure to avoid disabling this lint rule.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 790ecee and 8ae0503.

📒 Files selected for processing (16)
  • packages/types/src/home.d.ts (2 hunks)
  • web/core/components/home/home-dashboard-widgets.tsx (2 hunks)
  • web/core/components/home/root.tsx (4 hunks)
  • web/core/components/home/user-greetings.tsx (1 hunks)
  • web/core/components/home/widgets/links/links.tsx (1 hunks)
  • web/core/components/home/widgets/links/root.tsx (1 hunks)
  • web/core/components/home/widgets/loaders/loader.tsx (1 hunks)
  • web/core/components/home/widgets/manage/widget-item.tsx (4 hunks)
  • web/core/components/home/widgets/manage/widget-list.tsx (2 hunks)
  • web/core/components/home/widgets/manage/widget.helpers.ts (3 hunks)
  • web/core/components/home/widgets/recents/filters.tsx (1 hunks)
  • web/core/components/home/widgets/recents/index.tsx (1 hunks)
  • web/core/components/home/widgets/recents/page.tsx (1 hunks)
  • web/core/components/home/widgets/recents/project.tsx (1 hunks)
  • web/core/store/workspace/home.ts (6 hunks)
  • web/ee/components/home/header.tsx (1 hunks)
✅ Files skipped from review due to trivial changes (7)
  • web/ee/components/home/header.tsx
  • web/core/components/home/widgets/recents/filters.tsx
  • web/core/components/home/widgets/links/root.tsx
  • web/core/components/home/user-greetings.tsx
  • web/core/components/home/widgets/recents/project.tsx
  • web/core/components/home/widgets/links/links.tsx
  • web/core/components/home/widgets/recents/page.tsx
🔇 Additional comments (28)
packages/types/src/home.d.ts (1)

72-72: Great improvement using stricter typing.

Changing key: string to key: THomeWidgetKeys enforces compile-time checks and improves type safety.

web/core/components/home/home-dashboard-widgets.tsx (2)

28-28: Good use of store fields for better state management.

Extracting toggleWidgetSettings, widgetsMap, showWidgetSettings, and orderedWidgets from useHome() is a clean approach to keep widget state organized. No issues spotted here.


41-45: Conditional rendering looks solid.

The logic to only render widgets that have a valid component and are enabled is clear and efficient. Avoid rendering placeholders unless needed.

web/core/components/home/widgets/manage/widget-list.tsx (2)

12-13: Kudos for going fully reactive with observer.

Wrapping WidgetList with observer ensures seamless reaction to store updates. This approach eliminates stale UI states.


49-55: Dynamic rendering based on ordered widgets is well structured.

Using orderedWidgets.map(...) keeps the list flexible and sorted. Keys are set properly, and toggling the widget is straightforward. This approach is maintainable and scalable.

web/core/components/home/widgets/manage/widget.helpers.ts (3)

2-2: Imports appear consistent and aligned with new widget data types.
No issues with the modified import line.


48-53: Function documentation updated correctly.
The refactoring of param name from “favorite” to “widget” aligns with the new type usage. No functional issues identified.


58-59: Self-dropping condition is handled properly.
This guard prevents dropping a widget onto itself.

web/core/components/home/widgets/recents/index.tsx (3)

6-7: SWR and lucide-react imports look good.
No concerns here; usage is consistent with best practices for data fetching and icons.


10-13: Imports reorganization.
The updated imports for LayersIcon, WorkspaceService, EmptyWorkspace, and WidgetLoader maintain clarity.


17-17: Retained import for RecentProject.
The reference to RecentProject remains valid and consistent.

web/core/components/home/root.tsx (5)

4-4: Use of SWR for data fetching.
Switching to SWR can improve revalidation logic and performance. No issues identified.


14-14: Consolidated hooks import.
No problems with grouping additional hooks under a single import statement.


32-32: New store methods usage.
toggleWidgetSettings and fetchWidgets are more semantically accurate than the old method naming.


36-43: SWR config alignment.
Properly disabling revalidation in certain scenarios can reduce unnecessary calls. Looks effective and well-used here.


67-67: Joined project IDs check.
Rendering logic to show empty state or the widgets is clearly structured.

web/core/store/workspace/home.ts (6)

3-4: MobX and type imports are correct.
No issues spotted in the updated import statements.


12-14: Enhanced type specificity for widgets.
Changing from string[] to THomeWidgetKeys[] clarifies usage and helps maintain type safety.


28-28: Proper initialization of widgets.
Assigning an empty array of THomeWidgetKeys[] is consistent with the new type definition.


40-41: Computed property definition is structured correctly.
The orderedWidgets property is set up appropriately for MobX.


55-57: orderedWidgets computation.
Sorting widgets by descending sort_order ensures the correct display order.


67-67: Sorting before mapping.
Setting this.widgets based on sorted data ensures consistent ordering across the application.

web/core/components/home/widgets/manage/widget-item.tsx (6)

17-17: Anticipate undefined workspaceSlug
While useParams() typically provides workspaceSlug, there's a possibility it may be undefined. Consider adding a fallback or guard clause to avoid runtime issues for routes missing workspaceSlug.


30-33: Props update aligns well with new widget mapping
The new widgetId and handleToggle props cleanly separate widget identification from toggling logic, improving clarity and manageability.


48-48: Ensure widget is not undefined
widgetsMap[widgetId] could be undefined if the widgetId doesn’t exist in the store. Consider adding a check or fallback to avoid potential runtime errors.


Line range hint 55-72: Confirm widget.key stability for drag-and-drop
Using widget.key as the primary identifier in draggable operations is valid if widget.key remains stable across re-renders. If widget.key can change, or if there are potential conflicts, consider using a more unique or persistent ID.


130-130: Readable display transformation
Replacing underscores with spaces is a quick way to improve readability. This is a simple but effective enhancement for user-facing labels.


132-135: Validate toggle usage
Calling handleToggle(workspaceSlug.toString(), widget.key, !widget.is_enabled) is straightforward. However, confirm that workspaceSlug is always a valid, non-empty string to prevent undesired toggling behavior in edge-case routes.

import { QuickLinksWidgetLoader } from "./quick-links";
import { RecentActivityWidgetLoader } from "./recent-activity";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Potential mismatch between widget keys.

You are importing RecentActivityWidgetLoader and mapping it to EWidgetKeys.RECENT_ACTIVITY = "recent_activity", but in other files, the key "recents" is used. This mismatch may cause rendering or typing issues. Please ensure the widget key is consistently named across all files.

@@ -2,7 +2,7 @@ import { TLogoProps } from "./common";
import { TIssuePriorities } from "./issues";

export type TRecentActivityFilterKeys = "all item" | "issue" | "page" | "project";
export type THomeWidgetKeys = "quick_links" | "recent_activity" | "stickies";
export type THomeWidgetKeys = "quick_links" | "recents" | "my_stickies" | "quick_tutorial" | "new_at_plane";
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Ensure consistent naming for the recent activity widget.

Here, you define "recents" as part of THomeWidgetKeys. However, in loader.tsx, the enum uses "recent_activity". Please unify the naming (e.g., use all "recents" or all "recent_activity") to avoid potential type mismatches.

Comment on lines +15 to +21
[key in THomeWidgetKeys]: { component: React.FC<THomeWidgetProps> | null; fullWidth: boolean };
} = {
quick_links: { component: DashboardQuickLinks, fullWidth: false },
recent_activity: { component: RecentActivityWidget, fullWidth: false },
stickies: { component: StickiesWidget, fullWidth: false },
recents: { component: RecentActivityWidget, fullWidth: false },
my_stickies: { component: StickiesWidget, fullWidth: false },
new_at_plane: { component: null, fullWidth: false },
quick_tutorial: { component: null, fullWidth: false },
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Confirm unified widget keys usage.

Defining "recents", "my_stickies", etc., is consistent with the updated THomeWidgetKeys. Nonetheless, be sure to align any usage of "recent_activity" in the codebase (e.g., EWidgetKeys.RECENT_ACTIVITY) with "recents" to prevent runtime errors.

@gakshita gakshita changed the title fix: added ee dummy component for header fix: manage widgets integrations Jan 6, 2025
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

🧹 Nitpick comments (3)
web/core/store/workspace/home.ts (3)

55-57: Consider reducing code duplication.

The sorting and mapping logic is duplicated between orderedWidgets getter and fetchWidgets method. Consider reusing the getter to maintain consistency:

  fetchWidgets = async (workspaceSlug: string) => {
    try {
      const widgets = await this.workspaceService.fetchWorkspaceWidgets(workspaceSlug);
      runInAction(() => {
-       this.widgets = orderBy(Object.values(widgets), "sort_order", "desc").map((widget) => widget.key);
+       widgets.forEach((widget) => {
+         this.widgetsMap[widget.key] = widget;
+       });
+       this.widgets = this.orderedWidgets;
-       widgets.forEach((widget) => {
-         this.widgetsMap[widget.key] = widget;
-       });
      });
    } catch (error) {

Also applies to: 67-67


Line range hint 89-112: Consider improving the widget reordering strategy.

The current implementation has potential issues:

  1. Using fixed increments/decrements of 10000 could lead to sort_order overflow
  2. Floating-point division might cause precision issues
  3. No periodic normalization of sort_order values

Consider these improvements:

  1. Implement periodic rebalancing of sort_order values
  2. Use integer arithmetic instead of floating-point
  3. Add bounds checking for sort_order values
  4. Consider using a more scalable ordering algorithm like Fractal Tree ordering

Would you like me to provide a more detailed implementation of these improvements?


Line range hint 71-74: Enhance error handling with more context.

The current error messages could be more informative for debugging purposes.

    } catch (error) {
-     console.error("Failed to fetch widgets");
+     console.error("Failed to fetch widgets:", {
+       error,
+       workspaceSlug,
+       context: "HomeStore.fetchWidgets"
+     });
      throw error;
    }

Apply similar improvements to other error handlers in the file.

Also applies to: 83-86, 113-116

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae0503 and 4bea812.

📒 Files selected for processing (1)
  • web/core/store/workspace/home.ts (5 hunks)
🔇 Additional comments (2)
web/core/store/workspace/home.ts (2)

3-4: LGTM! Type safety improvements.

The changes enhance type safety by using the specific THomeWidgetKeys type instead of generic strings, making the code more maintainable and less error-prone.

Also applies to: 12-14


28-28: LGTM! Proper MobX store setup.

The store is correctly configured with observable properties and the new computed property is properly registered in the constructor.

Also applies to: 40-41

@rahulramesha
Copy link
Collaborator

@gakshita Code looks good, Please resolve conflicts

@pushya22 pushya22 merged commit 0af9b09 into preview Jan 7, 2025
13 of 14 checks passed
@pushya22 pushya22 deleted the fix-home-header branch January 7, 2025 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants