Skip to content

Comments

improvement: refactored issue grouping logic to access MobX store directly#6134

Merged
pushya22 merged 3 commits intopreviewfrom
improvement-issue-grouping
Dec 11, 2024
Merged

improvement: refactored issue grouping logic to access MobX store directly#6134
pushya22 merged 3 commits intopreviewfrom
improvement-issue-grouping

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Dec 2, 2024

Simplified the implementation by accessing the MobX store directly within the grouping logic, eliminating the need to pass it as a parameter. This reduces redundancy and improves code readability.

Other improvements

  • Cleaned up cycles store.

Summary by CodeRabbit

  • New Features

    • The icon property in the IGroupByColumn interface is now optional, enhancing flexibility.
    • Introduced getProjectModuleDetails method for improved module retrieval.
  • Improvements

    • Simplified function calls in the Kanban, List, and utility components for better clarity and reduced dependencies.
    • Streamlined data access in utility functions, enhancing maintainability.
  • Bug Fixes

    • Removed unused hooks and methods to simplify cycle management logic and improve performance.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces modifications across several files, primarily focusing on the IGroupByColumn interface and various components related to the Kanban layout. Key changes include making the icon property optional in the IGroupByColumn interface, removing multiple store hooks from the KanBan, SwimLanes, and List components, and refactoring the getGroupByColumns function to accept a single object parameter. Additionally, the CycleStore and ModuleStore interfaces have been simplified, with several methods removed or modified to enhance clarity and reduce complexity.

Changes

