Browse Source

feat(alert-preview): keep track of preview endpoint (#41875)

Frontend change to go with
[this](https://github.com/getsentry/sentry/pull/41858). Preview endpoint
also returns the endpoint of the window, and should be passed back for
the next calls to preview.
Andrew Xue 2 years ago
parent
commit
772c70bca9

+ 17 - 0
static/app/views/alerts/create.spec.jsx

@@ -470,6 +470,7 @@ describe('ProjectAlertsCreate', function () {
         body: groups,
         headers: {
           'X-Hits': groups.length,
+          Endpoint: 'endpoint',
         },
       });
       createWrapper({organization});
@@ -483,6 +484,7 @@ describe('ProjectAlertsCreate', function () {
               filterMatch: 'all',
               filters: [],
               frequency: 60 * 24,
+              endpoint: null,
             },
           })
         );
@@ -495,6 +497,20 @@ describe('ProjectAlertsCreate', function () {
       for (const group of groups) {
         expect(screen.getByText(group.shortId)).toBeInTheDocument();
       }
+
+      await selectEvent.select(screen.getByText('Add optional trigger...'), [
+        'A new issue is created',
+      ]);
+      await waitFor(() => {
+        expect(mock).toHaveBeenLastCalledWith(
+          expect.any(String),
+          expect.objectContaining({
+            data: expect.objectContaining({
+              endpoint: 'endpoint',
+            }),
+          })
+        );
+      });
     });
 
     it('invalid preview alert', async () => {
@@ -517,6 +533,7 @@ describe('ProjectAlertsCreate', function () {
         body: [],
         headers: {
           'X-Hits': 0,
+          Endpoint: 'endpoint',
         },
       });
       createWrapper({organization});

+ 6 - 1
static/app/views/alerts/rules/issue/index.tsx

@@ -154,6 +154,7 @@ type State = AsyncView['state'] & {
   issueCount: number;
   loadingPreview: boolean;
   previewCursor: string | null | undefined;
+  previewEndpoint: null | string;
   previewError: boolean;
   previewGroups: string[] | null;
   previewPage: number;
@@ -251,6 +252,7 @@ class IssueRuleEditor extends AsyncView<Props, State> {
       sendingNotification: false,
       incompatibleConditions: null,
       incompatibleFilters: null,
+      previewEndpoint: null,
     };
 
     const projectTeamIds = new Set(project.teams.map(({id}) => id));
@@ -365,7 +367,7 @@ class IssueRuleEditor extends AsyncView<Props, State> {
 
   fetchPreview = (resetCursor = false) => {
     const {organization} = this.props;
-    const {project, rule, previewCursor} = this.state;
+    const {project, rule, previewCursor, previewEndpoint} = this.state;
 
     if (!rule || !organization.features.includes('issue-alert-preview')) {
       return;
@@ -390,6 +392,7 @@ class IssueRuleEditor extends AsyncView<Props, State> {
           actionMatch: rule?.actionMatch || 'all',
           filterMatch: rule?.filterMatch || 'all',
           frequency: rule?.frequency || 60,
+          endpoint: previewEndpoint,
         },
       })
       .then(([data, _, resp]) => {
@@ -397,6 +400,7 @@ class IssueRuleEditor extends AsyncView<Props, State> {
 
         const pageLinks = resp?.getResponseHeader('Link');
         const hits = resp?.getResponseHeader('X-Hits');
+        const endpoint = resp?.getResponseHeader('Endpoint');
         const issueCount =
           typeof hits !== 'undefined' && hits ? parseInt(hits, 10) || 0 : 0;
         this.setState({
@@ -405,6 +409,7 @@ class IssueRuleEditor extends AsyncView<Props, State> {
           pageLinks: pageLinks ?? '',
           issueCount,
           loadingPreview: false,
+          previewEndpoint: endpoint ?? null,
         });
       })
       .catch(_ => {