Browse Source

feat(crons): Allow ownership assignment in create / edit (#68808)

Refs GH-68807
Evan Purkhiser 11 months ago
parent
commit
b0f4b6b8c6

+ 2 - 0
fixtures/js-stubs/monitor.tsx

@@ -6,6 +6,7 @@ import {
 } from 'sentry/views/monitors/types';
 
 import {ProjectFixture} from './project';
+import {UserFixture} from './user';
 
 export function MonitorFixture(params: Partial<Monitor> = {}): Monitor {
   return {
@@ -15,6 +16,7 @@ export function MonitorFixture(params: Partial<Monitor> = {}): Monitor {
     project: ProjectFixture(),
     slug: 'my-monitor',
     status: 'active',
+    owner: `user:${UserFixture().id}`,
     type: MonitorType.CRON_JOB,
     config: {
       checkin_margin: 5,

+ 15 - 1
static/app/views/monitors/components/monitorForm.spec.tsx

@@ -19,7 +19,10 @@ jest.mock('sentry/utils/useTeams');
 jest.mock('sentry/utils/useMembers');
 
 describe('MonitorForm', function () {
-  const organization = OrganizationFixture({features: ['issue-platform']});
+  const organization = OrganizationFixture({
+    features: ['issue-platform', 'crons-ownership'],
+  });
+
   const member = MemberFixture({user: UserFixture({name: 'John Smith'})});
   const team = TeamFixture({slug: 'test-team'});
   const {project, routerContext} = initializeOrg({organization});
@@ -116,6 +119,9 @@ describe('MonitorForm', function () {
       '2'
     );
 
+    const ownerSelect = screen.getByRole('textbox', {name: 'Owner'});
+    await selectEvent.select(ownerSelect, 'John Smith');
+
     const notifySelect = screen.getByRole('textbox', {name: 'Notify'});
 
     await selectEvent.openMenu(notifySelect);
@@ -156,6 +162,7 @@ describe('MonitorForm', function () {
         data: {
           name: 'My Monitor',
           project: 'project-slug',
+          owner: `user:${member.user?.id}`,
           type: 'cron_job',
           config,
           alertRule,
@@ -219,6 +226,12 @@ describe('MonitorForm', function () {
     expect(screen.getByRole('spinbutton', {name: 'Failure Tolerance'})).toHaveValue(2);
     expect(screen.getByRole('spinbutton', {name: 'Recovery Tolerance'})).toHaveValue(2);
 
+    // Ownership
+    await selectEvent.openMenu(screen.getByRole('textbox', {name: 'Owner'}));
+    const ownerOption = screen.getByRole('menuitemradio', {name: member.user?.name});
+    expect(ownerOption).toBeChecked();
+    await userEvent.keyboard('{Escape}');
+
     // Alert rule configuration
     await selectEvent.openMenu(screen.getByRole('textbox', {name: 'Notify'}));
     const memberOption = screen.getByRole('menuitemcheckbox', {name: member.user?.name});
@@ -268,6 +281,7 @@ describe('MonitorForm', function () {
           name: monitor.name,
           slug: monitor.slug,
           project: monitor.project.slug,
+          owner: `user:${member.user?.id}`,
           type: 'cron_job',
           config,
           alertRule,

+ 24 - 0
static/app/views/monitors/components/monitorForm.tsx

@@ -225,6 +225,7 @@ function MonitorForm({
   ];
 
   const hasIssuePlatform = organization.features.includes('issue-platform');
+  const hasOwnership = organization.features.includes('crons-ownership');
 
   return (
     <Form
@@ -238,6 +239,7 @@ function MonitorForm({
           ? {
               name: monitor.name,
               slug: monitor.slug,
+              owner: monitor.owner,
               type: monitor.type ?? DEFAULT_MONITOR_TYPE,
               project: monitor.project.slug,
               'alertRule.targets': alertRuleTarget,
@@ -451,6 +453,28 @@ function MonitorForm({
             </InputGroup>
           </Fragment>
         )}
+        {hasOwnership && (
+          <Fragment>
+            <StyledListItem>{t('Set Owner')}</StyledListItem>
+            <ListItemSubText>
+              {t(
+                'Choose a team or member as the monitor owner. Issues created will be automatically assigned to the owner.'
+              )}
+            </ListItemSubText>
+            <InputGroup>
+              <Panel>
+                <PanelBody>
+                  <SentryMemberTeamSelectorField
+                    name="owner"
+                    label={t('Owner')}
+                    help={t('Automatically assign issues to a team or user.')}
+                    menuPlacement="auto"
+                  />
+                </PanelBody>
+              </Panel>
+            </InputGroup>
+          </Fragment>
+        )}
         <StyledListItem>{t('Notifications')}</StyledListItem>
         <ListItemSubText>
           {t('Configure who to notify upon issue creation and when.')}

+ 1 - 0
static/app/views/monitors/types.tsx

@@ -121,6 +121,7 @@ export interface Monitor {
   id: string;
   isMuted: boolean;
   name: string;
+  owner: string;
   project: Project;
   slug: string;
   status: ObjectStatus;