index.tsx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import {Component, Fragment} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {disablePlugin, enablePlugin, fetchPlugins} from 'sentry/actionCreators/plugins';
  4. import SentryDocumentTitle from 'sentry/components/sentryDocumentTitle';
  5. import {t} from 'sentry/locale';
  6. import type {Plugin} from 'sentry/types/integrations';
  7. import type {Organization} from 'sentry/types/organization';
  8. import type {Project} from 'sentry/types/project';
  9. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  10. import withPlugins from 'sentry/utils/withPlugins';
  11. import SettingsPageHeader from 'sentry/views/settings/components/settingsPageHeader';
  12. import PermissionAlert from 'sentry/views/settings/project/permissionAlert';
  13. import ProjectPlugins from './projectPlugins';
  14. type Props = RouteComponentProps<{projectId: string}, {}> & {
  15. organization: Organization;
  16. plugins: {
  17. error: React.ComponentProps<typeof ProjectPlugins>['error'];
  18. loading: boolean;
  19. plugins: Plugin[];
  20. };
  21. project: Project;
  22. };
  23. class ProjectPluginsContainer extends Component<Props> {
  24. componentDidMount() {
  25. this.fetchData();
  26. }
  27. fetchData = async () => {
  28. const {organization, params} = this.props;
  29. const plugins = await fetchPlugins({...params, orgId: organization.slug});
  30. const installCount = plugins.filter(
  31. plugin => plugin.hasConfiguration && plugin.enabled
  32. ).length;
  33. trackIntegrationAnalytics(
  34. 'integrations.index_viewed',
  35. {
  36. integrations_installed: installCount,
  37. view: 'legacy_integrations',
  38. organization: this.props.organization,
  39. },
  40. {startSession: true}
  41. );
  42. };
  43. handleChange = (pluginId: string, shouldEnable: boolean) => {
  44. const {organization, params} = this.props;
  45. const actionCreator = shouldEnable ? enablePlugin : disablePlugin;
  46. actionCreator({projectId: params.projectId, orgId: organization.slug, pluginId});
  47. };
  48. render() {
  49. const {loading, error, plugins} = this.props.plugins || {};
  50. const {organization, project} = this.props;
  51. const title = t('Legacy Integrations');
  52. return (
  53. <Fragment>
  54. <SentryDocumentTitle title={title} orgSlug={organization.slug} />
  55. <SettingsPageHeader title={title} />
  56. <PermissionAlert project={project} />
  57. <ProjectPlugins
  58. {...this.props}
  59. onChange={this.handleChange}
  60. loading={loading}
  61. error={error}
  62. plugins={plugins}
  63. />
  64. </Fragment>
  65. );
  66. }
  67. }
  68. export {ProjectPluginsContainer};
  69. export default withPlugins(ProjectPluginsContainer);