Skip to content

[WEB-4108]chore: refactored project wrapper #7066

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

Draft
wants to merge 7 commits into
base: preview
Choose a base branch
from

Conversation

vamsikrishnamathala
Copy link
Member

@vamsikrishnamathala vamsikrishnamathala commented May 15, 2025

Description

This update refactors ProjectAuthWrapper. All the SWR calls are aggregated into a single re-usable hook.

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

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • Refactor
    • Simplified project data fetching by consolidating multiple individual data fetches into a single unified hook.
    • Reduced code complexity in project-related components by centralizing resource synchronization.
  • Chores
    • Added new internal hooks to manage and synchronize project resources more efficiently.
  • New Features
    • Introduced a streamlined project resource management hook for improved data synchronization.
    • Enabled automatic initialization of project timeline charts within the resource management process.
    • Integrated the new project resource hook into the project authorization component for seamless data handling.

Copy link
Contributor

coderabbitai bot commented May 15, 2025

Walkthrough

A new data synchronization system for project resources was introduced using custom React hooks. The logic for fetching and synchronizing project data was consolidated from multiple SWR hooks into a single core hook, useProjectCoreResources. A wrapper hook, useProjectResources, was added that calls the core hook and returns a static loading state. The enterprise edition re-exports the community hook. The project wrapper component was refactored to invoke the new consolidated hook and removed individual SWR calls.

Changes

Files/Paths Change Summary
web/ce/hooks/use-project-resources.ts Added useProjectResources hook that calls useProjectCoreResources and returns { isLoading: false }.
web/core/hooks/use-project-resources.ts Added useProjectCoreResources hook that synchronizes core project resources using multiple SWR hooks.
web/ee/hooks/use-project-resources.ts Added file re-exporting all exports from ce/hooks/use-project-resources.
web/core/layouts/auth-layout/project-wrapper.tsx Removed individual SWR hooks and related imports for project data fetching and syncing.
web/ce/layouts/project-wrapper.tsx Imported and invoked useProjectResources hook inside ProjectAuthWrapper component.

Sequence Diagram(s)

sequenceDiagram
    participant ProjectAuthWrapper
    participant useProjectResources
    participant useProjectCoreResources
    participant SWR
    participant GlobalStore

    ProjectAuthWrapper->>useProjectResources: Call with workspaceSlug, projectId
    useProjectResources->>useProjectCoreResources: Call with workspaceSlug, projectId
    useProjectCoreResources->>SWR: Fetch project data (details, members, labels, etc.)
    SWR-->>useProjectCoreResources: Return data
    useProjectCoreResources->>GlobalStore: Sync data via side effects
    useProjectResources-->>ProjectAuthWrapper: Return { isLoading: false }
Loading

Poem

In the warren of code, a new path appears,
One hook to fetch all, the clutter it clears.
Project resources, now gathered with ease,
SWR bunnies hop, syncing data as they please.
With wrappers and exports, the structure refined—
A carrot for progress, for all rabbit-kind! 🥕

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 30th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between fa6c4df and 7a6ff6e.

📒 Files selected for processing (2)
  • web/ce/hooks/use-project-resources.ts (1 hunks)
  • web/core/hooks/use-project-resources.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/ce/hooks/use-project-resources.ts
  • web/core/hooks/use-project-resources.ts
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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: 0

🧹 Nitpick comments (2)
web/ce/hooks/use-project-resources.ts (2)

34-39: Consider adding a dependency to the useEffect

The ESLint disable comment suggests that there might be missing dependencies in the useEffect dependency array.

 useEffect(() => {
   initGantt();
-  // eslint-disable-next-line react-hooks/exhaustive-deps
- }, []);
+ }, [initGantt]);

Alternatively, if initGantt should only run once regardless of changes to the function reference, consider moving it outside the component or memoizing it.


56-121: Consider abstracting the repeated SWR pattern

There's a repeating pattern across multiple SWR calls with similar conditional logic. This could potentially be abstracted into a helper function.

+ // Helper function to reduce repetition
+ const fetchProjectResource = (
+   key: string,
+   fetcher: () => Promise<any>,
+   options: any = { revalidateIfStale: false, revalidateOnFocus: false }
+ ) => {
+   return useSWR(
+     workspaceSlug && projectId ? `${key}_${workspaceSlug}_${projectId}` : null,
+     workspaceSlug && projectId ? () => fetcher() : null,
+     options
+   );
+ };
+
 // Project labels
-useSWR(
-  workspaceSlug && projectId ? `PROJECT_LABELS_${workspaceSlug}_${projectId}` : null,
-  workspaceSlug && projectId ? () => fetchProjectLabels(workspaceSlug.toString(), projectId.toString()) : null,
-  { revalidateIfStale: false, revalidateOnFocus: false }
-);
+fetchProjectResource(
+  "PROJECT_LABELS",
+  () => fetchProjectLabels(workspaceSlug!.toString(), projectId!.toString())
+);

This would make the code more DRY and easier to maintain.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 084cc75 and d9ef19d.

