index.tsx 6.4 KB

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