projectPluginRow.tsx 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import {PureComponent} from 'react';
  2. import {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 {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 {id, name, slug, version, author, hasConfiguration, enabled, canDisable} =
  39. this.props;
  40. const configureUrl = recreateRoute(id, this.props);
  41. return (
  42. <Access access={['project:write']}>
  43. {({hasAccess}) => {
  44. const LinkOrSpan = hasAccess ? Link : 'span';
  45. return (
  46. <PluginItem key={id} className={slug}>
  47. <PluginInfo>
  48. <StyledPluginIcon size={48} pluginId={id} />
  49. <PluginDescription>
  50. <PluginName>
  51. {`${name} `}
  52. {getDynamicText({
  53. value: (
  54. <Version>{version ? `v${version}` : <em>{t('n/a')}</em>}</Version>
  55. ),
  56. fixed: <Version>v10</Version>,
  57. })}
  58. </PluginName>
  59. <div>
  60. {author && (
  61. <ExternalLink css={grayText} href={author.url}>
  62. {author.name}
  63. </ExternalLink>
  64. )}
  65. {hasConfiguration && (
  66. <span>
  67. {' '}
  68. &middot;{' '}
  69. <LinkOrSpan css={grayText} to={configureUrl}>
  70. {t('Configure plugin')}
  71. </LinkOrSpan>
  72. </span>
  73. )}
  74. </div>
  75. </PluginDescription>
  76. </PluginInfo>
  77. <Switch
  78. size="lg"
  79. isDisabled={!hasAccess || !canDisable}
  80. isActive={enabled}
  81. toggle={this.handleChange}
  82. />
  83. </PluginItem>
  84. );
  85. }}
  86. </Access>
  87. );
  88. }
  89. }
  90. export default withOrganization(ProjectPluginRow);
  91. const PluginItem = styled('div')`
  92. display: flex;
  93. flex: 1;
  94. align-items: center;
  95. `;
  96. const PluginDescription = styled('div')`
  97. display: flex;
  98. justify-content: center;
  99. flex-direction: column;
  100. `;
  101. const PluginInfo = styled('div')`
  102. display: flex;
  103. flex: 1;
  104. line-height: 24px;
  105. `;
  106. const PluginName = styled('div')`
  107. font-size: 16px;
  108. `;
  109. const StyledPluginIcon = styled(PluginIcon)`
  110. margin-right: 16px;
  111. `;
  112. // Keeping these colors the same from old integrations page
  113. const Version = styled('span')`
  114. color: #babec2;
  115. `;