Skip to content

fix(aci): Selected project state should react to form changes#112484

Merged
malwilley merged 3 commits intomasterfrom
malwilley/detector-ctx-project
Apr 8, 2026
Merged

fix(aci): Selected project state should react to form changes#112484
malwilley merged 3 commits intomasterfrom
malwilley/detector-ctx-project

Conversation

@malwilley
Copy link
Copy Markdown
Member

@malwilley malwilley commented Apr 8, 2026

Closes ISWF-2330

This primarily fixes an issue where the selected project in other parts of the form were not updating correctly when the project was changed.

The full project object was previously stored in a context at the top of the detector form, so other components could use things like the project icon, slug, etc. This PR simplifies things a bit by taking it out of the context and creating a new hook useDetectorFormProject() which takes the project ID from the form state and looks up the project in our cache.

@malwilley malwilley requested a review from a team as a code owner April 8, 2026 16:53
@linear-code
Copy link
Copy Markdown

linear-code bot commented Apr 8, 2026

@github-actions github-actions bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@saponifi3d saponifi3d left a comment

Choose a reason for hiding this comment

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

lgtm

the way i reasoned through the context / data splits here is that the context is setting things that change logic flows / which components are being rendered and therefore is logically different than just form data. is that more or less what you were thinking too?

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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Removed project-not-found guards cause unhandled throws
    • Restored the project-not-found guard in edit.tsx that validates the detector's project exists before rendering the form, preventing useDetectorFormProject() from throwing an uncaught error.

Create PR

Or push these changes by commenting:

@cursor push 825a7867a7
Preview (825a7867a7)
diff --git a/static/app/views/detectors/edit.tsx b/static/app/views/detectors/edit.tsx
--- a/static/app/views/detectors/edit.tsx
+++ b/static/app/views/detectors/edit.tsx
@@ -10,7 +10,7 @@
 
 export default function DetectorEdit() {
   const params = useParams<{detectorId: string}>();
-  const {fetching: isFetchingProjects} = useProjects();
+  const {projects, fetching: isFetchingProjects} = useProjects();
   useWorkflowEngineFeatureGate({redirect: true});
 
   const {
@@ -34,6 +34,11 @@
     );
   }
 
+  const project = projects.find(p => p.id === detector.projectId);
+  if (!project) {
+    return <LoadingError message={t('Project not found')} />;
+  }
+
   return (
     <DetectorFormProvider detectorType={detector.type} detector={detector}>
       <EditExistingDetectorForm detector={detector} />

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 15d15c8. Configure here.

Comment thread static/app/views/detectors/edit.tsx
@malwilley
Copy link
Copy Markdown
Member Author

the way i reasoned through the context / data splits here is that the context is setting things that change logic flows / which components are being rendered and therefore is logically different than just form data. is that more or less what you were thinking too?

Yeah the context is being used for state or data we need in the form components, but which isn't being sent to the endpoint when we save it

Comment thread static/app/views/detectors/components/forms/newDetectorLayout.tsx
@malwilley malwilley merged commit 28bd01a into master Apr 8, 2026
65 checks passed
@malwilley malwilley deleted the malwilley/detector-ctx-project branch April 8, 2026 17:58
george-sentry pushed a commit that referenced this pull request Apr 9, 2026
This primarily fixes an issue where the selected project in other parts
of the form were not updating correctly when the project was changed.

The full project object was previously stored in a context at the top of
the detector form, so other components could use things like the project
icon, slug, etc. This PR simplifies things a bit by taking it out of the
context and creating a new hook `useDetectorFormProject()` which takes
the project ID from the form state and looks up the project in our
cache.
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.

2 participants