1
0
mirror of https://github.com/bitwarden/browser synced 2026-02-04 10:43:47 +00:00

[PM-26676][PM-27291] Implement organization-aware state merging

Update the scan operator in _setupReportState to detect organization
changes and handle them differently from same-org updates.

Logic:
1. If organizationId changed -> Use currState.data directly
   - Allows null to clear old org's data when switching
   - Fixes PM-26676: Org data persists when switching orgs

2. If same org (or no orgId) -> Preserve prevState.data when null
   - Maintains critical flags during loading states
   - Fixes PM-27291: Critical flags lost when generating new reports

This resolves the conflict between PR #17008 and PR #17053:
- PR #17008 needed: "Don't clear data when null" (preserve critical flags)
- PR #17053 needed: "Clear data when null" (remove old org data)

Now both behaviors work correctly by detecting the organization context.

Testing:
- Organization switching: Old org data cleared, new org data loads
- Critical apps: Flags preserved across report generation
- Cross-org: Each org maintains its own critical app flags
This commit is contained in:
Claude
2025-10-30 00:58:30 +00:00
parent 591d431c0c
commit d3e193c7df

View File

@@ -731,11 +731,24 @@ export class RiskInsightsOrchestratorService {
newReportGeneration$,
this._markUnmarkUpdates$,
).pipe(
scan((prevState: ReportState, currState: ReportState) => ({
...prevState,
...currState,
data: currState.data !== null ? currState.data : prevState.data,
})),
scan((prevState: ReportState, currState: ReportState) => {
// If organization changed, use new state completely (don't preserve old data)
// This allows null data to clear old org's data when switching orgs
if (currState.organizationId && prevState.organizationId !== currState.organizationId) {
return {
...currState,
data: currState.data, // Allow null to clear old org's data
};
}
// Same org (or no org ID): preserve data when currState.data is null
// This preserves critical flags during loading states within the same org
return {
...prevState,
...currState,
data: currState.data !== null ? currState.data : prevState.data,
};
}),
startWith({ loading: false, error: null, data: null }),
shareReplay({ bufferSize: 1, refCount: true }),
takeUntil(this._destroy$),