index.tsx 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. import React from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import {removeSentryApp} from 'sentry/actionCreators/sentryApps';
  5. import ExternalLink from 'sentry/components/links/externalLink';
  6. import NavTabs from 'sentry/components/navTabs';
  7. import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels';
  8. import {t, tct} from 'sentry/locale';
  9. import space from 'sentry/styles/space';
  10. import {Organization, SentryApp} from 'sentry/types';
  11. import {
  12. platformEventLinkMap,
  13. PlatformEvents,
  14. } from 'sentry/utils/analytics/integrations/platformAnalyticsEvents';
  15. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  16. import routeTitleGen from 'sentry/utils/routeTitle';
  17. import withOrganization from 'sentry/utils/withOrganization';
  18. import AsyncView from 'sentry/views/asyncView';
  19. import CreateIntegrationButton from 'sentry/views/organizationIntegrations/createIntegrationButton';
  20. import ExampleIntegrationButton from 'sentry/views/organizationIntegrations/exampleIntegrationButton';
  21. import EmptyMessage from 'sentry/views/settings/components/emptyMessage';
  22. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  23. import SentryApplicationRow from 'sentry/views/settings/organizationDeveloperSettings/sentryApplicationRow';
  24. type Props = Omit<AsyncView['props'], 'params'> & {
  25. organization: Organization;
  26. } & RouteComponentProps<{orgId: string}, {}>;
  27. type Tab = 'public' | 'internal';
  28. type State = AsyncView['state'] & {
  29. applications: SentryApp[];
  30. tab: Tab;
  31. };
  32. class OrganizationDeveloperSettings extends AsyncView<Props, State> {
  33. analyticsView = 'developer_settings' as const;
  34. getDefaultState(): State {
  35. const {location} = this.props;
  36. const value =
  37. (['public', 'internal'] as const).find(tab => tab === location?.query?.type) ||
  38. 'internal';
  39. return {
  40. ...super.getDefaultState(),
  41. applications: [],
  42. tab: value,
  43. };
  44. }
  45. get tab() {
  46. return this.state.tab;
  47. }
  48. getTitle() {
  49. const {orgId} = this.props.params;
  50. return routeTitleGen(t('Developer Settings'), orgId, false);
  51. }
  52. getEndpoints(): ReturnType<AsyncView['getEndpoints']> {
  53. const {orgId} = this.props.params;
  54. return [['applications', `/organizations/${orgId}/sentry-apps/`]];
  55. }
  56. removeApp = (app: SentryApp) => {
  57. const apps = this.state.applications.filter(a => a.slug !== app.slug);
  58. removeSentryApp(this.api, app).then(
  59. () => {
  60. this.setState({applications: apps});
  61. },
  62. () => {}
  63. );
  64. };
  65. onTabChange = (value: Tab) => {
  66. this.setState({tab: value});
  67. };
  68. renderApplicationRow = (app: SentryApp) => {
  69. const {organization} = this.props;
  70. return (
  71. <SentryApplicationRow
  72. key={app.uuid}
  73. app={app}
  74. organization={organization}
  75. onRemoveApp={this.removeApp}
  76. />
  77. );
  78. };
  79. renderInternalIntegrations() {
  80. const integrations = this.state.applications.filter(
  81. (app: SentryApp) => app.status === 'internal'
  82. );
  83. const isEmpty = integrations.length === 0;
  84. return (
  85. <Panel>
  86. <PanelHeader>{t('Internal Integrations')}</PanelHeader>
  87. <PanelBody>
  88. {!isEmpty ? (
  89. integrations.map(this.renderApplicationRow)
  90. ) : (
  91. <EmptyMessage>
  92. {t('No internal integrations have been created yet.')}
  93. </EmptyMessage>
  94. )}
  95. </PanelBody>
  96. </Panel>
  97. );
  98. }
  99. renderPublicIntegrations() {
  100. const integrations = this.state.applications.filter(app => app.status !== 'internal');
  101. const isEmpty = integrations.length === 0;
  102. return (
  103. <Panel>
  104. <PanelHeader>{t('Public Integrations')}</PanelHeader>
  105. <PanelBody>
  106. {!isEmpty ? (
  107. integrations.map(this.renderApplicationRow)
  108. ) : (
  109. <EmptyMessage>
  110. {t('No public integrations have been created yet.')}
  111. </EmptyMessage>
  112. )}
  113. </PanelBody>
  114. </Panel>
  115. );
  116. }
  117. renderTabContent(tab: Tab) {
  118. switch (tab) {
  119. case 'internal':
  120. return this.renderInternalIntegrations();
  121. case 'public':
  122. default:
  123. return this.renderPublicIntegrations();
  124. }
  125. }
  126. renderBody() {
  127. const {organization} = this.props;
  128. const tabs = [
  129. ['internal', t('Internal Integration')],
  130. ['public', t('Public Integration')],
  131. ] as [id: Tab, label: string][];
  132. return (
  133. <div>
  134. <SettingsPageHeader
  135. title={t('Developer Settings')}
  136. body={
  137. <React.Fragment>
  138. {t(
  139. 'Create integrations that interact with Sentry using the REST API and webhooks. '
  140. )}
  141. <br />
  142. {tct('For more information [link: see our docs].', {
  143. link: (
  144. <ExternalLink
  145. href={platformEventLinkMap[PlatformEvents.DOCS]}
  146. onClick={() => {
  147. trackIntegrationAnalytics(PlatformEvents.DOCS, {
  148. organization,
  149. view: this.analyticsView,
  150. });
  151. }}
  152. />
  153. ),
  154. })}
  155. </React.Fragment>
  156. }
  157. action={
  158. <ActionContainer>
  159. <ExampleIntegrationButton
  160. analyticsView={this.analyticsView}
  161. style={{marginRight: space(1)}}
  162. />
  163. <CreateIntegrationButton analyticsView={this.analyticsView} />
  164. </ActionContainer>
  165. }
  166. />
  167. <NavTabs underlined>
  168. {tabs.map(([type, label]) => (
  169. <li
  170. key={type}
  171. className={this.tab === type ? 'active' : ''}
  172. onClick={() => this.onTabChange(type)}
  173. >
  174. <a>{label}</a>
  175. </li>
  176. ))}
  177. </NavTabs>
  178. {this.renderTabContent(this.tab)}
  179. </div>
  180. );
  181. }
  182. }
  183. const ActionContainer = styled('div')`
  184. display: flex;
  185. `;
  186. export default withOrganization(OrganizationDeveloperSettings);