import React from 'react'; import {RouteComponentProps} from 'react-router'; import styled from '@emotion/styled'; import Feature from 'app/components/acl/feature'; import CreateAlertButton from 'app/components/createAlertButton'; import * as Layout from 'app/components/layouts/thirds'; import ExternalLink from 'app/components/links/externalLink'; import List from 'app/components/list'; import ListItem from 'app/components/list/listItem'; import {Panel, PanelBody, PanelHeader} from 'app/components/panels'; import SentryDocumentTitle from 'app/components/sentryDocumentTitle'; import {t} from 'app/locale'; import space from 'app/styles/space'; import {Organization, Project} from 'app/types'; import BuilderBreadCrumbs from 'app/views/alerts/builder/builderBreadCrumbs'; import {Dataset} from 'app/views/settings/incidentRules/types'; import { AlertType, AlertWizardAlertNames, AlertWizardOptions, AlertWizardPanelContent, AlertWizardRuleTemplates, } from './options'; import RadioPanelGroup from './radioPanelGroup'; type RouteParams = { orgId: string; projectId: string; }; type Props = RouteComponentProps & { organization: Organization; project: Project; hasMetricAlerts: boolean; }; type State = { alertOption: AlertType | null; }; class AlertWizard extends React.Component { state: State = { alertOption: null, }; handleChangeAlertOption = (alertOption: AlertType) => { this.setState({alertOption}); }; renderCreateAlertButton() { const {organization, project, location} = this.props; const {alertOption} = this.state; const metricRuleTemplate = alertOption && AlertWizardRuleTemplates[alertOption]; const disabled = !organization.features.includes('performance-view') && metricRuleTemplate?.dataset === Dataset.TRANSACTIONS; const to = { pathname: `/organizations/${organization.slug}/alerts/${project.slug}/new/`, query: { ...(metricRuleTemplate && metricRuleTemplate), createFromWizard: true, referrer: location?.query?.referrer, }, }; return ( {t('Set Conditions')} ); } render() { const { hasMetricAlerts, organization, params: {projectId}, } = this.props; const {alertOption} = this.state; const title = t('Alert Creation Wizard'); const panelContent = alertOption && AlertWizardPanelContent[alertOption]; return ( {t('What should we alert you about?')} {t('Errors')} {AlertWizardOptions.map(({categoryHeading, options}, i) => ( {i > 0 && {categoryHeading}} { return [alertType, AlertWizardAlertNames[alertType]]; })} onChange={this.handleChangeAlertOption} value={alertOption} label="alert-option" /> ))} {panelContent && alertOption && (
{AlertWizardAlertNames[alertOption]} {panelContent.description}{' '} {panelContent.docsLink && ( {t('Learn more')} )} {t('Examples')} {panelContent.examples.map((example, i) => ( {example} ))}
)} {this.renderCreateAlertButton()}
); } } const StyledLayoutBody = styled(Layout.Body)` margin-bottom: -${space(3)}; `; const Styledh2 = styled('h2')` font-weight: normal; font-size: ${p => p.theme.fontSizeLarge}; margin-bottom: ${space(1)} !important; `; const WizardBody = styled('div')` display: flex; padding-top: ${space(1)}; `; const WizardOptions = styled('div')` flex: 3; margin-right: ${space(3)}; padding-right: ${space(3)}; max-width: 300px; `; const WizardImage = styled('img')` max-height: 300px; `; const WizardPanel = styled(Panel)<{visible?: boolean}>` max-width: 700px; position: sticky; top: 20px; flex: 5; display: flex; ${p => !p.visible && 'visibility: hidden'}; flex-direction: column; align-items: start; align-self: flex-start; ${p => p.visible && 'animation: 0.6s pop ease forwards'}; @keyframes pop { 0% { transform: translateY(30px); opacity: 0; } 100% { transform: translateY(0); opacity: 1; } } `; const ExampleList = styled(List)` margin-bottom: ${space(2)} !important; `; const WizardPanelBody = styled(PanelBody)` flex: 1; min-width: 100%; `; const PanelDescription = styled('p')` margin-bottom: ${space(2)}; `; const ExampleHeader = styled('div')` margin: 0 0 ${space(1)} 0; font-size: ${p => p.theme.fontSizeLarge}; `; const ExampleItem = styled(ListItem)` font-size: ${p => p.theme.fontSizeMedium}; `; const OptionsWrapper = styled('div')` margin-bottom: ${space(4)}; &:last-child { margin-bottom: 0; } `; const WizardButton = styled('div')` border-top: 1px solid ${p => p.theme.border}; padding: ${space(1.5)} ${space(1.5)} ${space(1.5)} ${space(1.5)}; `; export default AlertWizard;