Browse Source

feat(alerts): Opt out of alert being disabled via edit (#56687)

Scott Cooper 1 year ago
parent
commit
dd2276a0ca

+ 7 - 0
static/app/types/alerts.tsx

@@ -90,6 +90,13 @@ export interface IssueAlertRule extends UnsavedIssueAlertRule {
   disableReason?: 'noisy';
   errors?: {detail: string}[];
   lastTriggered?: string;
+  /**
+   * Set to true to opt out of the rule being automatically disabled
+   * see also - status=disabled, disableDate, disableReason
+   * TODO(scttcper): This is only used in the edit request and we should
+   *  move it to its own interface
+   */
+  optOutEdit?: boolean;
   snoozeCreatedBy?: string;
   snoozeForEveryone?: boolean;
 }

+ 22 - 0
static/app/views/alerts/rules/issue/index.spec.tsx

@@ -1,5 +1,6 @@
 import {browserHistory, PlainRoute} from 'react-router';
 import selectEvent from 'react-select-event';
+import moment from 'moment';
 
 import {initializeOrg} from 'sentry-test/initializeOrg';
 import {
@@ -342,6 +343,27 @@ describe('IssueRuleEditor', function () {
         screen.getByText('Post to a Threads channel with these')
       ).toBeInTheDocument();
     });
+
+    it('opts out of the alert being disabled', async function () {
+      MockApiClient.addMockResponse({
+        url: '/projects/org-slug/project-slug/rules/1/',
+        body: TestStubs.ProjectAlertRule({
+          status: 'disabled',
+          disabledDate: moment().add(1, 'day').toISOString(),
+        }),
+      });
+      createWrapper();
+      await userEvent.click(screen.getByText('Save Rule'));
+
+      await waitFor(() =>
+        expect(mock).toHaveBeenCalledWith(
+          endpoint,
+          expect.objectContaining({
+            data: expect.objectContaining({optOutEdit: true}),
+          })
+        )
+      );
+    });
   });
 
   describe('Edit Rule: Slack Channel Look Up', function () {

+ 5 - 0
static/app/views/alerts/rules/issue/index.tsx

@@ -626,6 +626,11 @@ class IssueRuleEditor extends DeprecatedAsyncView<Props, State> {
           delete filter.name;
         }
         transaction.setData('actions', rule.actions);
+
+        // Check if rule is currently disabled or going to be disabled
+        if ('status' in rule && (rule.status === 'disabled' || !!rule.disableDate)) {
+          rule.optOutEdit = true;
+        }
       }
       const [data, , resp] = await this.api.requestPromise(endpoint, {
         includeAllArgs: true,