feat(tracemetrics): Add alert via dropdown in explore#112963
Conversation
Allows alerts to be added from the 'saveas' dropdown in metrics tab. Will show as 'monitors' for the new workflow engine ui.
| const alertsUrls = metricQueries | ||
| .filter(mq => isVisualizeFunction(mq.queryParams.visualizes[0]!)) | ||
| .map((metricQuery, index) => { | ||
| const visualize = metricQuery.queryParams.visualizes[0]!; |
There was a problem hiding this comment.
We should prob fix this in another PR to not allow multiple if they are really 1:1
Sentry Snapshot Testing
|
| const project = | ||
| projects.length === 1 | ||
| ? projects[0] | ||
| : projects.find(p => p.id === `${pageFilters.selection.projects[0]}`); |
There was a problem hiding this comment.
Bug: When "All Projects" is selected, the project variable becomes undefined, causing the alert creation URL to lack a pre-selected project, degrading the user experience.
Severity: LOW
Suggested Fix
Add an explicit check to handle the "All Projects" case. If pageFilters.selection.projects is empty or contains the sentinel value for all projects, do not attempt to find a specific project. Instead, allow the alert creation URL to be generated without a project, or implement logic to handle this case as intended, ensuring the user experience is not degraded.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: static/app/views/explore/metrics/useSaveAsMetricItems.tsx#L52-L55
Potential issue: When a user has "All Projects" or "My Projects" selected in the metrics
explore view, the logic to determine the current project results in an `undefined`
value. This is because `projects.find(p => p.id ===
`${pageFilters.selection.projects[0]}`)` fails when `pageFilters.selection.projects[0]`
is `undefined` or `-1`. While the downstream `getAlertsUrl()` function handles the
`undefined` project gracefully by generating a URL without a project slug, this leads to
a functional regression. The user is navigated to the alert creation page but must
manually re-select the project, losing the context from the explore view.
Did we get this right? 👍 / 👎 to inform future reviews.
Allows alerts to be added from the 'saveas' dropdown in metrics tab. Will show as 'monitors' for the new workflow engine ui.
Equations are not allowed since they aren't supported in alerts yet.