Skip to content

[WEB-4311] fix: membership data handling and state reversal on error#7205

Merged
sriramveeraghanta merged 1 commit intopreviewfrom
fix-members-optimistic-update
Jun 16, 2025
Merged

[WEB-4311] fix: membership data handling and state reversal on error#7205
sriramveeraghanta merged 1 commit intopreviewfrom
fix-members-optimistic-update

Conversation

@prateekshourya29
Copy link
Member

@prateekshourya29 prateekshourya29 commented Jun 12, 2025

Description

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Summary by CodeRabbit

  • New Features
    • Added the ability to retrieve a sorted list of workspace member IDs, excluding bots and prioritizing the current user.
  • Bug Fixes
    • Improved data integrity when updating member information to prevent unintended changes to existing records.

@makeplane
Copy link

makeplane bot commented Jun 12, 2025

Pull Request Linked with Plane Work Items

Comment Automatically Generated by Plane

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 13, 2025

Walkthrough

The changes introduce shallow copying of member data before updates in both project and workspace member stores to prevent unintended mutations. Additionally, a new computed function for retrieving sorted workspace member IDs is added, and an existing getter is refactored to use this function for improved code reuse and maintainability.

Changes

File(s) Change Summary
web/core/store/member/base-project-member.store.ts Shallow copy of project membership data before role update to avoid mutating the original object.
web/core/store/member/workspace-member.store.ts Added getWorkspaceMemberIds computed function; refactored workspaceMemberIds getter to use it; shallow copy of member before update.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant WorkspaceMemberStore

    Caller->>WorkspaceMemberStore: getWorkspaceMemberIds(workspaceSlug)
    WorkspaceMemberStore->>WorkspaceMemberStore: Compute member IDs (exclude bots, prioritize current user)
    WorkspaceMemberStore-->>Caller: Sorted member ID list
Loading

Suggested reviewers

  • prateekshourya29
  • gakshita
  • sriramveeraghanta

Poem

In the warren of code, we hop with delight,
Making copies of members, to keep data right.
With functions refactored and logic so neat,
Our store now avoids a mutation repeat.
Sorted IDs in a row,
The rabbit’s code continues to grow! 🐇

✨ 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

🔭 Outside diff range comments (1)
web/core/store/member/base-project-member.store.ts (1)

305-320: ⚠️ Potential issue

Rollback misses several fields & may leave stale state for non-current users.

  1. projectUserInfo is reverted only for the current user.
    For every other user an optimistic write is still present after a failure, so UIs that rely on projectUserInfo will keep showing the wrong role.

  2. workspaceProjectsPermissions is reset with membershipBeforeUpdate.original_role, not with the previously captured permission (permissionBeforeUpdate).
    original_role can be undefined (e.g. first update), which would wipe the permission entry.

Diff suggestion:

-const permissionBeforeUpdate = isCurrentUser
-  ? this.rootStore.user.permission.getProjectRoleByWorkspaceSlugAndProjectId(workspaceSlug, projectId)
-  : undefined;
+const permissionBeforeUpdate =
+  this.rootStore.user.permission.getProjectRoleByWorkspaceSlugAndProjectId(
+    workspaceSlug,
+    projectId,
+  );

@@
-        if (isCurrentUser) {
-          set(
-            this.rootStore.user.permission.workspaceProjectsPermissions,
-            [workspaceSlug, projectId],
-            membershipBeforeUpdate?.original_role
-          );
-          set(
-            this.rootStore.user.permission.projectUserInfo,
-            [workspaceSlug, projectId, "role"],
-            permissionBeforeUpdate
-          );
-        }
+        // revert workspace-level permission only for current user
+        if (isCurrentUser) {
+          set(
+            this.rootStore.user.permission.workspaceProjectsPermissions,
+            [workspaceSlug, projectId],
+            permissionBeforeUpdate,
+          );
+        }
+        // projectUserInfo should be reverted for **all** users
+        set(
+          this.rootStore.user.permission.projectUserInfo,
+          [workspaceSlug, projectId, "role"],
+          permissionBeforeUpdate,
+        );
🧹 Nitpick comments (1)
web/core/store/member/workspace-member.store.ts (1)

226-236: Variable name & rollback typo reduce clarity

originalProjectMemberData doesn’t match the workspace context and is referenced in the catch block. Rename to avoid confusion and ensure the rollback uses the renamed variable.

