Skip to content

fix(metrics): Update selected metric on project change#112944

Draft
nsdeschenes wants to merge 2 commits intomasterfrom
nd/chore-tracemetrics-change-selected-metric-if-project-changes
Draft

fix(metrics): Update selected metric on project change#112944
nsdeschenes wants to merge 2 commits intomasterfrom
nd/chore-tracemetrics-change-selected-metric-if-project-changes

Conversation

@nsdeschenes
Copy link
Copy Markdown
Contributor

Update metrics explore to reconcile the selected metric when the project filter changes.

The selector now falls back to the first available metric when a single-metric view switches to a project that does not contain the current metric. It also leaves multi-metric selections alone and adds regression coverage around both behaviors.

This moved the reconciliation into the selector itself because that component owns the live, project-scoped metric options used by the toolbar.

nsdeschenes and others added 2 commits April 14, 2026 14:12
Move project-change metric reconciliation into the metrics selector so it reacts to the live project-scoped metric options used by the toolbar.

This updates the selected metric only when the metrics page has a single aggregate metric query and the current metric no longer exists in the new project selection.

Co-Authored-By: Codex <noreply@openai.com>
Add regression coverage for the metrics explore project-switch behavior.

The new tests verify that a matching metric is preserved across project changes and that multi-metric selections are not rewritten automatically.

Co-Authored-By: Codex <noreply@openai.com>
@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 14, 2026
@sentry
Copy link
Copy Markdown
Contributor

sentry bot commented Apr 14, 2026

Sentry Snapshot Testing

Name Added Removed Modified Renamed Unchanged Status
sentry-frontend
sentry-frontend
0 0 0 0 204 ✅ Unchanged

Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0831919. Configure here.

previousProjectsRef.current = selection.projects;
pendingProjectValidationRef.current = fallbackOnProjectChange;
sawFetchForPendingProjectRef.current = 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.

Pending validation not cancelled when fallback disabled

Medium Severity

pendingProjectValidationRef is only updated inside the if (projectsChanged) block, so when fallbackOnProjectChange transitions from true to false (e.g., user adds a second metric query while a project-change fetch is in flight), the pending flag stays true. The effect then proceeds with the fallback once the fetch completes, incorrectly overwriting the selected metric even though the multi-metric view is supposed to leave selections alone.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0831919. Configure here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant