-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
feat(aci): Add simpler UX for connecting alerts to a project #104221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(aci): Add simpler UX for connecting alerts to a project #104221
Conversation
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
| label={t('Connected monitors mode')} | ||
| value={monitorMode} | ||
| choices={[ | ||
| ['project', t('Alert on all issues in a project')], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be something like "Alert on all issues in selected project(s)" since it's multiselect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept this wording because it is more simple/direct and the input is obviously multi-select, but I can see it going either way
| const {data: issueStreamDetectors} = useIssueStreamDetectors(); | ||
| const initialMode = getInitialMonitorMode(issueStreamDetectors, connectedIds); | ||
|
|
||
| if (!initialMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be checking if the issue stream detector query is loading here instead of checking initialMode, then if the query fails we use the specific mode?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah true, that's better - updated!
…ng-alerts-to-a-project
| // Sync the derived selectedProjectIds to the form model so the field can read from it | ||
| useEffect(() => { | ||
| const selectedProjectIds = | ||
| issueStreamDetectorsQuery.data | ||
| ?.filter(detector => connectedIds.includes(detector.id)) | ||
| .map(d => d.projectId) ?? []; | ||
| if (form && selectedProjectIds.length > 0) { | ||
| form.setValue('projectIds', selectedProjectIds); | ||
| } | ||
| }, [connectedIds, form, issueStreamDetectorsQuery.data]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: useEffect fails to clear projectIds in form model when selectedProjectIds is empty, causing stale data submission.
Severity: HIGH | Confidence: High
🔍 Detailed Analysis
When a user clears all project selections in SentryProjectSelectorField, the useEffect hook's condition selectedProjectIds.length > 0 prevents form.setValue('projectIds', selectedProjectIds) from being called. This leaves the form model's projectIds field with stale, previously selected values, even though connectedIds is correctly updated to []. Consequently, submitting the form sends incorrect, outdated projectIds, leading to incorrect automation connections.
💡 Suggested Fix
Remove the selectedProjectIds.length > 0 condition from the useEffect hook, ensuring form.setValue('projectIds', selectedProjectIds) is always called when form exists, even if selectedProjectIds is an empty array.
🤖 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/automations/components/editConnectedMonitors.tsx#L204-L213
Potential issue: When a user clears all project selections in
`SentryProjectSelectorField`, the `useEffect` hook's condition
`selectedProjectIds.length > 0` prevents `form.setValue('projectIds',
selectedProjectIds)` from being called. This leaves the form model's `projectIds` field
with stale, previously selected values, even though `connectedIds` is correctly updated
to `[]`. Consequently, submitting the form sends incorrect, outdated `projectIds`,
leading to incorrect automation connections.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5003126
| return connectedIds.every(id => issueStreamDetectors.find(d => d.id === id)) | ||
| ? 'project' | ||
| : 'specific'; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Query error defaults to wrong mode with connected monitors
The getInitialMonitorMode function incorrectly returns 'project' when issueStreamDetectors is undefined due to a failed query, even when connectedIds exist. Per the PR discussion, when the query fails, it should fall back to 'specific' mode to preserve existing behavior and show the user's connected monitors. Currently, a user editing an automation with specific monitors connected would see the project selector instead of their monitors if the issue stream detectors API call fails, potentially leading to data loss on save.
Adds a radio button to the "connect monitors" section. The default flow will be for users to select one or multiple projects that will alert on any issue. We need to fetch all the issue stream monitors in order to match them up with the projects from the dropdown.
The other option is to connect specific monitors, which works the same as it does today.