Skip to content

Comments

[WEB-2807] fix: Root issue store to have updated url params at all times#6147

Merged
pushya22 merged 1 commit intopreviewfrom
fix-issue-untag-module-cycle
Dec 4, 2024
Merged

[WEB-2807] fix: Root issue store to have updated url params at all times#6147
pushya22 merged 1 commit intopreviewfrom
fix-issue-untag-module-cycle

Conversation

@rahulramesha
Copy link
Contributor

@rahulramesha rahulramesha commented Dec 3, 2024

This PR fixes the issues disappearing while untagging modules of the issue under certain conditions. The root cause for this was the out dated url params in Root Issue store. That is being fixed in this PR to have updated url params in Root Issue store

Summary by CodeRabbit

  • Bug Fixes
    • Improved the logic for updating properties in the Issue management system to prevent unnecessary updates, enhancing performance and efficiency.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2024

Walkthrough

The pull request modifies the IssueRootStore class in root.store.ts, specifically enhancing the autorun function in its constructor. The changes introduce conditions to check if the current property values differ from those in rootStore.router before updating them. This aims to prevent unnecessary updates and optimize state management. There are no alterations to the structure or declarations of the IIssueRootStore interface or the IssueRootStore class.

Changes

File Path Change Summary
web/core/store/issue/root.store.ts Enhanced logic in the IssueRootStore constructor's autorun function to check for value differences before updating properties.

Possibly related PRs

Suggested reviewers

  • SatishGandham

🐇 In the code where values play,
We check before we update each day.
No more changes that aren't quite right,
Keeping our store in sync, what a delight!
With each little hop, we refine our way,
Optimizing flows, come join the play! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between b6ab853 and 5b3cbc7.

📒 Files selected for processing (1)
  • web/core/store/issue/root.store.ts (1 hunks)
🔇 Additional comments (1)
web/core/store/issue/root.store.ts (1)

172-178: LGTM! Consider some improvements for maintainability.

The conditional checks prevent unnecessary state updates and should fix the module disappearance issue. The implementation is consistent across all URL parameters.

Consider extracting the URL parameter sync logic into a helper function to reduce repetition and improve maintainability:

+ private syncUrlParam<T>(currentValue: T | undefined, routerValue: T | undefined, key: keyof this) {
+   if (currentValue !== routerValue) {
+     (this[key] as T | undefined) = routerValue;
+   }
+ }

  autorun(() => {
    if (rootStore?.user?.data?.id) this.currentUserId = rootStore?.user?.data?.id;
-   if (this.workspaceSlug !== rootStore.router.workspaceSlug) this.workspaceSlug = rootStore.router.workspaceSlug;
-   if (this.projectId !== rootStore.router.projectId) this.projectId = rootStore.router.projectId;
-   if (this.cycleId !== rootStore.router.cycleId) this.cycleId = rootStore.router.cycleId;
-   if (this.moduleId !== rootStore.router.moduleId) this.moduleId = rootStore.router.moduleId;
-   if (this.viewId !== rootStore.router.viewId) this.viewId = rootStore.router.viewId;
-   if (this.globalViewId !== rootStore.router.globalViewId) this.globalViewId = rootStore.router.globalViewId;
-   if (this.userId !== rootStore.router.userId) this.userId = rootStore.router.userId;
+   this.syncUrlParam(this.workspaceSlug, rootStore.router.workspaceSlug, 'workspaceSlug');
+   this.syncUrlParam(this.projectId, rootStore.router.projectId, 'projectId');
+   this.syncUrlParam(this.cycleId, rootStore.router.cycleId, 'cycleId');
+   this.syncUrlParam(this.moduleId, rootStore.router.moduleId, 'moduleId');
+   this.syncUrlParam(this.viewId, rootStore.router.viewId, 'viewId');
+   this.syncUrlParam(this.globalViewId, rootStore.router.globalViewId, 'globalViewId');
+   this.syncUrlParam(this.userId, rootStore.router.userId, 'userId');

Let's verify that the router values are properly typed:

✅ Verification successful

Based on the search results, I can now generate the final response. The router store implementation shows proper type definitions with the interface IRouterStore defining all URL-related parameters as optional string types (string | undefined), which ensures type safety for the values being synchronized.

LGTM with verified type safety! Consider helper function for maintainability.

The implementation is type-safe and the conditional checks prevent unnecessary state updates. The router values are properly typed through the IRouterStore interface, ensuring type consistency.

Consider extracting the URL parameter sync logic into a helper function to reduce repetition:

private syncUrlParam(currentValue: string | undefined, routerValue: string | undefined, key: keyof this) {
  if (currentValue !== routerValue) {
    (this[key] as string | undefined) = routerValue;
  }
}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check if router values are properly typed
# Expected: Find the router interface definition to ensure type safety

# Search for router interface definition
ast-grep --pattern 'interface $ROUTER_TYPE {
  $$$
  workspaceSlug: $_
  projectId: $_
  cycleId: $_
  moduleId: $_
  viewId: $_
  globalViewId: $_
  userId: $_
  $$$
}'

Length of output: 171


Script:

#!/bin/bash
# Let's try a different approach to find router-related type definitions
# First, let's find the router store definition
ast-grep --pattern 'class $_ {
  $$$
  workspaceSlug: $_
  projectId: $_
  $$$
}'

# Also search for any type definitions related to router
rg "type.*Router|interface.*Router" -A 5

Length of output: 65995


Script:

#!/bin/bash
# Let's search for the router store implementation to verify type safety
rg "class RouterStore|interface IRouterStore" -A 10 web/core/store/router.store.ts

# Also search for the store's properties
ast-grep --pattern 'class RouterStore {
  $$$
  workspaceSlug: $_
  projectId: $_
  cycleId: $_
  moduleId: $_
  viewId: $_
  globalViewId: $_
  userId: $_
  $$$
}'

Length of output: 817


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 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.

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