Skip to content

fix(app-platform): Render unpublished integrations #13524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import SentryAppComponentsActions from 'app/actions/sentryAppComponentActions';
export function fetchSentryAppComponents(api, orgSlug, projectId) {
const componentsUri = `/organizations/${orgSlug}/sentry-app-components/?projectId=${projectId}`;

const promise = api.requestPromise(componentsUri);
promise.then(res => SentryAppComponentsActions.loadComponents(res));
return promise;
return api.requestPromise(componentsUri).then(res => {
SentryAppComponentsActions.loadComponents(res);
return res;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,8 @@ class ExternalIssueList extends AsyncComponent {

return components.map(component => {
const {sentryApp} = component;

const installation = sentryAppInstallations.find(
i => i.sentryApp.uuid === sentryApp.uuid
i => i.app.uuid === sentryApp.uuid
);

const issue = (externalIssues || []).find(i => i.serviceType == sentryApp.slug);
Expand Down
10 changes: 1 addition & 9 deletions src/sentry/static/sentry/app/components/group/sidebar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const GroupSidebar = createReactClass({
group: SentryTypes.Group,
event: SentryTypes.Event,
environments: PropTypes.arrayOf(SentryTypes.Environment),
sentryAppInstallations: PropTypes.array,
},

getInitialState() {
Expand Down Expand Up @@ -228,13 +227,7 @@ const GroupSidebar = createReactClass({
},

render() {
const {
group,
organization,
project,
environments,
sentryAppInstallations,
} = this.props;
const {group, organization, project, environments} = this.props;
const projectId = project.slug;

return (
Expand All @@ -254,7 +247,6 @@ const GroupSidebar = createReactClass({
group={this.props.group}
project={project}
orgId={organization.slug}
sentryAppInstallations={sentryAppInstallations}
/>
</ErrorBoundary>

Expand Down
14 changes: 13 additions & 1 deletion src/sentry/static/sentry/app/stores/sentryAppStore.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Reflux from 'reflux';
import {uniqBy} from 'lodash';

const SentryAppStore = Reflux.createStore({
init() {
Expand All @@ -11,7 +12,14 @@ const SentryAppStore = Reflux.createStore({

load(items) {
this.items = items;
this.trigger(items);
this.deDup();
this.trigger(this.items);
},

add(...apps) {
apps.forEach(app => this.items.push(app));
this.deDup();
this.trigger(this.items);
},

get(slug) {
Expand All @@ -21,6 +29,10 @@ const SentryAppStore = Reflux.createStore({
getAll() {
return this.items;
},

deDup() {
this.items = uniqBy(this.items, i => i.uuid);
},
});

export default SentryAppStore;
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import SentryAppStore from 'app/stores/sentryAppStore';

const fetchSentryAppInstallations = (api, orgSlug) => {
const sentryAppsUri = '/sentry-apps/';
const ownedSentryAppsUri = `/organizations/${orgSlug}/sentry-apps/`;
const installsUri = `/organizations/${orgSlug}/sentry-app-installations/`;

function updateSentryAppStore(sentryApps) {
SentryAppStore.load(sentryApps);
}

function fetchOwnedSentryApps() {
api.requestPromise(ownedSentryAppsUri).then(apps => SentryAppStore.add(...apps));
}

function fetchInstalls() {
api
.requestPromise(installsUri)
Expand All @@ -28,6 +33,7 @@ const fetchSentryAppInstallations = (api, orgSlug) => {
api
.requestPromise(sentryAppsUri)
.then(updateSentryAppStore)
.then(fetchOwnedSentryApps)
.then(fetchInstalls);
};

Expand Down
172 changes: 115 additions & 57 deletions tests/js/spec/views/organizationGroupDetails/groupEventDetails.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,7 @@ describe('groupEventDetails', () => {
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: [],
tags: [{key: 'environment', value: 'dev'}],
});

const mockGroupApis = () => {
MockApiClient.addMockResponse({
url: `/issues/${group.id}/`,
body: group,
Expand Down Expand Up @@ -67,12 +52,36 @@ describe('groupEventDetails', () => {
url: `/groups/${group.id}/integrations/`,
body: [],
});
};

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: [],
tags: [{key: 'environment', value: 'dev'}],
});

mockGroupApis();

MockApiClient.addMockResponse({
url: '/sentry-apps/',
body: [],
});

MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-apps/`,
body: [],
});

MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-app-installations/`,
body: [],
Expand Down Expand Up @@ -195,51 +204,100 @@ describe('groupEventDetails', () => {
});
});

it('loads Sentry Apps', () => {
const request = MockApiClient.addMockResponse({
url: '/sentry-apps/',
body: [],
describe('Platform Integrations', () => {
let wrapper; // eslint-disable-line
let integrationsRequest;
let orgIntegrationsRequest;
let componentsRequest;

const mountWrapper = () => {
return mount(
<GroupEventDetails
api={new MockApiClient()}
group={group}
project={project}
organization={org}
environments={[{id: '1', name: 'dev', displayName: 'Dev'}]}
params={{orgId: org.slug, groupId: group.id, eventId: '1'}}
location={{query: {environment: 'dev'}}}
/>,
routerContext
);
};

beforeEach(() => {
const integration = TestStubs.SentryApp();
const unpublishedIntegration = TestStubs.SentryApp({status: 'unpublished'});
const internalIntegration = TestStubs.SentryApp({status: 'internal'});

const unpublishedInstall = TestStubs.SentryAppInstallation({
app: {
slug: unpublishedIntegration.slug,
uuid: unpublishedIntegration.uuid,
},
});

const internalInstall = TestStubs.SentryAppInstallation({
app: {
slug: internalIntegration.slug,
uuid: internalIntegration.uuid,
},
});

const component = TestStubs.SentryAppComponent({
sentryApp: {
uuid: unpublishedIntegration.uuid,
slug: unpublishedIntegration.slug,
name: unpublishedIntegration.name,
},
});

MockApiClient.clearMockResponses();
mockGroupApis();

MockApiClient.addMockResponse({
url: `/projects/${org.slug}/${project.slug}/events/1/`,
body: event,
});

componentsRequest = MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-app-components/?projectId=${project.id}`,
body: [component],
});

MockApiClient.addMockResponse({
url: `/projects/${org.slug}/${project.slug}/events/1/`,
body: event,
});

integrationsRequest = MockApiClient.addMockResponse({
url: '/sentry-apps/',
body: [integration],
});

MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-app-installations/`,
body: [unpublishedInstall, internalInstall],
});

orgIntegrationsRequest = MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-apps/`,
body: [unpublishedIntegration, internalIntegration],
});

wrapper = mountWrapper();
});

project.organization = org;

mount(
<GroupEventDetails
api={new MockApiClient()}
group={group}
project={project}
organization={org}
environments={[{id: '1', name: 'dev', displayName: 'Dev'}]}
params={{}}
location={{}}
/>,
routerContext
);

expect(request).toHaveBeenCalledTimes(1);
});

it('loads sentry app components when flagged in', () => {
const request = MockApiClient.addMockResponse({
url: `/organizations/${org.slug}/sentry-app-components/?projectId=${project.id}`,
body: [],
it('loads Integrations', () => {
expect(integrationsRequest).toHaveBeenCalled();
});

project.organization = org;

mount(
<GroupEventDetails
api={new MockApiClient()}
group={group}
project={project}
organization={org}
environments={[{id: '1', name: 'dev', displayName: 'Dev'}]}
params={{}}
location={{}}
/>,
routerContext
);
it('loads unpublished and internal Integrations', () => {
expect(orgIntegrationsRequest).toHaveBeenCalled();
});

expect(request).toHaveBeenCalledTimes(1);
it('loads Integration UI components', () => {
expect(componentsRequest).toHaveBeenCalled();
});
});
});