Browse Source

ref(crons): Disable env selector when no assignee (#62236)

<img width="879" alt="image"
src="https://github.com/getsentry/sentry/assets/9372512/7c9a8745-e95f-4bc6-a4c9-ae316650ba32">
David Wang 1 year ago
parent
commit
8ad605afce
1 changed files with 22 additions and 8 deletions
  1. 22 8
      static/app/views/monitors/components/monitorForm.tsx

+ 22 - 8
static/app/views/monitors/components/monitorForm.tsx

@@ -470,14 +470,28 @@ function MonitorForm({
                 multiple
                 menuPlacement="auto"
               />
-              <SelectField
-                label={t('Environment')}
-                help={t('Only receive notifications from a specific environment.')}
-                name="alertRule.environment"
-                options={alertRuleEnvs}
-                menuPlacement="auto"
-                defaultValue=""
-              />
+              <Observer>
+                {() => {
+                  const selectedAssignee = form.current.getValue('alertRule.targets');
+                  // Check for falsey value or empty array value
+                  const disabled = !selectedAssignee || !selectedAssignee.toString();
+
+                  return (
+                    <SelectField
+                      label={t('Environment')}
+                      help={t('Only receive notifications from a specific environment.')}
+                      name="alertRule.environment"
+                      options={alertRuleEnvs}
+                      disabled={disabled}
+                      menuPlacement="auto"
+                      defaultValue=""
+                      disabledReason={t(
+                        'Please select which teams or members to notify first.'
+                      )}
+                    />
+                  );
+                }}
+              </Observer>
             </PanelBody>
           </Panel>
         </InputGroup>