Browse Source

fix(issues): Show warning when custom ignore duration is set in the past [UP-175] (#39893)

There was already a warning, but it didn't actually display to the user
since the modal immediately closed. This keeps the modal open and shows
the warning so the user knows why nothing happened.
Malachi Willey 2 years ago
parent
commit
f3f83209ad

+ 28 - 0
static/app/components/actions/ignore.spec.jsx

@@ -3,6 +3,7 @@ import {
   renderGlobalModal,
   screen,
   userEvent,
+  within,
 } from 'sentry-test/reactTestingLibrary';
 
 import IgnoreActions from 'sentry/components/actions/ignore';
@@ -62,4 +63,31 @@ describe('IgnoreActions', function () {
       expect(spy).toHaveBeenCalled();
     });
   });
+
+  describe('custom', function () {
+    it('can ignore until a custom date/time', function () {
+      render(
+        <IgnoreActions onUpdate={spy} shouldConfirm confirmMessage={() => 'confirm me'} />
+      );
+      renderGlobalModal();
+
+      userEvent.click(screen.getByRole('button', {name: 'Ignore options'}));
+      userEvent.hover(screen.getByRole('menuitemradio', {name: 'For…'}));
+      userEvent.click(screen.getByRole('menuitemradio', {name: /Custom/}));
+
+      // opens modal
+      expect(screen.getByRole('dialog')).toBeInTheDocument();
+
+      userEvent.click(
+        within(screen.getByRole('dialog')).getByRole('button', {name: 'Ignore'})
+      );
+
+      expect(spy).toHaveBeenCalledWith({
+        status: 'ignored',
+        statusDetails: {
+          ignoreDuration: expect.any(Number),
+        },
+      });
+    });
+  });
 });

+ 7 - 5
static/app/components/customIgnoreDurationModal.tsx

@@ -48,13 +48,15 @@ export default class CustomIgnoreDurationModal extends Component<Props, State> {
   snoozeClicked = () => {
     const minutes = this.selectedIgnoreMinutes();
 
-    this.setState({
-      dateWarning: minutes <= 0,
-    });
+    if (minutes <= 0) {
+      this.setState({
+        dateWarning: minutes <= 0,
+      });
 
-    if (minutes > 0) {
-      this.props.onSelected({ignoreDuration: minutes});
+      return;
     }
+
+    this.props.onSelected({ignoreDuration: minutes});
     this.props.closeModal();
   };