Skip to content

fix: Address auto toggle of ann group#382

Open
igoroctaviano wants to merge 1 commit intomasterfrom
fix/ann-group-auto-toggle
Open

fix: Address auto toggle of ann group#382
igoroctaviano wants to merge 1 commit intomasterfrom
fix/ann-group-auto-toggle

Conversation

@igoroctaviano
Copy link
Copy Markdown
Collaborator

fix: Auto-toggle all annotation groups of an ANN series on load

Summary

Closes the regression reported in #260 (latest comment) where opening a Microscopy Bulk Simple Annotation (ANN) series via URL only toggled the visibility of the first annotation group instead of all annotation groups belonging to that series.

This PR also fixes a related latent bug in the SR ROI visibility handler that was mutating the visibleRoiUIDs/selectedRoiUIDs Set references in place (rather than cloning), which can cause React to bail out of re-rendering on auto-load of SR-derived URLs.

Affected behavior

  • URL: /studies/{studyUID}/series/{annSeriesUID} where the ANN series contains multiple annotation groups.
  • Before this PR: only one annotation group toggle was on after auto-load — the rest stayed hidden until the user manually toggled them.
  • After this PR: every annotation group belonging to the URL series is toggled on automatically. Failures on individual groups (if any) are logged without aborting the rest.

Root cause

SlideViewer.loadDerivedDataset had two compounding issues in the MicroscopyBulkSimpleAnnotation branch:

  1. find() instead of filter() — introduced in #360. When the original behavior from #261 (forEach over all annotation groups) was changed to add a seriesInstanceUID filter, forEach was replaced with find(), so only the first matching annotation group was ever toggled.
  2. Re-throw aborts the loophandleAnnotationGroupVisibilityChange calls volumeViewer.showAnnotationGroup() and re-throws after notifying. Even after switching back to filter().forEach(), a throw on any subsequent group (e.g. a dmv setAnnotationGroupStyle issue) aborted the iteration, leaving only the first group toggled. The per-group runValidations({ dialog: true }) was also designed for manual user toggles, not for automatic load-time iteration over many groups.

A separate latent bug in handleAnnotationVisibilityChange (the SR ROI handler) was mutating the existing Set reference inside setState, which can cause React to bail out of re-rendering since the new state holds the same reference as the previous one.

Changes

src/components/SlideViewer.tsx

loadDerivedDatasetMicroscopyBulkSimpleAnnotation branch:

  • Replaced find() with filter() so all annotation groups whose seriesInstanceUID matches the URL series are picked up, not just the first.
  • Bypassed handleAnnotationGroupVisibilityChange for the auto-load path:
    • Calls volumeViewer.showAnnotationGroup(uid) directly with a per-group try/catch, so a failure on one group no longer aborts the iteration.
    • Skips the per-group runValidations({ dialog: true }) modal (which is intended for manual interactive toggles, not auto-load over N groups).
  • Batched the state update into a single setState at the end that adds all successfully-shown UIDs to visibleAnnotationGroupUIDs, avoiding any chance of intermediate setState/re-render interleavings dropping updates.
  • Added diagnostic logger.debug lines (auto-load Microscopy Bulk Simple Annotation: found N matching annotation group(s) out of M total for series "..." and showing X/N annotation group(s)) plus logger.error per-group failures for easier triage.

handleAnnotationVisibilityChange (SR ROIs) — Set mutation fix:

  • Cloned state.visibleRoiUIDs and state.selectedRoiUIDs (new Set(state.X)) inside the functional setState updater instead of mutating the same reference. This is the same pattern already used by the ANN handler and by the rest of the visibility handlers in the file.

Diff scope

 src/components/SlideViewer.tsx | 62 ++++++++++++++++++++++++++++++++++--------
 1 file changed, 50 insertions(+), 12 deletions(-)

Test plan

Tested locally via bun dev against IDC test data with the following ANN URLs (referenced in the issue):

  • https://andrey-slim-test.web.app/studies/1.2.826.0.1.3680043.8.498.24144283661646178704245748389871574522/series/1.2.826.0.1.3680043.10.511.3.40735706884016056933166099558854806 — multi-group ANN that previously only toggled the first group; now all toggle on.
  • Verify with the broader URL set from the systematic regression sweep in #260:
    • SR (Comprehensive 3D SR) — should remain working
    • SEG (binary + fractional) — should remain working
    • PM (parametric maps) — should remain working
    • ANN (bulk annotations) — multi-group cases now toggle all
  • DevTools console shows the new auto-load diagnostics (found N/M, showing X/N, plus any per-group failed to auto-show… errors that previously broke iteration).
  • Manual toggle behavior in the side panel is unchanged (the existing handleAnnotationGroupVisibilityChange path is untouched for user interaction).
  • Lint / type-check passes (bun lint / TypeScript compile).

Risk / rollback

  • The auto-load path no longer surfaces per-group validation dialogs. If a future use case wants those dialogs at load time, validation can be invoked once per matching group separately from the visibility toggle.
  • The SR ROI Set-cloning change is strictly safer than the previous in-place mutation (matches the pattern used elsewhere in the same component) and does not change the public API.
  • Pure rollback is a single-file revert of src/components/SlideViewer.tsx.

Related

@sonarqubecloud
Copy link
Copy Markdown

@deepsource-io
Copy link
Copy Markdown

deepsource-io Bot commented Apr 30, 2026

DeepSource Code Review

We reviewed changes in f04d0d6...61c369d on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
JavaScript Apr 30, 2026 9:44a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

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.

Add a URL parameter or explicitly list UID to enable visualization of annotations on load

1 participant