projectPluginRow.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import {PureComponent} from 'react';
  2. import type {RouteComponentProps} from 'react-router';
  3. import {css} from '@emotion/react';
  4. import styled from '@emotion/styled';
  5. import Access from 'sentry/components/acl/access';
  6. import ExternalLink from 'sentry/components/links/externalLink';
  7. import Link from 'sentry/components/links/link';
  8. import Switch from 'sentry/components/switchButton';
  9. import {t} from 'sentry/locale';
  10. import PluginIcon from 'sentry/plugins/components/pluginIcon';
  11. import type {Organization, Plugin, Project} from 'sentry/types';
  12. import getDynamicText from 'sentry/utils/getDynamicText';
  13. import {trackIntegrationAnalytics} from 'sentry/utils/integrationUtil';
  14. import recreateRoute from 'sentry/utils/recreateRoute';
  15. import withOrganization from 'sentry/utils/withOrganization';
  16. const grayText = css`
  17. color: #979ba0;
  18. `;
  19. type Props = {
  20. onChange: (id: string, enabled: boolean) => void;
  21. organization: Organization;
  22. project: Project;
  23. } & Plugin &
  24. Pick<RouteComponentProps<{}, {}>, 'params' | 'routes'>;
  25. class ProjectPluginRow extends PureComponent<Props> {
  26. handleChange = () => {
  27. const {onChange, id, enabled} = this.props;
  28. onChange(id, !enabled);
  29. const eventKey = !enabled ? 'integrations.enabled' : 'integrations.disabled';
  30. trackIntegrationAnalytics(eventKey, {
  31. integration: id,
  32. integration_type: 'plugin',
  33. view: 'legacy_integrations',
  34. organization: this.props.organization,
  35. });
  36. };
  37. render() {
  38. const {
  39. id,
  40. name,
  41. slug,
  42. version,
  43. author,
  44. hasConfiguration,
  45. enabled,
  46. canDisable,
  47. project,
  48. } = this.props;
  49. const configureUrl = recreateRoute(id, this.props);
  50. return (
  51. <Access access={['project:write']} project={project}>
  52. {({hasAccess}) => {
  53. const LinkOrSpan = hasAccess ? Link : 'span';
  54. return (
  55. <PluginItem key={id} className={slug}>
  56. <PluginInfo>
  57. <StyledPluginIcon size={48} pluginId={id} />
  58. <PluginDescription>
  59. <PluginName>
  60. {`${name} `}
  61. {getDynamicText({
  62. value: (
  63. <Version>{version ? `v${version}` : <em>{t('n/a')}</em>}</Version>
  64. ),
  65. fixed: <Version>v10</Version>,
  66. })}
  67. </PluginName>
  68. <div>
  69. {author && (
  70. <ExternalLink css={grayText} href={author.url}>
  71. {author.name}
  72. </ExternalLink>
  73. )}
  74. {hasConfiguration && (
  75. <span>
  76. {' '}
  77. &middot;{' '}
  78. <LinkOrSpan css={grayText} to={configureUrl}>
  79. {t('Configure plugin')}
  80. </LinkOrSpan>
  81. </span>
  82. )}
  83. </div>
  84. </PluginDescription>
  85. </PluginInfo>
  86. <Switch
  87. size="lg"
  88. isDisabled={!hasAccess || !canDisable}
  89. isActive={enabled}
  90. toggle={this.handleChange}
  91. />
  92. </PluginItem>
  93. );
  94. }}
  95. </Access>
  96. );
  97. }
  98. }
  99. export default withOrganization(ProjectPluginRow);
  100. const PluginItem = styled('div')`
  101. display: flex;
  102. flex: 1;
  103. align-items: center;
  104. `;
  105. const PluginDescription = styled('div')`
  106. display: flex;
  107. justify-content: center;
  108. flex-direction: column;
  109. `;
  110. const PluginInfo = styled('div')`
  111. display: flex;
  112. flex: 1;
  113. line-height: 24px;
  114. `;
  115. const PluginName = styled('div')`
  116. font-size: 16px;
  117. `;
  118. const StyledPluginIcon = styled(PluginIcon)`
  119. margin-right: 16px;
  120. `;
  121. // Keeping these colors the same from old integrations page
  122. const Version = styled('span')`
  123. color: #babec2;
  124. `;