-const originalProjectMemberData = { ...this.workspaceMemberMap?.[workspaceSlug]?.[userId] };
+const originalWorkspaceMemberData = { ...this.workspaceMemberMap?.[workspaceSlug]?.[userId] };
...
-        set(this.workspaceMemberMap, [workspaceSlug, userId], originalProjectMemberData);
+        set(this.workspaceMemberMap, [workspaceSlug, userId], originalWorkspaceMemberData);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ad11a34 and 0fa7f68.

📒 Files selected for processing (2)
  • web/core/store/member/base-project-member.store.ts (1 hunks)
  • web/core/store/member/workspace-member.store.ts (4 hunks)
🔇 Additional comments (3)
web/core/store/member/base-project-member.store.ts (1)

276-277: 👍 Good call on keeping an immutable snapshot of the membership.

A shallow spread copy of the original membership lets you roll back fast without leaking proxies from MobX.
LGTM.

web/core/store/member/workspace-member.store.ts (2)

97-101: Empty array vs. null – changed semantics, verify callers.

workspaceMemberIds now returns [] when a slug is present but no members exist, whereas it previously returned null.
If any consumers relied on the old null check (if (!ids) …) they will now treat “no members” as “members loaded”, which can break loading spinners or pagination logic.
Please audit the usages.


115-124: Nice reuse & bot filtering.

Extracting the logic into getWorkspaceMemberIds and filtering out bots declutters the getter and is consistent with the project-member store.

@sriramveeraghanta sriramveeraghanta merged commit cf595de into preview Jun 16, 2025
5 of 6 checks passed
@sriramveeraghanta sriramveeraghanta deleted the fix-members-optimistic-update branch June 16, 2025 08:32
vamsikrishnamathala pushed a commit that referenced this pull request Aug 7, 2025
* refactor: move web utils to packages

* fix: build and lint errors

* chore: update drag handle plugin

* chore: update table cell type to fix build errors

* fix: build errors

* chore: sync few changes

* feat: add pi base url to constants

* chore: update all util imports in ee folder

* chore: refactor web utils imports

* chore: update imports

* fix: build errors

* fix: build errors

* fix: update utils import

* chore: minor fixes related to duplicate assets imports

* chore: update duplicate assets service

* [WEB-4316] chore: new endpoints to download an asset (#7207)

* chore: new endpoints to download an asset

* chore: add exception handling

* [WEB-4323] refactor: Analytics refactor (#7213)

* chore: updated label for epics

* chore: improved export logic

* refactor: move csvConfig to export.ts and clean up export logic

* refactor: remove unused CSV export logic from WorkItemsInsightTable component

* refactor: streamline data handling in InsightTable component for improved rendering

* feat: add translation for "No. of {entity}" and update priority chart y-axis label to use new translation

* refactor: cleaned up some component and added utilitites

* feat: add "at_risk" translation to multiple languages in translations.json files

* refactor: update TrendPiece component to use new status variants for analytics

* fix: adjust TrendPiece component logic for on-track and off-track status

* refactor: use nullish coalescing operator for yAxis.dx in line and scatter charts

* feat: add "at_risk" translation to various languages in translations.json files

* feat: add "no_of" translation to various languages in translations.json files

* feat: update "at_risk" translation in Ukrainian, Vietnamese, and Chinese locales in translations.json files

* refactor: rename insightsFields to ANALYTICS_INSIGHTS_FIELDS and update analytics tab import to use getAnalyticsTabs function

* feat: update AnalyticsWrapper to use i18n for titles and add new translation for "no_of" in Russian

* fix: update yAxis labels and offsets in various charts to use new translation key and improve layout

* feat: define AnalyticsTab interface and refactor getAnalyticsTabs function for improved type safety

* fix: update AnalyticsTab interface to use TAnalyticsTabsBase for improved type safety

* fix: add whitespace-nowrap class to TableHead for improved header layout in DataTable component

* [WEB-4311]  fix: membership data handling and state reversal on error (#7205)

* [WEB-4231] Pie chart tooltip #7192

* fix: build errors

* fix: utils imports

* chore: fix build errors

* yarn lock file update

---------

Co-authored-by: Aaryan Khandelwal <65252264+aaryan610@users.noreply.github.com>
Co-authored-by: JayashTripathy <76092296+JayashTripathy@users.noreply.github.com>
Co-authored-by: sriram veeraghanta <veeraghanta.sriram@gmail.com>
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