index.tsx 8.1 KB

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