setupAlertIntegrationButton.tsx 2.6 KB

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