File Path Change Summary
packages/types/src/issues.d.ts Updated IGroupByColumn interface: `icon: ReactElement
web/core/components/issues/issue-layouts/kanban/default.tsx Removed store hooks: useMember, useProject, useLabel, useCycle, useModule, useProjectState. Updated getGroupByColumns to use named parameters.
web/core/components/issues/issue-layouts/kanban/swimlanes.tsx Removed store hooks and consolidated into groupByList and subGroupByList. Updated getGroupByColumns to accept an object with named parameters.
web/core/components/issues/issue-layouts/list/default.tsx Removed store hooks and updated getGroupByColumns to accept an object with named parameters. Maintained existing logic for rendering components.
web/core/components/issues/issue-layouts/utils.tsx Refactored getGroupByColumns to accept a single object parameter. Updated helper functions to access store context directly.
web/core/store/cycle.store.ts Removed CycleDateCheckData, getActiveCycleProgress, and other properties/methods from ICycleStore. Introduced getProjectCycleDetails.
web/core/store/module.store.ts Added getProjectModuleDetails to IModuleStore. Refactored getProjectModuleIds to utilize this new method.

Suggested labels

🌟improvement, 🧹chore, 🌐frontend

Suggested reviewers

  • SatishGandham
  • rahulramesha

Poem

🐰 In the fields where the code does play,
A new icon's found its way,
Optional now, it hops with glee,
Simplified hooks, oh what a spree!
Kanban lanes, so clear and bright,
Happy coding, day and night! 🌼


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

🧹 Outside diff range and nitpick comments (2)
web/core/components/issues/issue-layouts/kanban/swimlanes.tsx (1)

263-275: LGTM! Improved store access pattern

The refactoring simplifies the store access by:

  1. Consolidating multiple store hooks into a single useIssueStoreType hook
  2. Using derived values with named parameters for better readability
  3. Maintaining type safety with explicit type casting

This aligns well with the PR's objective of simplifying store access patterns.

Consider extracting these derived values into a custom hook for better reusability:

const useGroupByColumns = (
  groupBy: TIssueGroupByOptions | undefined,
  subGroupBy: TIssueGroupByOptions | undefined
) => {
  const storeType = useIssueStoreType();
  const isWorkspaceLvl = isWorkspaceLevel(storeType);
  
  return {
    groupByList: getGroupByColumns({
      groupBy: groupBy as GroupByColumnTypes,
      includeNone: true,
      isWorkspaceLevel: isWorkspaceLvl,
    }),
    subGroupByList: getGroupByColumns({
      groupBy: subGroupBy as GroupByColumnTypes,
      includeNone: true,
      isWorkspaceLevel: isWorkspaceLvl,
    })
  };
};
web/core/store/module.store.ts (1)

289-292: Simplify error handling in catch blocks

The error handling in catch blocks has been simplified by removing the error parameter. While this reduces verbosity, consider adding error tracking for production monitoring.

Consider adding error tracking:

-    } catch {
+    } catch (error) {
+      if (process.env.NODE_ENV === 'production') {
+        // Add your error tracking service here
+        errorTrackingService.captureError(error);
+      }
       this.loader = false;
       return undefined;
     }

Also applies to: 315-318

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3c6006d and ceb0e91.

📒 Files selected for processing (7)
  • packages/types/src/issues.d.ts (1 hunks)
  • web/core/components/issues/issue-layouts/kanban/default.tsx (2 hunks)
  • web/core/components/issues/issue-layouts/kanban/swimlanes.tsx (1 hunks)
  • web/core/components/issues/issue-layouts/list/default.tsx (1 hunks)
  • web/core/components/issues/issue-layouts/utils.tsx (8 hunks)
  • web/core/store/cycle.store.ts (6 hunks)
  • web/core/store/module.store.ts (5 hunks)
🔇 Additional comments (11)
web/core/components/issues/issue-layouts/utils.tsx (2)

69-107: Refactored getGroupByColumns function enhances clarity

The getGroupByColumns function now accepts a single object parameter, improving readability and maintainability by grouping related arguments.


Line range hint 109-186: Simplified helper functions by accessing store directly

The helper functions now access the store context directly, reducing redundancy and streamlining data retrieval.

web/core/store/cycle.store.ts (3)

53-53: Addition of getProjectCycleDetails method improves cycle retrieval

Introducing the getProjectCycleDetails method enhances the ability to retrieve detailed cycle information for a given project.


328-336: Implemented getProjectCycleDetails function correctly

The function effectively retrieves and sorts cycles for the specified project, ensuring accurate data access.


340-348: Implemented getProjectCycleIds function efficiently

Using getProjectCycleDetails to obtain cycle IDs promotes code reuse and consistency across the codebase.

packages/types/src/issues.d.ts (1)

219-219: Made icon property optional in IGroupByColumn

Updating the icon property to be optional increases flexibility when defining group columns without mandating an icon.

web/core/components/issues/issue-layouts/list/default.tsx (1)

81-85: Simplified getGroupByColumns function call

Refactoring the call to getGroupByColumns to use an object parameter enhances readability and aligns with the updated function signature.

web/core/components/issues/issue-layouts/kanban/default.tsx (1)

90-99: Updated getGroupByColumns function call for consistency

Adjusting the getGroupByColumns call to accept an object parameter simplifies the code and ensures consistency with the refactored function.

web/core/store/module.store.ts (3)

34-34: LGTM! Added new method to interface

The new getProjectModuleDetails method in the interface properly defines the return type and parameter.


214-222: LGTM! Well-implemented computed method

The new getProjectModuleDetails method:

  1. Properly checks fetch status
  2. Filters modules by project ID and archived status
  3. Maintains sort order consistency

224-233: LGTM! Improved code reuse

The refactored getProjectModuleIds method now reuses getProjectModuleDetails, reducing code duplication and improving maintainability.

Comment on lines +487 to 488
// eslint-disable-next-line @typescript-eslint/no-unused-vars
fetchActiveCycleProgressPro = action(async (workspaceSlug: string, projectId: string, cycleId: string) => {});
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

Incomplete implementation of fetchActiveCycleProgressPro

The method fetchActiveCycleProgressPro is currently empty, indicating incomplete functionality. Please implement this method or remove it if it's no longer needed.

Would you like assistance in implementing this method or should it be removed?

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

🧹 Outside diff range and nitpick comments (2)
web/core/store/module.store.ts (1)

295-297: Consider logging errors in the catch blocks

In the fetchModules and fetchModulesSlim methods, the catch blocks do not capture or log the errors, which may hinder debugging and error tracing. Consider logging the errors to provide more context in case of failures.

Proposed change for fetchModules:

} catch (error) {
  this.loader = false;
+ console.error("Failed to fetch modules:", error);
  return undefined;
}

Similarly, for fetchModulesSlim:

} catch (error) {
  this.loader = false;
+ console.error("Failed to fetch modules slim:", error);
  return undefined;
}

Also applies to: 321-323

web/core/components/issues/issue-layouts/utils.tsx (1)

132-159: Potential null check for currentProjectDetails in getCycleColumns

The function assumes currentProjectDetails and currentProjectDetails.id are defined. Consider adding null checks or handling undefined cases to prevent potential runtime errors.

const { currentProjectDetails } = store.projectRoot.project;
if (!currentProjectDetails || !currentProjectDetails.id) return;

This check is already present; ensure similar checks are implemented wherever necessary.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ceb0e91 and 7f0bc83.

📒 Files selected for processing (4)
  • web/core/components/issues/issue-layouts/kanban/swimlanes.tsx (1 hunks)
  • web/core/components/issues/issue-layouts/utils.tsx (8 hunks)
  • web/core/store/cycle.store.ts (6 hunks)
  • web/core/store/module.store.ts (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/core/components/issues/issue-layouts/kanban/swimlanes.tsx
🔇 Additional comments (15)
web/core/store/module.store.ts (3)

35-36: Addition of getProjectModuleDetails method approved

The addition of the getProjectModuleDetails method enhances module retrieval functionality by providing direct access to module details based on projectId.


218-223: Efficient retrieval of project module details

The getProjectModuleDetails function efficiently retrieves and sorts module details for a given projectId. The use of computedFn optimizes performance by memoizing the computed values.


229-233: Refactoring getProjectModuleIds to utilize getProjectModuleDetails

The refactoring of getProjectModuleIds to use getProjectModuleDetails promotes code reuse and simplifies logic. This enhances maintainability and reduces potential errors.

web/core/components/issues/issue-layouts/utils.tsx (6)

39-39: Direct import of store for state management

Importing store directly from @/lib/store-context centralizes state management and aligns with the PR objective of accessing the MobX store directly, simplifying the implementation.


63-66: Improved type definition for getGroupByColumns parameters

Defining TGetGroupByColumns as an object enhances readability and future maintainability by allowing for easier addition of parameters.


73-107: Refactored getGroupByColumns function enhances clarity

The refactoring of getGroupByColumns to accept a single object parameter and the use of a mapping object (groupByColumnMap) improves the clarity and scalability of the function.


232-238: Default parameter in getLabelsColumns and usage of correct label set

The function getLabelsColumns correctly uses the default parameter isWorkspaceLevel: boolean = false. It appropriately selects workspace or project labels based on this parameter.


253-256: Direct access to store in getAssigneeColumns and getCreatedByColumns

Accessing store.memberRoot directly simplifies the functions and aligns with the PR objective. Ensure that projectMemberIds and getUserDetails are available and handle any potential undefined values.

[approve]

Run the following script to verify that all projectMemberIds have corresponding user details:

Also applies to: 269-273

✅ Verification successful

Based on the gathered information, I can now provide the final response:

Direct access to store.memberRoot is safe and properly handled

The code correctly handles potential undefined values:

  • memberRoot is properly typed with IMemberRootStore interface which includes memberMap and getUserDetails
  • The function has a guard clause if (!projectMemberIds) return
  • getUserDetails is widely used across the codebase and is a standard way to access user information
  • The pattern aligns with the codebase's conventions as seen in multiple components
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that all project member IDs have corresponding user details.

# Expected result: All member IDs should have corresponding entries in `store.memberRoot.getUserDetails`.

for memberId in "${store.memberRoot.project.projectMemberIds[@]}"; do
  if [[ -z "${store.memberRoot.getUserDetails($memberId)}" ]]; then
    echo "Missing user details for member ID: $memberId"
  fi
done

Length of output: 136


Script:

#!/bin/bash
# Let's analyze the code structure and usage of store.memberRoot
ast-grep --pattern 'store.memberRoot'

# Also check for any error handling or type definitions related to memberRoot
rg "memberRoot" -A 3

Length of output: 7606


Script:

#!/bin/bash
# Let's examine the type definitions and implementation of memberRoot store
rg "interface IMemberRootStore" -A 10

# Also check the implementation of getUserDetails
ast-grep --pattern 'getUserDetails'

# And check how projectMemberIds is handled
ast-grep --pattern 'projectMemberIds'

Length of output: 14045


Line range hint 110-129: Ensure all projects are loaded before mapping

In the getProjectColumns function, ensure that all projects are loaded into projectMap to prevent undefined entries when mapping project IDs to columns.

Run the following script to verify that all projects are loaded:

🧰 Tools
🪛 Biome (1.9.4)

[error] 61-61: Unnecessary use of boolean literals in conditional expression.

Simplify your code by directly assigning the result without using a ternary operator.
If your goal is negation, you may use the logical NOT (!) or double NOT (!!) operator for clearer and concise code.
Check for more details about NOT operator.
Unsafe fix: Remove the conditional expression with

(lint/complexity/noUselessTernary)

web/core/store/cycle.store.ts (6)

17-17: Updated imports reflect new helper functions

The import statement now includes orderCycles and shouldFilterCycle from cycle.helper, indicating refactoring and code reuse.


54-54: Addition of getProjectCycleDetails method

The getProjectCycleDetails method provides a streamlined way to retrieve cycle details for a given projectId, enhancing the functionality of the CycleStore.


333-338: Efficient retrieval of project cycle details

The getProjectCycleDetails function efficiently retrieves and sorts cycle details for a given projectId, improving code organization and reusability.


345-350: Refactored getProjectCycleIds to use getProjectCycleDetails

By utilizing getProjectCycleDetails, the getProjectCycleIds function reduces code duplication and enhances maintainability.


415-417: Conditional addition to activeCycleIdMap

The inclusion of a condition to set the activeCycleIdMap ensures only cycles with status "current" are marked active, which improves logic accuracy.


497-498: Incomplete implementation of fetchActiveCycleProgressPro

The method fetchActiveCycleProgressPro is currently empty, indicating incomplete functionality. Please implement this method or remove it if it's no longer needed.

@pushya22 pushya22 merged commit 0ac68f2 into preview Dec 11, 2024
@pushya22 pushya22 deleted the improvement-issue-grouping branch December 11, 2024 09:44
nishantPFM pushed a commit to Pocket-Fm/plane that referenced this pull request Dec 12, 2024
…ectly (makeplane#6134)

* improvement: refactored issue grouping logic to access MobX store directly

* chore: minor updates
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.

3 participants