fix(metrics): Update selected metric on project change#112944
fix(metrics): Update selected metric on project change#112944nsdeschenes wants to merge 2 commits intomasterfrom
Conversation
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>
Sentry Snapshot Testing
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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; | ||
| } |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit 0831919. Configure here.


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.