-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(aci): Move monitor project/environment fields from the header to the form body #111762
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
47bd68e
feat(aci): Move project/environment fields from the header into the body
malwilley d46264f
Rename base fields to just name field
malwilley 5ae3c60
Better header layout
malwilley def3f67
Merge branch 'master' into malwilley/detector-form-layout
malwilley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
static/app/views/detectors/components/forms/common/detectorNameField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import {EditableText} from 'sentry/components/editableText'; | ||
| import {FormField} from 'sentry/components/forms/formField'; | ||
| import * as Layout from 'sentry/components/layouts/thirds'; | ||
| import {t} from 'sentry/locale'; | ||
| import {useDetectorFormContext} from 'sentry/views/detectors/components/forms/context'; | ||
|
|
||
| export function DetectorNameField() { | ||
| const {setHasSetDetectorName} = useDetectorFormContext(); | ||
|
|
||
| return ( | ||
| <Layout.Title> | ||
| <FormField name="name" inline={false} flexibleControlStateSize stacked> | ||
| {({onChange, value}) => ( | ||
| <EditableText | ||
| allowEmpty | ||
| value={value || ''} | ||
| onChange={newValue => { | ||
| onChange(newValue, { | ||
| target: { | ||
| value: newValue, | ||
| }, | ||
| }); | ||
| setHasSetDetectorName(true); | ||
| }} | ||
| placeholder={t('New Monitor')} | ||
| aria-label={t('Monitor Name')} | ||
| /> | ||
| )} | ||
| </FormField> | ||
| </Layout.Title> | ||
| ); | ||
| } |
49 changes: 49 additions & 0 deletions
49
static/app/views/detectors/components/forms/common/environmentField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| import {SelectField} from 'sentry/components/forms/fields/selectField'; | ||
| import {useFormField} from 'sentry/components/workflowEngine/form/useFormField'; | ||
| import {t} from 'sentry/locale'; | ||
| import {useProjects} from 'sentry/utils/useProjects'; | ||
|
|
||
| export interface EnvironmentConfig { | ||
| fieldProps?: Partial<React.ComponentProps<typeof SelectField>>; | ||
| includeAllEnvironments?: boolean; | ||
| } | ||
|
|
||
| type EnvironmentFieldProps = Partial<React.ComponentProps<typeof SelectField>> & { | ||
| includeAllEnvironments?: boolean; | ||
| }; | ||
|
|
||
| export function EnvironmentField({ | ||
| includeAllEnvironments = true, | ||
| ...props | ||
| }: EnvironmentFieldProps) { | ||
| const {projects} = useProjects(); | ||
| const projectId = useFormField<string>('projectId')!; | ||
|
|
||
| const environments = projects.find(p => p.id === projectId)?.environments ?? []; | ||
|
|
||
| return ( | ||
| <StyledEnvironmentField | ||
| choices={[ | ||
| ...(includeAllEnvironments ? [['', t('All Environments')] as const] : []), | ||
| ...(environments?.map(environment => [environment, environment] as const) ?? []), | ||
| ]} | ||
| inline={false} | ||
| flexibleControlStateSize | ||
| stacked | ||
| name="environment" | ||
| label={t('Environment')} | ||
| placeholder={t('Environment')} | ||
| aria-label={t('Select Environment')} | ||
| size="sm" | ||
| {...props} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const StyledEnvironmentField = styled(SelectField)` | ||
| flex-grow: 1; | ||
| max-width: 260px; | ||
| padding: 0; | ||
| `; |
40 changes: 40 additions & 0 deletions
40
static/app/views/detectors/components/forms/common/projectEnvironmentSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import {Flex} from '@sentry/scraps/layout'; | ||
|
|
||
| import {Container} from 'sentry/components/workflowEngine/ui/container'; | ||
| import {Section} from 'sentry/components/workflowEngine/ui/section'; | ||
| import {t} from 'sentry/locale'; | ||
| import { | ||
| EnvironmentField, | ||
| type EnvironmentConfig, | ||
| } from 'sentry/views/detectors/components/forms/common/environmentField'; | ||
| import {ProjectField} from 'sentry/views/detectors/components/forms/common/projectField'; | ||
|
|
||
| export type {EnvironmentConfig}; | ||
|
|
||
| interface ProjectEnvironmentSectionProps { | ||
| environment?: EnvironmentConfig; | ||
| } | ||
|
|
||
| export function ProjectEnvironmentSection({environment}: ProjectEnvironmentSectionProps) { | ||
| const environmentConfig = { | ||
| includeAllEnvironments: true, | ||
| ...environment, | ||
| }; | ||
|
|
||
| return ( | ||
| <Container> | ||
| <Section | ||
| title={t('Choose the Project and Environment')} | ||
| description={t('This is where issues will be created.')} | ||
| > | ||
| <Flex gap="md"> | ||
| <ProjectField /> | ||
| <EnvironmentField | ||
| includeAllEnvironments={environmentConfig.includeAllEnvironments} | ||
| {...(environmentConfig.fieldProps ?? {})} | ||
| /> | ||
| </Flex> | ||
| </Section> | ||
| </Container> | ||
| ); | ||
| } |
51 changes: 51 additions & 0 deletions
51
static/app/views/detectors/components/forms/common/projectField.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import styled from '@emotion/styled'; | ||
|
|
||
| import {SentryProjectSelectorField} from 'sentry/components/forms/fields/sentryProjectSelectorField'; | ||
| import {t} from 'sentry/locale'; | ||
| import {useProjects} from 'sentry/utils/useProjects'; | ||
| import {useDetectorFormContext} from 'sentry/views/detectors/components/forms/context'; | ||
| import {useCanEditDetector} from 'sentry/views/detectors/utils/useCanEditDetector'; | ||
|
|
||
| export function ProjectField() { | ||
| const {projects, fetching} = useProjects(); | ||
| const {project, detectorType} = useDetectorFormContext(); | ||
| const canEditDetector = useCanEditDetector({projectId: project.id, detectorType}); | ||
|
|
||
| return ( | ||
| <StyledProjectField | ||
| inline={false} | ||
| flexibleControlStateSize | ||
| stacked | ||
| projects={projects} | ||
| groupProjects={p => (p.isMember ? 'member' : 'all')} | ||
| groups={[ | ||
| {key: 'member', label: t('My Projects')}, | ||
| {key: 'all', label: t('All Projects')}, | ||
| ]} | ||
| name="projectId" | ||
| label={t('Project')} | ||
| placeholder={t('Project')} | ||
| aria-label={t('Select Project')} | ||
| disabled={fetching} | ||
| size="sm" | ||
| required | ||
| validate={() => { | ||
| if (!canEditDetector) { | ||
| return [ | ||
| [ | ||
| 'projectId', | ||
| t('You do not have permission to create or edit monitors in this project'), | ||
| ], | ||
| ]; | ||
| } | ||
| return []; | ||
| }} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| const StyledProjectField = styled(SentryProjectSelectorField)` | ||
| flex-grow: 1; | ||
| max-width: 260px; | ||
| padding: 0; | ||
| `; | ||
17 changes: 17 additions & 0 deletions
17
static/app/views/detectors/components/forms/common/projectSection.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import {Container} from 'sentry/components/workflowEngine/ui/container'; | ||
| import {Section} from 'sentry/components/workflowEngine/ui/section'; | ||
| import {t} from 'sentry/locale'; | ||
| import {ProjectField} from 'sentry/views/detectors/components/forms/common/projectField'; | ||
|
|
||
| export function ProjectSection() { | ||
| return ( | ||
| <Container> | ||
| <Section | ||
| title={t('Choose a Project')} | ||
| description={t('This is where issues will be created.')} | ||
| > | ||
| <ProjectField /> | ||
| </Section> | ||
| </Container> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 0 additions & 150 deletions
150
static/app/views/detectors/components/forms/detectorBaseFields.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: The
ProjectFieldvalidation checks permissions against the initial project from context, not the currently selected project in the form, leading to incorrect permission errors.Severity: MEDIUM
Suggested Fix
The validation logic should get the currently selected project ID from the form state using
useFormField('projectId')instead of relying on the staleprojectfromDetectorFormContext. This will ensure permissions are checked against the user's actual selection.Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Uh oh!
There was an error while loading. Please reload this page.
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.
Hmm this is just code that I moved over so it's not related to theses changes, but there does appear to be a bug here.
Created a linear issue: ISWF-2330