Skip to content

Commit 70b4379

Browse files
saponifi3dgeorge-sentry
authored andcommitted
feat(aci): Add ability to create envs inline (#112558)
# Description Updated the environment selector to be able to create a new environment inline. Right now, we can only select environments on Uptime and Metric monitors. The Metric monitor will be able to save the new environments after #112537 is deployed. ### Metric Monitor <img width="1624" height="1061" alt="Screenshot 2026-04-08 at 4 56 33 PM" src="https://github.com/user-attachments/assets/f6c2ebef-3b2c-45fe-bc29-839c4be81f35" /> ### Uptime Monitor <img width="1624" height="1061" alt="Screenshot 2026-04-08 at 4 58 48 PM" src="https://github.com/user-attachments/assets/09b61794-3242-48ee-8f03-d3b0ecc05060" /> ### Uptime Saves <img width="1624" height="1061" alt="Screenshot 2026-04-08 at 4 59 33 PM" src="https://github.com/user-attachments/assets/5783da6b-a7f7-4e07-b501-eb7eebcab22f" />
1 parent ddbf8c4 commit 70b4379

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

static/app/views/detectors/components/forms/common/environmentField.tsx

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import {useContext, useState} from 'react';
12
import styled from '@emotion/styled';
23

34
import {SelectField} from 'sentry/components/forms/fields/selectField';
5+
import {FormContext} from 'sentry/components/forms/formContext';
46
import {useFormField} from 'sentry/components/workflowEngine/form/useFormField';
57
import {t} from 'sentry/locale';
68
import {useProjects} from 'sentry/utils/useProjects';
@@ -14,29 +16,42 @@ type EnvironmentFieldProps = Partial<React.ComponentProps<typeof SelectField>> &
1416
includeAllEnvironments?: boolean;
1517
};
1618

19+
const ENV_FIELD_NAME = 'environment';
20+
1721
export function EnvironmentField({
1822
includeAllEnvironments = true,
1923
...props
2024
}: EnvironmentFieldProps) {
2125
const {projects} = useProjects();
2226
const projectId = useFormField<string>('projectId')!;
27+
const formContext = useContext(FormContext);
28+
29+
const [newEnvironment, setNewEnvironment] = useState<string | undefined>(undefined);
2330

2431
const environments = projects.find(p => p.id === projectId)?.environments ?? [];
2532

33+
const choices = [
34+
...(includeAllEnvironments ? [['', t('All Environments')] as const] : []),
35+
...(newEnvironment ? [[newEnvironment, newEnvironment] as const] : []),
36+
...(environments?.map(environment => [environment, environment] as const) ?? []),
37+
];
38+
2639
return (
2740
<StyledEnvironmentField
28-
choices={[
29-
...(includeAllEnvironments ? [['', t('All Environments')] as const] : []),
30-
...(environments?.map(environment => [environment, environment] as const) ?? []),
31-
]}
41+
choices={choices}
3242
inline={false}
3343
flexibleControlStateSize
3444
stacked
35-
name="environment"
45+
name={ENV_FIELD_NAME}
3646
label={t('Environment')}
3747
placeholder={t('Environment')}
3848
aria-label={t('Select Environment')}
3949
size="sm"
50+
creatable
51+
onCreateOption={env => {
52+
setNewEnvironment(env);
53+
formContext.form?.setValue(ENV_FIELD_NAME, env);
54+
}}
4055
{...props}
4156
/>
4257
);

0 commit comments

Comments
 (0)