Skip to content

Fix multi-organization selection not being retained during selective share#10468

Open
SujanSanjula96 wants to merge 1 commit into
wso2:masterfrom
SujanSanjula96:fix/issue-7605
Open

Fix multi-organization selection not being retained during selective share#10468
SujanSanjula96 wants to merge 1 commit into
wso2:masterfrom
SujanSanjula96:fix/issue-7605

Conversation

@SujanSanjula96

Copy link
Copy Markdown
Contributor

Purpose

Related Issues

  • N/A

Related PRs

  • N/A

Checklist

  • e2e cypress tests locally verified. (for internal contributers)
  • Manual test round performed and verified.
  • UX/UI review done on the final implementation.
  • Documentation provided. (Add links if there are any)
  • Relevant backend changes deployed and verified
  • Unit tests provided. (Add links if there are any)
  • Integration tests provided. (Add links if there are any)

Security checks

Developer Checklist (Mandatory)

  • Complete the Developer Checklist in the related product-is issue to track any behavioral change or migration impact.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a patch changeset and updates the selective org share tree to reconcile bulk selection changes from RichTreeView against the current selection array instead of handling each item toggle separately.

Changes

Selective org share selection

Layer / File(s) Summary
Bulk selection reconciliation
features/common.ui.shared-access.v1/components/selective-org-share-with-selective-roles.tsx, .changeset/shy-rules-share.md
The tree now uses onSelectedItemsChange, the component diffs the new selection against selectedItems before calling resolveSelectedItems, and the changeset records the patch release for @wso2is/common.ui.shared-access.v1.
🚥 Pre-merge checks | ✅ 5 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The template is present, but the Purpose section is empty and the checklist/security items are left unfilled. Add a brief Purpose summary of the change and complete the relevant checklist and security items, or mark only the truly applicable ones.
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main fix: retaining multi-organization selection during selective share.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Changeset Required ✅ Passed PASS: The PR adds .changeset/shy-rules-share.md, a new non-README changeset entry with a patch release for @wso2is/common.ui.shared-access.v1.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ create changeset

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@features/common.ui.shared-access.v1/components/selective-org-share-with-selective-roles.tsx`:
- Around line 861-872: The bulk-selection path in handleSelectedItemsChange can
add the same parent org multiple times because
resolveSelectedItems/selectParentNodes rely on render-time selectedItems and
addedOrgs closures while processing several siblings in one synchronous pass.
Fix this by reconciling additions with a locally accumulated Set or by deduping
inside the functional state updaters used in selectParentNodes so each parent ID
is only appended once, and verify the recursion guard in selectParentNodes still
terminates correctly after the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: d64931b9-5af5-43ac-8008-d423cc0d27b5

📥 Commits

Reviewing files that changed from the base of the PR and between 0651514 and caf30fe.

📒 Files selected for processing (2)
  • .changeset/shy-rules-share.md
  • features/common.ui.shared-access.v1/components/selective-org-share-with-selective-roles.tsx

Comment on lines +861 to +872
const handleSelectedItemsChange = (newSelectedItems: string[]): void => {
const newSet: Set<string> = new Set(newSelectedItems);
const prevSet: Set<string> = new Set(selectedItems);

// Items newly selected: present in the new selection but not in the previous one.
const addedItems: string[] = newSelectedItems.filter((itemId: string) => !prevSet.has(itemId));
// Items deselected: present in the previous selection but not in the new one.
const removedItems: string[] = selectedItems.filter((itemId: string) => !newSet.has(itemId));

addedItems.forEach((itemId: string) => resolveSelectedItems(itemId, true));
removedItems.forEach((itemId: string) => resolveSelectedItems(itemId, false));
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Batching multiple selections can push duplicate parent org IDs into selectedItems/addedOrgs.

resolveSelectedItems(itemId, true) calls selectParentNodes, which guards with selectedItems.includes(parentNode.id) and addedOrgs.includes(...) read from the render-time closure, then appends via setSelectedItems(prev => [ ...prev, parentNode.id ]). When the array handler processes several newly-added siblings that share a parent in a single synchronous pass, each iteration sees the same stale arrays (no parent yet) and appends the parent again, producing duplicate IDs in selectedItems and addedOrgs.

The previous per-toggle path re-rendered between events, refreshing those closures, so duplicates didn't accumulate — this bulk path is exactly the multi-select scenario this PR enables, so it's newly reachable.

Consider reconciling against a locally-accumulated set rather than relying on the stale closure between iterations (or dedupe in the functional updaters):

🛠️ One option: dedupe in the parent-selection updater
-        if (!selectedItems.includes(parentNode.id)) {
-            setSelectedItems((prev: string[]) => [ ...prev, parentNode.id ]);
-            selectParentNodes(parentNode.id);
-
-            // add the selected organization to the addedOrgs list if it is not already there
-            if (!addedOrgs.includes(parentNode.id)) {
-                setAddedOrgs((addedOrgs: string[]) => [ ...addedOrgs, parentNode.id ]);
-            }
-        }
+        setSelectedItems((prev: string[]) =>
+            prev.includes(parentNode.id) ? prev : [ ...prev, parentNode.id ]);
+        setAddedOrgs((prev: string[]) =>
+            prev.includes(parentNode.id) ? prev : [ ...prev, parentNode.id ]);
+        selectParentNodes(parentNode.id);

Note: the recursion guard for selectParentNodes also needs rethinking if you change the early-exit; verify termination on cyclic-free trees.

Want me to draft a full reconciliation that builds the next selectedItems/addedOrgs/removedOrgs from a single accumulated set to avoid stale-closure batching issues?

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@features/common.ui.shared-access.v1/components/selective-org-share-with-selective-roles.tsx`
around lines 861 - 872, The bulk-selection path in handleSelectedItemsChange can
add the same parent org multiple times because
resolveSelectedItems/selectParentNodes rely on render-time selectedItems and
addedOrgs closures while processing several siblings in one synchronous pass.
Fix this by reconciling additions with a locally accumulated Set or by deduping
inside the functional state updaters used in selectParentNodes so each parent ID
is only appended once, and verify the recursion guard in selectParentNodes still
terminates correctly after the change.

@codecov

codecov Bot commented Jun 25, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 72.73%. Comparing base (05c202e) to head (caf30fe).
⚠️ Report is 100 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #10468    +/-   ##
========================================
  Coverage   72.72%   72.73%            
========================================
  Files         469      469            
  Lines       70888    70908    +20     
  Branches      484      240   -244     
========================================
+ Hits        51555    51572    +17     
- Misses      19037    19225   +188     
+ Partials      296      111   -185     

see 187 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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.

1 participant