📒 Files selected for processing (7)
  • web/app/[workspaceSlug]/(projects)/browse/[workItem]/page.tsx (3 hunks)
  • web/app/[workspaceSlug]/(projects)/projects/(detail)/layout.tsx (1 hunks)
  • web/ce/hooks/use-project-resources.ts (1 hunks)
  • web/ce/layouts/project-wrapper.tsx (0 hunks)
  • web/core/layouts/auth-layout/index.ts (0 hunks)
  • web/core/layouts/auth-layout/project-wrapper.tsx (0 hunks)
  • web/ee/layouts/project-wrapper.tsx (0 hunks)
💤 Files with no reviewable changes (4)
  • web/core/layouts/auth-layout/index.ts
  • web/core/layouts/auth-layout/project-wrapper.tsx
  • web/ee/layouts/project-wrapper.tsx
  • web/ce/layouts/project-wrapper.tsx
🧰 Additional context used
🧬 Code Graph Analysis (3)
web/app/[workspaceSlug]/(projects)/browse/[workItem]/page.tsx (3)
web/core/store/router.store.ts (3)
  • projectId (85-87)
  • issueId (149-151)
  • workspaceSlug (69-71)
web/ce/hooks/use-project-resources.ts (1)
  • useProjectResources (124-126)
web/core/components/issues/issue-detail/root.tsx (1)
  • IssueDetailRoot (62-392)
web/app/[workspaceSlug]/(projects)/projects/(detail)/layout.tsx (1)
web/ce/hooks/use-project-resources.ts (1)
  • useProjectResources (124-126)
web/ce/hooks/use-project-resources.ts (3)
web/core/store/router.store.ts (2)
  • workspaceSlug (69-71)
  • projectId (85-87)
web/core/hooks/store/use-cycle.ts (1)
  • useCycle (7-11)
web/core/local-db/storage.sqlite.ts (1)
  • persistence (475-475)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (11)
web/app/[workspaceSlug]/(projects)/browse/[workItem]/page.tsx (4)

19-19: Great job replacing the wrapper component with a hook!

The import change from ProjectAuthWrapper to useProjectResources aligns with modern React practices of using hooks for shared logic instead of wrapper components.


49-49: Good use of nullish coalescing operator for fallback value

Using ?? to provide a default empty string ensures projectId is always a string, which prevents type-related issues downstream.


56-57: Nice explanatory comment for the hook usage

Adding the comment "Load project resources when needed" clearly explains the purpose of the hook call, which is good for maintainability.


102-109: Clean removal of the wrapper component

The code is now more straightforward by directly rendering IssueDetailRoot without the extra wrapper layer, which simplifies the component tree.

web/app/[workspaceSlug]/(projects)/projects/(detail)/layout.tsx (3)

5-6: Good organization with the "hooks" comment

Adding the comment to categorize imports improves code readability and organization.


11-14: Clear comment and well-placed hook call

The explanatory comment and hook call are placed at the top level of the component, ensuring resources are loaded early.


15-15: Simplified return statement

Directly returning children without the wrapper component simplifies the component tree and reduces unnecessary nesting.

web/ce/hooks/use-project-resources.ts (4)

1-19: Well-organized imports

The imports are nicely organized with comments separating different categories, which improves readability.


20-33: Good consolidation of resource hooks

The hook effectively consolidates all the necessary resource hooks in one place, making it easier to manage project-related data fetching.


40-54: Smart use of SWR for issue synchronization

Using SWR with conditional fetching based on workspace and project ID availability ensures that synchronization only happens when needed. The refresh interval of 5 minutes is also a reasonable choice.


123-126: Good wrapper hook for API consistency

Creating a dedicated useProjectResources wrapper hook provides a clean API for components and allows for future extensibility.

@vamsikrishnamathala vamsikrishnamathala changed the title chore: refactored project wrapper [WEB-4108]chore: refactored project wrapper May 16, 2025
Copy link

makeplane bot commented May 16, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

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 (3)
web/core/hooks/use-project-resources.ts (3)

34-38: Consider adding cleanup logic for the Gantt chart.

The hook initializes the Gantt chart on mount but doesn't provide cleanup logic. To prevent potential memory leaks, consider adding a cleanup function in the useEffect return.

useEffect(() => {
  initGantt();
  // eslint-disable-next-line react-hooks/exhaustive-deps
+  return () => {
+    // Add cleanup logic here if needed
+  };
}, []);

68-94: Consider abstracting repeated SWR pattern.

This block shows multiple SWR calls with the same revalidation settings. Consider creating a utility function to reduce repetition.

// A helper function to reduce repetition
const fetchProjectResource = (
  key: string,
  fetcher: () => Promise<any>,
  options = { revalidateIfStale: false, revalidateOnFocus: false }
) => {
  return useSWR(
    workspaceSlug && projectId ? `${key}_${workspaceSlug}_${projectId}` : null,
    workspaceSlug && projectId ? () => fetcher() : null,
    options
  );
};

// Example usage
fetchProjectResource(
  "PROJECT_LABELS",
  () => fetchProjectLabels(workspaceSlug!.toString(), projectId!.toString())
);

115-121: Consider exposing loading and error states.

The hook currently triggers side effects but doesn't provide consumers with loading or error states. Consider returning these states to improve usability.

