index.tsx 2.3 KB

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