setupAlertIntegrationButton.tsx 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import {Button} from 'sentry/components/button';
  2. import DeprecatedAsyncComponent from 'sentry/components/deprecatedAsyncComponent';
  3. import {Tooltip} from 'sentry/components/tooltip';
  4. import {t} from 'sentry/locale';
  5. import PluginIcon from 'sentry/plugins/components/pluginIcon';
  6. import ConfigStore from 'sentry/stores/configStore';
  7. import type {Organization} from 'sentry/types/organization';
  8. import type {Project} from 'sentry/types/project';
  9. type Props = DeprecatedAsyncComponent['props'] & {
  10. organization: Organization;
  11. projectSlug: string;
  12. };
  13. type State = DeprecatedAsyncComponent['state'] & {
  14. detailedProject?: Project & {
  15. hasAlertIntegrationInstalled: boolean;
  16. };
  17. };
  18. /**
  19. * This component renders a button to Set up an alert integration (just Slack for now)
  20. * if the project has no alerting integrations setup already.
  21. */
  22. export default class SetupAlertIntegrationButton extends DeprecatedAsyncComponent<
  23. Props,
  24. State
  25. > {
  26. getEndpoints(): ReturnType<DeprecatedAsyncComponent['getEndpoints']> {
  27. const {projectSlug, organization} = this.props;
  28. return [
  29. [
  30. 'detailedProject',
  31. `/projects/${organization.slug}/${projectSlug}/?expand=hasAlertIntegration`,
  32. ],
  33. ];
  34. }
  35. renderLoading() {
  36. return null;
  37. }
  38. // if there is an error, just show nothing
  39. renderError() {
  40. return null;
  41. }
  42. renderBody(): React.ReactNode {
  43. const {organization} = this.props;
  44. const {detailedProject} = this.state;
  45. // don't render anything if we don't have the project yet or if an alert integration
  46. // is installed
  47. if (!detailedProject || detailedProject.hasAlertIntegrationInstalled) {
  48. return null;
  49. }
  50. const {isSelfHosted} = ConfigStore.getState();
  51. // link to docs to set up Slack for self-hosted folks
  52. const referrerQuery = '?referrer=issue-alert-builder';
  53. const buttonProps = isSelfHosted
  54. ? {
  55. href: `https://develop.sentry.dev/integrations/slack/${referrerQuery}`,
  56. }
  57. : {
  58. to: `/settings/${organization.slug}/integrations/slack/${referrerQuery}`,
  59. };
  60. // TOOD(Steve): need to use the Tooltip component because adding a title to the button
  61. // puts the tooltip in the upper left hand corner of the page instead of the button
  62. return (
  63. <Tooltip title={t('Send Alerts to Slack. Install the integration now.')}>
  64. <Button
  65. size="sm"
  66. icon={<PluginIcon pluginId="slack" size={16} />}
  67. {...buttonProps}
  68. >
  69. {t('Set Up Slack Now')}
  70. </Button>
  71. </Tooltip>
  72. );
  73. }
  74. }