setupAlertIntegrationButton.tsx 2.4 KB

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