index.tsx 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import React from 'react';
  2. import {RouteComponentProps} from 'react-router';
  3. import styled from '@emotion/styled';
  4. import Feature from 'app/components/acl/feature';
  5. import CreateAlertButton from 'app/components/createAlertButton';
  6. import * as Layout from 'app/components/layouts/thirds';
  7. import ExternalLink from 'app/components/links/externalLink';
  8. import List from 'app/components/list';
  9. import ListItem from 'app/components/list/listItem';
  10. import {Panel, PanelBody, PanelHeader} from 'app/components/panels';
  11. import SentryDocumentTitle from 'app/components/sentryDocumentTitle';
  12. import {t} from 'app/locale';
  13. import space from 'app/styles/space';
  14. import {Organization, Project} from 'app/types';
  15. import BuilderBreadCrumbs from 'app/views/alerts/builder/builderBreadCrumbs';
  16. import {Dataset} from 'app/views/settings/incidentRules/types';
  17. import {
  18. AlertType,
  19. AlertWizardAlertNames,
  20. AlertWizardOptions,
  21. AlertWizardPanelContent,
  22. AlertWizardRuleTemplates,
  23. } from './options';
  24. import RadioPanelGroup from './radioPanelGroup';
  25. type RouteParams = {
  26. orgId: string;
  27. projectId: string;
  28. };
  29. type Props = RouteComponentProps<RouteParams, {}> & {
  30. organization: Organization;
  31. project: Project;
  32. hasMetricAlerts: boolean;
  33. };
  34. type State = {
  35. alertOption: AlertType | null;
  36. };
  37. class AlertWizard extends React.Component<Props, State> {
  38. state: State = {
  39. alertOption: null,
  40. };
  41. handleChangeAlertOption = (alertOption: AlertType) => {
  42. this.setState({alertOption});
  43. };
  44. renderCreateAlertButton() {
  45. const {organization, project, location} = this.props;
  46. const {alertOption} = this.state;
  47. const metricRuleTemplate = alertOption && AlertWizardRuleTemplates[alertOption];
  48. const disabled =
  49. !organization.features.includes('performance-view') &&
  50. metricRuleTemplate?.dataset === Dataset.TRANSACTIONS;
  51. const to = {
  52. pathname: `/organizations/${organization.slug}/alerts/${project.slug}/new/`,
  53. query: {
  54. ...(metricRuleTemplate && metricRuleTemplate),
  55. createFromWizard: true,
  56. referrer: location?.query?.referrer,
  57. },
  58. };
  59. return (
  60. <CreateAlertButton
  61. organization={organization}
  62. projectSlug={project.slug}
  63. priority="primary"
  64. to={to}
  65. disabled={disabled}
  66. hideIcon
  67. >
  68. {t('Set Conditions')}
  69. </CreateAlertButton>
  70. );
  71. }
  72. render() {
  73. const {
  74. hasMetricAlerts,
  75. organization,
  76. params: {projectId},
  77. } = this.props;
  78. const {alertOption} = this.state;
  79. const title = t('Alert Creation Wizard');
  80. const panelContent = alertOption && AlertWizardPanelContent[alertOption];
  81. return (
  82. <React.Fragment>
  83. <SentryDocumentTitle title={title} projectSlug={projectId} />
  84. <Feature features={['organizations:alert-wizard']}>
  85. <Layout.Header>
  86. <Layout.HeaderContent>
  87. <BuilderBreadCrumbs
  88. hasMetricAlerts={hasMetricAlerts}
  89. orgSlug={organization.slug}
  90. projectSlug={projectId}
  91. title={t('Create Alert Rule')}
  92. />
  93. <Layout.Title>{t('What should we alert you about?')}</Layout.Title>
  94. </Layout.HeaderContent>
  95. </Layout.Header>
  96. <StyledLayoutBody>
  97. <Layout.Main fullWidth>
  98. <WizardBody>
  99. <WizardOptions>
  100. <Styledh2>{t('Errors')}</Styledh2>
  101. {AlertWizardOptions.map(({categoryHeading, options}, i) => (
  102. <OptionsWrapper key={categoryHeading}>
  103. {i > 0 && <Styledh2>{categoryHeading}</Styledh2>}
  104. <RadioPanelGroup
  105. choices={options.map(alertType => {
  106. return [alertType, AlertWizardAlertNames[alertType]];
  107. })}
  108. onChange={this.handleChangeAlertOption}
  109. value={alertOption}
  110. label="alert-option"
  111. />
  112. </OptionsWrapper>
  113. ))}
  114. </WizardOptions>
  115. <WizardPanel visible={!!panelContent && !!alertOption}>
  116. <WizardPanelBody>
  117. {panelContent && alertOption && (
  118. <div>
  119. <PanelHeader>{AlertWizardAlertNames[alertOption]}</PanelHeader>
  120. <PanelBody withPadding>
  121. <PanelDescription>
  122. {panelContent.description}{' '}
  123. {panelContent.docsLink && (
  124. <ExternalLink href={panelContent.docsLink}>
  125. {t('Learn more')}
  126. </ExternalLink>
  127. )}
  128. </PanelDescription>
  129. <WizardImage src={panelContent.illustration} />
  130. <ExampleHeader>{t('Examples')}</ExampleHeader>
  131. <ExampleList symbol="bullet">
  132. {panelContent.examples.map((example, i) => (
  133. <ExampleItem key={i}>{example}</ExampleItem>
  134. ))}
  135. </ExampleList>
  136. </PanelBody>
  137. </div>
  138. )}
  139. <WizardButton>{this.renderCreateAlertButton()}</WizardButton>
  140. </WizardPanelBody>
  141. </WizardPanel>
  142. </WizardBody>
  143. </Layout.Main>
  144. </StyledLayoutBody>
  145. </Feature>
  146. </React.Fragment>
  147. );
  148. }
  149. }
  150. const StyledLayoutBody = styled(Layout.Body)`
  151. margin-bottom: -${space(3)};
  152. `;
  153. const Styledh2 = styled('h2')`
  154. font-weight: normal;
  155. font-size: ${p => p.theme.fontSizeLarge};
  156. margin-bottom: ${space(1)} !important;
  157. `;
  158. const WizardBody = styled('div')`
  159. display: flex;
  160. padding-top: ${space(1)};
  161. `;
  162. const WizardOptions = styled('div')`
  163. flex: 3;
  164. margin-right: ${space(3)};
  165. padding-right: ${space(3)};
  166. max-width: 300px;
  167. `;
  168. const WizardImage = styled('img')`
  169. max-height: 300px;
  170. `;
  171. const WizardPanel = styled(Panel)<{visible?: boolean}>`
  172. max-width: 700px;
  173. position: sticky;
  174. top: 20px;
  175. flex: 5;
  176. display: flex;
  177. ${p => !p.visible && 'visibility: hidden'};
  178. flex-direction: column;
  179. align-items: start;
  180. align-self: flex-start;
  181. ${p => p.visible && 'animation: 0.6s pop ease forwards'};
  182. @keyframes pop {
  183. 0% {
  184. transform: translateY(30px);
  185. opacity: 0;
  186. }
  187. 100% {
  188. transform: translateY(0);
  189. opacity: 1;
  190. }
  191. }
  192. `;
  193. const ExampleList = styled(List)`
  194. margin-bottom: ${space(2)} !important;
  195. `;
  196. const WizardPanelBody = styled(PanelBody)`
  197. flex: 1;
  198. min-width: 100%;
  199. `;
  200. const PanelDescription = styled('p')`
  201. margin-bottom: ${space(2)};
  202. `;
  203. const ExampleHeader = styled('div')`
  204. margin: 0 0 ${space(1)} 0;
  205. font-size: ${p => p.theme.fontSizeLarge};
  206. `;
  207. const ExampleItem = styled(ListItem)`
  208. font-size: ${p => p.theme.fontSizeMedium};
  209. `;
  210. const OptionsWrapper = styled('div')`
  211. margin-bottom: ${space(4)};
  212. &:last-child {
  213. margin-bottom: 0;
  214. }
  215. `;
  216. const WizardButton = styled('div')`
  217. border-top: 1px solid ${p => p.theme.border};
  218. padding: ${space(1.5)} ${space(1.5)} ${space(1.5)} ${space(1.5)};
  219. `;
  220. export default AlertWizard;