Browse Source

Revert "fix(app-platform): Conditionally make requests (#12476)" (#12479)

This reverts commit 2d14384214cb0dace2daa6b889bc6da70e7ab549.
Matte Noble 6 years ago
parent
commit
716b7b6d0e

+ 0 - 5
src/sentry/static/sentry/app/components/group/externalIssuesList.jsx

@@ -71,11 +71,6 @@ class ExternalIssueList extends AsyncComponent {
   //
   fetchSentryAppData() {
     const {api, orgId, group, project} = this.props;
-    const features = new Set(project.organization.features);
-
-    if (!features.has('sentry-apps')) {
-      return;
-    }
 
     api
       .requestPromise(

+ 78 - 0
src/sentry/static/sentry/app/utils/withSentryAppInstallations.jsx

@@ -0,0 +1,78 @@
+import React from 'react';
+
+import {Client} from 'app/api';
+import SentryTypes from 'app/sentryTypes';
+import getDisplayName from 'app/utils/getDisplayName';
+import SentryAppInstallationStore from 'app/stores/sentryAppInstallationsStore';
+
+const withSentryAppInstallations = WrappedComponent => {
+  class WithSentryAppInstallations extends React.Component {
+    static displayName = `withSentryAppInstallations(${getDisplayName(
+      WrappedComponent
+    )})`;
+
+    static propTypes = {
+      project: SentryTypes.Project,
+    };
+
+    constructor(props) {
+      super(props);
+      this.api = new Client();
+      this.sentryApps = [];
+    }
+
+    componentWillMount() {
+      this.fetchData();
+    }
+
+    componentWillUnmount() {
+      this.api.clear();
+    }
+
+    fetchData() {
+      const slug = this.props.project.organization.slug;
+
+      this.api
+        .requestPromise(`/organizations/${slug}/sentry-apps/`)
+        .then(data => {
+          this.sentryApps = data;
+          this.fetchInstallations();
+        })
+        .catch(this.gracefullyFail);
+    }
+
+    fetchInstallations() {
+      const slug = this.props.project.organization.slug;
+
+      this.api
+        .requestPromise(`/organizations/${slug}/sentry-app-installations/`)
+        .then(data => {
+          data.forEach(this.addSentryApp);
+          SentryAppInstallationStore.load(data);
+        })
+        .catch(this.gracefullyFail);
+    }
+
+    addSentryApp = install => {
+      install.sentryApp = this.sentryAppByUuid(install.app.uuid);
+    };
+
+    sentryAppByUuid = uuid => {
+      return this.sentryApps.find(a => a.uuid === uuid);
+    };
+
+    gracefullyFail = () => {
+      this.installations = [];
+    };
+
+    render() {
+      return (
+        <WrappedComponent sentryAppInstallations={this.installations} {...this.props} />
+      );
+    }
+  }
+
+  return WithSentryAppInstallations;
+};
+
+export default withSentryAppInstallations;

+ 1 - 5
src/sentry/static/sentry/app/views/groupDetails/shared/groupEventDetails.jsx

@@ -70,11 +70,7 @@ class GroupEventDetails extends React.Component {
         });
       });
 
-    const features = new Set(organization.features);
-
-    if (features.has('sentry-apps')) {
-      fetchSentryAppInstallations(orgSlug);
-    }
+    fetchSentryAppInstallations(orgSlug);
   };
 
   render() {

+ 0 - 122
tests/js/spec/views/groupDetails/groupEventDetails.spec.jsx

@@ -1,122 +0,0 @@
-import React from 'react';
-import {mount} from 'enzyme';
-
-import {initializeOrg} from 'app-test/helpers/initializeOrg';
-import GroupEventDetails from 'app/views/groupDetails/shared/groupEventDetails';
-
-describe('groupEventDetails', () => {
-  let org;
-  let project;
-  let routerContext;
-  let group;
-  let event;
-
-  beforeEach(() => {
-    const props = initializeOrg();
-    org = props.organization;
-    project = props.project;
-    project.organization = org;
-    routerContext = props.routerContext;
-
-    group = TestStubs.Group();
-    event = TestStubs.Event({
-      size: 1,
-      dateCreated: '2019-03-20T00:00:00.000Z',
-      errors: [],
-      entries: [],
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/issues/${group.id}/`,
-      body: group,
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/issues/${group.id}/events/latest/`,
-      body: event,
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/projects/${org.slug}/${project.slug}/issues/`,
-      method: 'PUT',
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/projects/${org.slug}/${project.slug}/events/${event.id}/committers/`,
-      body: {committers: []},
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/projects/${org.slug}/${project.slug}/events/${event.id}/owners/`,
-      body: {owners: [], rules: []},
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/issues/${group.id}/participants/`,
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/issues/${group.id}/tags/`,
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/groups/${group.id}/integrations/`,
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      url: '/sentry-apps/',
-      body: [],
-    });
-
-    MockApiClient.addMockResponse({
-      url: `/organizations/${org.slug}/sentry-app-installations/`,
-      body: [],
-    });
-  });
-
-  it("doesn't load Sentry Apps without being flagged in", () => {
-    const request = MockApiClient.addMockResponse({
-      url: '/sentry-apps/',
-      body: [],
-    });
-
-    mount(
-      <GroupEventDetails
-        group={group}
-        project={project}
-        organization={org}
-        environments={[{id: '1', name: 'dev', displayName: 'Dev'}]}
-        params={{}}
-      />,
-      routerContext
-    );
-
-    expect(request).not.toHaveBeenCalled();
-  });
-
-  it('loads Sentry Apps when flagged in', () => {
-    const request = MockApiClient.addMockResponse({
-      url: '/sentry-apps/',
-      body: [],
-    });
-
-    org.features = ['sentry-apps'];
-    project.organization = org;
-
-    mount(
-      <GroupEventDetails
-        group={group}
-        project={project}
-        organization={org}
-        environments={[{id: '1', name: 'dev', displayName: 'Dev'}]}
-        params={{}}
-      />,
-      routerContext
-    );
-
-    expect(request).toHaveBeenCalledTimes(1);
-  });
-});