// Example of how the hook could return loading and error states
export const useProjectCoreResources = (workspaceSlug?: string, projectId?: string) => {
  // ... existing code ...
  
  // Track overall loading and error states
  const [isLoading, setIsLoading] = useState(true);
  const [error, setError] = useState<Error | null>(null);
  
  // Use useEffect to track when all resources are loaded
  useEffect(() => {
    // Logic to determine when all resources are loaded
    // and update isLoading and error states
  }, [/* dependencies */]);
  
  return { isLoading, error };
};
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between bb27156 and eb14414.

📒 Files selected for processing (3)
  • web/app/[workspaceSlug]/(projects)/browse/[workItem]/page.tsx (3 hunks)
  • web/ce/hooks/use-project-resources.ts (1 hunks)
  • web/core/hooks/use-project-resources.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/ce/hooks/use-project-resources.ts
  • web/app/[workspaceSlug]/(projects)/browse/[workItem]/page.tsx
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/core/hooks/use-project-resources.ts (3)
web/core/store/router.store.ts (2)
  • workspaceSlug (69-71)
  • projectId (85-87)
web/core/hooks/store/use-cycle.ts (1)
  • useCycle (7-11)
web/core/local-db/storage.sqlite.ts (1)
  • persistence (475-475)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Analyze (javascript)
  • GitHub Check: Analyze (python)
🔇 Additional comments (6)
web/core/hooks/use-project-resources.ts (6)

1-19: Clean and well-organized imports.

The imports are clearly organized into React core, third-party libraries, and internal hooks. This makes the file easy to understand and maintain.


20-33: Good hook design with clear dependencies.

The hook has a well-defined signature with optional parameters and properly initializes all required dependencies from various store hooks. This design allows for flexible usage across different components.


40-54: Well-implemented issue synchronization with refresh interval.

The implementation uses SWR effectively with appropriate cache keys and revalidation settings. The 5-minute refresh interval ensures data stays reasonably up-to-date while not overwhelming the server with requests.


56-66: Proper fetching of project details and user info.

The implementation correctly fetches project details and user project information conditionally based on the availability of workspace and project IDs.


96-101: Consistent fetch pattern for project cycles.

This implementation correctly follows the established pattern for fetching project resources with appropriate cache keys and revalidation settings.


20-121: Great refactoring from component to hook.

This refactoring successfully moves from a component-based approach to a hook-based approach, improving separation of concerns. The hook focuses solely on data fetching and synchronization, making it more reusable across different UI components.

@vamsikrishnamathala vamsikrishnamathala marked this pull request as draft May 16, 2025 10:06
@vamsikrishnamathala vamsikrishnamathala marked this pull request as ready for review May 19, 2025 07:19
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

♻️ Duplicate comments (1)
web/ce/hooks/use-project-resources.ts (1)

4-9: 🛠️ Refactor suggestion

Propagate the real loading state instead of returning a hard-coded value

useProjectCoreResources already returns an isLoading flag but the wrapper discards it and always returns false.
If useProjectCoreResources is later extended to do any async work (very likely), components relying on useProjectResources will never know that data is still being fetched and may render incomplete UI.

Proposed minimal fix:

 export const useProjectResources = (workspaceSlug?: string, projectId?: string) => {
-  useProjectCoreResources(workspaceSlug, projectId);
-  return {
-    isLoading: false,
-  };
+  const { isLoading } = useProjectCoreResources(workspaceSlug, projectId);
+  return { isLoading };
 };

This keeps the wrapper thin while preserving useful state for consumers.

🧹 Nitpick comments (1)
web/core/layouts/auth-layout/project-wrapper.tsx (1)

64-64: Leverage the isLoading flag returned by the new hook

The call to useProjectResources is made, but its return value is ignored.
Capturing isLoading would let the wrapper avoid duplicating the existing “parent loading” logic and prevent potential flashes of empty UI if the underlying hook ever becomes asynchronous (see previous comment).

-  useProjectResources(workspaceSlug?.toString(), projectId?.toString());
+  const { isLoading: isProjectLoading } = useProjectResources(
+    workspaceSlug?.toString(),
+    projectId?.toString()
+  );

You can then merge isProjectLoading with isParentLoading in the early-return spinner block.

This keeps the wrapper future-proof and in sync with the hook’s contract.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between 091bc45 and b4cc6d2.

📒 Files selected for processing (3)
  • web/ce/hooks/use-project-resources.ts (1 hunks)
  • web/core/hooks/use-project-resources.ts (1 hunks)
  • web/core/layouts/auth-layout/project-wrapper.tsx (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/core/hooks/use-project-resources.ts
🧰 Additional context used
🧬 Code Graph Analysis (1)
web/ce/hooks/use-project-resources.ts (1)
web/core/hooks/use-project-resources.ts (1)
  • useProjectCoreResources (17-115)

@vamsikrishnamathala vamsikrishnamathala force-pushed the chore-project_wrapper_refactor branch from fa6c4df to 7a6ff6e Compare May 21, 2025 07:41
@pushya22 pushya22 marked this pull request as draft May 22, 2025 11:38
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.

3 participants