index.tsx 6.3 KB

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