setupAlertIntegrationButton.tsx 2.5 KB

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