ruleConditionsForm.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. import {Fragment, PureComponent} from 'react';
  2. import type {InjectedRouter} from 'react-router';
  3. import {components} from 'react-select';
  4. import {css} from '@emotion/react';
  5. import styled from '@emotion/styled';
  6. import omit from 'lodash/omit';
  7. import pick from 'lodash/pick';
  8. import {addErrorMessage} from 'sentry/actionCreators/indicator';
  9. import type {Client} from 'sentry/api';
  10. import {
  11. OnDemandMetricAlert,
  12. OnDemandWarningIcon,
  13. } from 'sentry/components/alerts/onDemandMetricAlert';
  14. import SearchBar from 'sentry/components/events/searchBar';
  15. import SelectControl from 'sentry/components/forms/controls/selectControl';
  16. import SelectField from 'sentry/components/forms/fields/selectField';
  17. import FormField from 'sentry/components/forms/formField';
  18. import IdBadge from 'sentry/components/idBadge';
  19. import ListItem from 'sentry/components/list/listItem';
  20. import {MetricSearchBar} from 'sentry/components/metrics/metricSearchBar';
  21. import Panel from 'sentry/components/panels/panel';
  22. import PanelBody from 'sentry/components/panels/panelBody';
  23. import {InvalidReason} from 'sentry/components/searchSyntax/parser';
  24. import {SearchInvalidTag} from 'sentry/components/smartSearchBar/searchInvalidTag';
  25. import {t, tct} from 'sentry/locale';
  26. import {space} from 'sentry/styles/space';
  27. import type {Environment, Organization, Project, SelectValue} from 'sentry/types';
  28. import {ActivationConditionType, MonitorType} from 'sentry/types/alerts';
  29. import {getDisplayName} from 'sentry/utils/environment';
  30. import {hasCustomMetrics} from 'sentry/utils/metrics/features';
  31. import {getMRI} from 'sentry/utils/metrics/mri';
  32. import {getOnDemandKeys, isOnDemandQueryString} from 'sentry/utils/onDemandMetrics';
  33. import {hasOnDemandMetricAlertFeature} from 'sentry/utils/onDemandMetrics/features';
  34. import withApi from 'sentry/utils/withApi';
  35. import withProjects from 'sentry/utils/withProjects';
  36. import WizardField from 'sentry/views/alerts/rules/metric/wizardField';
  37. import {
  38. convertDatasetEventTypesToSource,
  39. DATA_SOURCE_LABELS,
  40. DATA_SOURCE_TO_SET_AND_EVENT_TYPES,
  41. } from 'sentry/views/alerts/utils';
  42. import type {AlertType} from 'sentry/views/alerts/wizard/options';
  43. import {getSupportedAndOmittedTags} from 'sentry/views/alerts/wizard/options';
  44. import {getProjectOptions} from '../utils';
  45. import {isCrashFreeAlert} from './utils/isCrashFreeAlert';
  46. import {DEFAULT_AGGREGATE, DEFAULT_TRANSACTION_AGGREGATE} from './constants';
  47. import type {AlertRuleComparisonType} from './types';
  48. import {Dataset, Datasource, TimeWindow} from './types';
  49. const TIME_WINDOW_MAP: Record<TimeWindow, string> = {
  50. [TimeWindow.ONE_MINUTE]: t('1 minute'),
  51. [TimeWindow.FIVE_MINUTES]: t('5 minutes'),
  52. [TimeWindow.TEN_MINUTES]: t('10 minutes'),
  53. [TimeWindow.FIFTEEN_MINUTES]: t('15 minutes'),
  54. [TimeWindow.THIRTY_MINUTES]: t('30 minutes'),
  55. [TimeWindow.ONE_HOUR]: t('1 hour'),
  56. [TimeWindow.TWO_HOURS]: t('2 hours'),
  57. [TimeWindow.FOUR_HOURS]: t('4 hours'),
  58. [TimeWindow.ONE_DAY]: t('24 hours'),
  59. };
  60. type Props = {
  61. aggregate: string;
  62. alertType: AlertType;
  63. api: Client;
  64. comparisonType: AlertRuleComparisonType;
  65. dataset: Dataset;
  66. disabled: boolean;
  67. isEditing: boolean;
  68. onComparisonDeltaChange: (value: number) => void;
  69. onFilterSearch: (query: string, isQueryValid) => void;
  70. onMonitorTypeSelect: (activatedAlertFields: {
  71. activationCondition?: ActivationConditionType | undefined;
  72. monitorType?: MonitorType;
  73. monitorWindowSuffix?: string | undefined;
  74. monitorWindowValue?: number | undefined;
  75. }) => void;
  76. onTimeWindowChange: (value: number) => void;
  77. organization: Organization;
  78. project: Project;
  79. projects: Project[];
  80. router: InjectedRouter;
  81. thresholdChart: React.ReactNode;
  82. timeWindow: number;
  83. activationCondition?: ActivationConditionType;
  84. allowChangeEventTypes?: boolean;
  85. comparisonDelta?: number;
  86. disableProjectSelector?: boolean;
  87. isErrorMigration?: boolean;
  88. isExtrapolatedChartData?: boolean;
  89. isForSpanMetric?: boolean;
  90. isTransactionMigration?: boolean;
  91. loadingProjects?: boolean;
  92. monitorType?: number;
  93. };
  94. type State = {
  95. environments: Environment[] | null;
  96. };
  97. class RuleConditionsForm extends PureComponent<Props, State> {
  98. state: State = {
  99. environments: null,
  100. };
  101. componentDidMount() {
  102. this.fetchData();
  103. }
  104. componentDidUpdate(prevProps: Props) {
  105. if (prevProps.project.id === this.props.project.id) {
  106. return;
  107. }
  108. this.fetchData();
  109. }
  110. formElemBaseStyle = {
  111. padding: `${space(0.5)}`,
  112. border: 'none',
  113. };
  114. async fetchData() {
  115. const {api, organization, project} = this.props;
  116. try {
  117. const environments = await api.requestPromise(
  118. `/projects/${organization.slug}/${project.slug}/environments/`,
  119. {
  120. query: {
  121. visibility: 'visible',
  122. },
  123. }
  124. );
  125. this.setState({environments});
  126. } catch (_err) {
  127. addErrorMessage(t('Unable to fetch environments'));
  128. }
  129. }
  130. get timeWindowOptions() {
  131. let options: Record<string, string> = TIME_WINDOW_MAP;
  132. const {alertType} = this.props;
  133. if (alertType === 'custom_metrics') {
  134. // Do not show ONE MINUTE interval as an option for custom_metrics alert
  135. options = omit(options, TimeWindow.ONE_MINUTE.toString());
  136. }
  137. if (isCrashFreeAlert(this.props.dataset)) {
  138. options = pick(TIME_WINDOW_MAP, [
  139. // TimeWindow.THIRTY_MINUTES, leaving this option out until we figure out the sub-hour session resolution chart limitations
  140. TimeWindow.ONE_HOUR,
  141. TimeWindow.TWO_HOURS,
  142. TimeWindow.FOUR_HOURS,
  143. TimeWindow.ONE_DAY,
  144. ]);
  145. }
  146. return Object.entries(options).map(([value, label]) => ({
  147. value: parseInt(value, 10),
  148. label: tct('[timeWindow] interval', {
  149. timeWindow: label.slice(-1) === 's' ? label.slice(0, -1) : label,
  150. }),
  151. }));
  152. }
  153. get searchPlaceholder() {
  154. switch (this.props.dataset) {
  155. case Dataset.ERRORS:
  156. return t('Filter events by level, message, and other properties\u2026');
  157. case Dataset.METRICS:
  158. case Dataset.SESSIONS:
  159. return t('Filter sessions by release version\u2026');
  160. default:
  161. return t('Filter transactions by URL, tags, and other properties\u2026');
  162. }
  163. }
  164. get selectControlStyles() {
  165. return {
  166. control: (provided: {[x: string]: string | number | boolean}) => ({
  167. ...provided,
  168. minWidth: 200,
  169. maxWidth: 300,
  170. }),
  171. container: (provided: {[x: string]: string | number | boolean}) => ({
  172. ...provided,
  173. margin: `${space(0.5)}`,
  174. }),
  175. };
  176. }
  177. renderEventTypeFilter() {
  178. const {organization, disabled, alertType, isErrorMigration} = this.props;
  179. const dataSourceOptions = [
  180. {
  181. label: t('Errors'),
  182. options: [
  183. {
  184. value: Datasource.ERROR_DEFAULT,
  185. label: DATA_SOURCE_LABELS[Datasource.ERROR_DEFAULT],
  186. },
  187. {
  188. value: Datasource.DEFAULT,
  189. label: DATA_SOURCE_LABELS[Datasource.DEFAULT],
  190. },
  191. {
  192. value: Datasource.ERROR,
  193. label: DATA_SOURCE_LABELS[Datasource.ERROR],
  194. },
  195. ],
  196. },
  197. ];
  198. if (
  199. organization.features.includes('performance-view') &&
  200. (alertType === 'custom_transactions' || alertType === 'custom_metrics')
  201. ) {
  202. dataSourceOptions.push({
  203. label: t('Transactions'),
  204. options: [
  205. {
  206. value: Datasource.TRANSACTION,
  207. label: DATA_SOURCE_LABELS[Datasource.TRANSACTION],
  208. },
  209. ],
  210. });
  211. }
  212. return (
  213. <FormField
  214. name="datasource"
  215. inline={false}
  216. style={{
  217. ...this.formElemBaseStyle,
  218. minWidth: 300,
  219. flex: 2,
  220. }}
  221. flexibleControlStateSize
  222. >
  223. {({onChange, onBlur, model}) => {
  224. const formDataset = model.getValue('dataset');
  225. const formEventTypes = model.getValue('eventTypes');
  226. const aggregate = model.getValue('aggregate');
  227. const mappedValue = convertDatasetEventTypesToSource(
  228. formDataset,
  229. formEventTypes
  230. );
  231. return (
  232. <SelectControl
  233. value={mappedValue}
  234. inFieldLabel={t('Events: ')}
  235. onChange={({value}) => {
  236. onChange(value, {});
  237. onBlur(value, {});
  238. // Reset the aggregate to the default (which works across
  239. // datatypes), otherwise we may send snuba an invalid query
  240. // (transaction aggregate on events datasource = bad).
  241. const newAggregate =
  242. value === Datasource.TRANSACTION
  243. ? DEFAULT_TRANSACTION_AGGREGATE
  244. : DEFAULT_AGGREGATE;
  245. if (alertType === 'custom_transactions' && aggregate !== newAggregate) {
  246. model.setValue('aggregate', newAggregate);
  247. }
  248. // set the value of the dataset and event type from data source
  249. const {dataset: datasetFromDataSource, eventTypes} =
  250. DATA_SOURCE_TO_SET_AND_EVENT_TYPES[value] ?? {};
  251. model.setValue('dataset', datasetFromDataSource);
  252. model.setValue('eventTypes', eventTypes);
  253. }}
  254. options={dataSourceOptions}
  255. isDisabled={disabled || isErrorMigration}
  256. />
  257. );
  258. }}
  259. </FormField>
  260. );
  261. }
  262. renderProjectSelector() {
  263. const {
  264. project: _selectedProject,
  265. projects,
  266. disabled,
  267. organization,
  268. disableProjectSelector,
  269. } = this.props;
  270. const projectOptions = getProjectOptions({
  271. organization,
  272. projects,
  273. isFormDisabled: disabled,
  274. });
  275. return (
  276. <FormField
  277. name="projectId"
  278. inline={false}
  279. style={{
  280. ...this.formElemBaseStyle,
  281. minWidth: 300,
  282. flex: 2,
  283. }}
  284. flexibleControlStateSize
  285. >
  286. {({onChange, onBlur, model}) => {
  287. const selectedProject =
  288. projects.find(({id}) => id === model.getValue('projectId')) ||
  289. _selectedProject;
  290. return (
  291. <SelectControl
  292. isDisabled={disabled || disableProjectSelector}
  293. value={selectedProject.id}
  294. options={projectOptions}
  295. onChange={({value}: {value: Project['id']}) => {
  296. // if the current owner/team isn't part of project selected, update to the first available team
  297. const nextSelectedProject =
  298. projects.find(({id}) => id === value) ?? selectedProject;
  299. const ownerId: string | undefined = model
  300. .getValue('owner')
  301. ?.split(':')[1];
  302. if (
  303. ownerId &&
  304. nextSelectedProject.teams.find(({id}) => id === ownerId) ===
  305. undefined &&
  306. nextSelectedProject.teams.length
  307. ) {
  308. model.setValue('owner', `team:${nextSelectedProject.teams[0].id}`);
  309. }
  310. onChange(value, {});
  311. onBlur(value, {});
  312. }}
  313. components={{
  314. SingleValue: containerProps => (
  315. <components.ValueContainer {...containerProps}>
  316. <IdBadge
  317. project={selectedProject}
  318. avatarProps={{consistentWidth: true}}
  319. avatarSize={18}
  320. disableLink
  321. />
  322. </components.ValueContainer>
  323. ),
  324. }}
  325. />
  326. );
  327. }}
  328. </FormField>
  329. );
  330. }
  331. renderInterval() {
  332. const {
  333. organization,
  334. disabled,
  335. alertType,
  336. timeWindow,
  337. onTimeWindowChange,
  338. project,
  339. monitorType,
  340. isForSpanMetric,
  341. } = this.props;
  342. return (
  343. <Fragment>
  344. <StyledListItem>
  345. <StyledListTitle>
  346. <div>{t('Define your metric')}</div>
  347. </StyledListTitle>
  348. </StyledListItem>
  349. <FormRow>
  350. {isForSpanMetric ? null : (
  351. <WizardField
  352. name="aggregate"
  353. help={null}
  354. organization={organization}
  355. disabled={disabled}
  356. project={project}
  357. style={{
  358. ...this.formElemBaseStyle,
  359. flex: 1,
  360. }}
  361. inline={false}
  362. flexibleControlStateSize
  363. columnWidth={200}
  364. alertType={alertType}
  365. required
  366. />
  367. )}
  368. {monitorType !== MonitorType.ACTIVATED && (
  369. <SelectControl
  370. name="timeWindow"
  371. styles={this.selectControlStyles}
  372. options={this.timeWindowOptions}
  373. required={monitorType === MonitorType.CONTINUOUS}
  374. isDisabled={disabled}
  375. value={timeWindow}
  376. onChange={({value}) => onTimeWindowChange(value)}
  377. inline={false}
  378. flexibleControlStateSize
  379. />
  380. )}
  381. </FormRow>
  382. </Fragment>
  383. );
  384. }
  385. renderMonitorTypeSelect() {
  386. // TODO: disable select on edit
  387. const {
  388. activationCondition,
  389. isEditing,
  390. monitorType,
  391. onMonitorTypeSelect,
  392. onTimeWindowChange,
  393. timeWindow,
  394. } = this.props;
  395. return (
  396. <Fragment>
  397. <StyledListItem>
  398. <StyledListTitle>
  399. <div>{t('Select Monitor Type')}</div>
  400. </StyledListTitle>
  401. </StyledListItem>
  402. <FormRow>
  403. <MonitorSelect>
  404. <MonitorCard
  405. disabled={isEditing}
  406. position="left"
  407. isSelected={monitorType === MonitorType.CONTINUOUS}
  408. onClick={() =>
  409. isEditing
  410. ? null
  411. : onMonitorTypeSelect({
  412. monitorType: MonitorType.CONTINUOUS,
  413. })
  414. }
  415. >
  416. <strong>{t('Continuous')}</strong>
  417. <div>{t('Continuously monitor trends for the metrics outlined below')}</div>
  418. </MonitorCard>
  419. <MonitorCard
  420. disabled={isEditing}
  421. position="right"
  422. isSelected={monitorType === MonitorType.ACTIVATED}
  423. onClick={() =>
  424. isEditing
  425. ? null
  426. : onMonitorTypeSelect({
  427. monitorType: MonitorType.ACTIVATED,
  428. })
  429. }
  430. >
  431. <strong>Conditional</strong>
  432. {monitorType === MonitorType.ACTIVATED ? (
  433. <ActivatedAlertFields>
  434. {`${t('Monitor')} `}
  435. <SelectControl
  436. name="activationCondition"
  437. styles={this.selectControlStyles}
  438. disabled={isEditing}
  439. options={[
  440. {
  441. value: ActivationConditionType.RELEASE_CREATION,
  442. label: t('New Release'),
  443. },
  444. {
  445. value: ActivationConditionType.DEPLOY_CREATION,
  446. label: t('New Deploy'),
  447. },
  448. ]}
  449. required
  450. value={activationCondition}
  451. onChange={({value}) =>
  452. onMonitorTypeSelect({activationCondition: value})
  453. }
  454. inline={false}
  455. flexibleControlStateSize
  456. size="xs"
  457. />
  458. {` ${t('for')} `}
  459. <SelectControl
  460. name="timeWindow"
  461. styles={this.selectControlStyles}
  462. options={this.timeWindowOptions}
  463. value={timeWindow}
  464. onChange={({value}) => onTimeWindowChange(value)}
  465. inline={false}
  466. flexibleControlStateSize
  467. size="xs"
  468. />
  469. </ActivatedAlertFields>
  470. ) : (
  471. <div>
  472. {t('Temporarily monitor specified query given activation condition')}
  473. </div>
  474. )}
  475. </MonitorCard>
  476. </MonitorSelect>
  477. </FormRow>
  478. </Fragment>
  479. );
  480. }
  481. render() {
  482. const {
  483. alertType,
  484. organization,
  485. disabled,
  486. onFilterSearch,
  487. allowChangeEventTypes,
  488. dataset,
  489. isExtrapolatedChartData,
  490. isTransactionMigration,
  491. isErrorMigration,
  492. aggregate,
  493. project,
  494. } = this.props;
  495. const {environments} = this.state;
  496. const hasActivatedAlerts = organization.features.includes('activated-alert-rules');
  497. const environmentOptions: SelectValue<string | null>[] = [
  498. {
  499. value: null,
  500. label: t('All Environments'),
  501. },
  502. ...(environments?.map(env => ({value: env.name, label: getDisplayName(env)})) ??
  503. []),
  504. ];
  505. return (
  506. <Fragment>
  507. <ChartPanel>
  508. <StyledPanelBody>{this.props.thresholdChart}</StyledPanelBody>
  509. </ChartPanel>
  510. {isTransactionMigration ? (
  511. <Fragment>
  512. <Spacer />
  513. <HiddenListItem />
  514. <HiddenListItem />
  515. </Fragment>
  516. ) : (
  517. <Fragment>
  518. {isExtrapolatedChartData && (
  519. <OnDemandMetricAlert
  520. message={t(
  521. 'The chart data above is an estimate based on the stored transactions that match the filters specified.'
  522. )}
  523. />
  524. )}
  525. {hasActivatedAlerts && this.renderMonitorTypeSelect()}
  526. {!isErrorMigration && this.renderInterval()}
  527. <StyledListItem>{t('Filter events')}</StyledListItem>
  528. <FormRow noMargin columns={1 + (allowChangeEventTypes ? 1 : 0) + 1}>
  529. {this.renderProjectSelector()}
  530. <SelectField
  531. name="environment"
  532. placeholder={t('All Environments')}
  533. style={{
  534. ...this.formElemBaseStyle,
  535. minWidth: 230,
  536. flex: 1,
  537. }}
  538. styles={{
  539. singleValue: (base: any) => ({
  540. ...base,
  541. }),
  542. option: (base: any) => ({
  543. ...base,
  544. }),
  545. }}
  546. options={environmentOptions}
  547. isDisabled={
  548. disabled || this.state.environments === null || isErrorMigration
  549. }
  550. isClearable
  551. inline={false}
  552. flexibleControlStateSize
  553. />
  554. {allowChangeEventTypes && this.renderEventTypeFilter()}
  555. </FormRow>
  556. <FormRow>
  557. <FormField
  558. name="query"
  559. inline={false}
  560. style={{
  561. ...this.formElemBaseStyle,
  562. flex: '6 0 500px',
  563. }}
  564. flexibleControlStateSize
  565. >
  566. {({onChange, onBlur, onKeyDown, initialData, value}) => {
  567. return hasCustomMetrics(organization) &&
  568. alertType === 'custom_metrics' ? (
  569. <MetricSearchBar
  570. mri={getMRI(aggregate)}
  571. projectIds={[project.id]}
  572. placeholder={this.searchPlaceholder}
  573. query={initialData.query}
  574. defaultQuery={initialData?.query ?? ''}
  575. useFormWrapper={false}
  576. searchSource="alert_builder"
  577. onChange={query => {
  578. onFilterSearch(query, true);
  579. onChange(query, {});
  580. }}
  581. />
  582. ) : (
  583. <SearchContainer>
  584. <StyledSearchBar
  585. disallowWildcard={dataset === Dataset.SESSIONS}
  586. disallowFreeText={[
  587. Dataset.GENERIC_METRICS,
  588. Dataset.TRANSACTIONS,
  589. ].includes(dataset)}
  590. invalidMessages={{
  591. [InvalidReason.WILDCARD_NOT_ALLOWED]: t(
  592. 'The wildcard operator is not supported here.'
  593. ),
  594. [InvalidReason.FREE_TEXT_NOT_ALLOWED]: t(
  595. 'Free text search is not allowed. If you want to partially match transaction names, use glob patterns like "transaction:*transaction-name*"'
  596. ),
  597. }}
  598. customInvalidTagMessage={item => {
  599. if (dataset !== Dataset.GENERIC_METRICS) {
  600. return null;
  601. }
  602. return (
  603. <SearchInvalidTag
  604. message={tct(
  605. "The field [field] isn't supported for performance alerts.",
  606. {
  607. field: <code>{item.desc}</code>,
  608. }
  609. )}
  610. docLink="https://docs.sentry.io/product/alerts/create-alerts/metric-alert-config/#tags--properties"
  611. />
  612. );
  613. }}
  614. searchSource="alert_builder"
  615. defaultQuery={initialData?.query ?? ''}
  616. metricAlert
  617. {...getSupportedAndOmittedTags(dataset, organization)}
  618. includeSessionTagsValues={dataset === Dataset.SESSIONS}
  619. disabled={disabled || isErrorMigration}
  620. useFormWrapper={false}
  621. organization={organization}
  622. placeholder={this.searchPlaceholder}
  623. onChange={onChange}
  624. query={initialData.query}
  625. // We only need strict validation for Transaction queries, everything else is fine
  626. highlightUnsupportedTags={
  627. organization.features.includes('alert-allow-indexed') ||
  628. (hasOnDemandMetricAlertFeature(organization) &&
  629. isOnDemandQueryString(initialData.query))
  630. ? false
  631. : dataset === Dataset.GENERIC_METRICS
  632. }
  633. onKeyDown={e => {
  634. /**
  635. * Do not allow enter key to submit the alerts form since it is unlikely
  636. * users will be ready to create the rule as this sits above required fields.
  637. */
  638. if (e.key === 'Enter') {
  639. e.preventDefault();
  640. e.stopPropagation();
  641. }
  642. onKeyDown?.(e);
  643. }}
  644. onClose={(query, {validSearch}) => {
  645. onFilterSearch(query, validSearch);
  646. onBlur(query);
  647. }}
  648. onSearch={query => {
  649. onFilterSearch(query, true);
  650. onChange(query, {});
  651. }}
  652. hasRecentSearches={dataset !== Dataset.SESSIONS}
  653. />
  654. {isExtrapolatedChartData && isOnDemandQueryString(value) && (
  655. <OnDemandWarningIcon
  656. color="gray500"
  657. msg={tct(
  658. `We don’t routinely collect metrics from [fields]. However, we’ll do so [strong:once this alert has been saved.]`,
  659. {
  660. fields: (
  661. <strong>
  662. {getOnDemandKeys(value)
  663. .map(key => `"${key}"`)
  664. .join(', ')}
  665. </strong>
  666. ),
  667. strong: <strong />,
  668. }
  669. )}
  670. />
  671. )}
  672. </SearchContainer>
  673. );
  674. }}
  675. </FormField>
  676. </FormRow>
  677. </Fragment>
  678. )}
  679. </Fragment>
  680. );
  681. }
  682. }
  683. const StyledListTitle = styled('div')`
  684. display: flex;
  685. span {
  686. margin-left: ${space(1)};
  687. }
  688. `;
  689. // This is a temporary hacky solution to hide list items without changing the numbering of the rest of the list
  690. // TODO(issues): Remove this once the migration is complete
  691. const HiddenListItem = styled(ListItem)`
  692. position: absolute;
  693. width: 0px;
  694. height: 0px;
  695. opacity: 0;
  696. pointer-events: none;
  697. `;
  698. const Spacer = styled('div')`
  699. margin-bottom: ${space(2)};
  700. `;
  701. const ChartPanel = styled(Panel)`
  702. margin-bottom: ${space(1)};
  703. `;
  704. const StyledPanelBody = styled(PanelBody)`
  705. ol,
  706. h4 {
  707. margin-bottom: ${space(1)};
  708. }
  709. `;
  710. const SearchContainer = styled('div')`
  711. display: flex;
  712. align-items: center;
  713. gap: ${space(1)};
  714. `;
  715. const StyledSearchBar = styled(SearchBar)`
  716. flex-grow: 1;
  717. ${p =>
  718. p.disabled &&
  719. `
  720. background: ${p.theme.backgroundSecondary};
  721. color: ${p.theme.disabled};
  722. cursor: not-allowed;
  723. `}
  724. `;
  725. const StyledListItem = styled(ListItem)`
  726. margin-bottom: ${space(0.5)};
  727. font-size: ${p => p.theme.fontSizeExtraLarge};
  728. line-height: 1.3;
  729. `;
  730. const FormRow = styled('div')<{columns?: number; noMargin?: boolean}>`
  731. display: flex;
  732. flex-direction: row;
  733. align-items: center;
  734. flex-wrap: wrap;
  735. margin-bottom: ${p => (p.noMargin ? 0 : space(4))};
  736. ${p =>
  737. p.columns !== undefined &&
  738. css`
  739. display: grid;
  740. grid-template-columns: repeat(${p.columns}, auto);
  741. `}
  742. `;
  743. const MonitorSelect = styled('div')`
  744. border-radius: ${p => p.theme.borderRadius};
  745. border: 1px solid ${p => p.theme.border};
  746. width: 100%;
  747. display: grid;
  748. grid-template-columns: 1fr 1fr;
  749. height: 5rem;
  750. `;
  751. type MonitorCardProps = {
  752. isSelected: boolean;
  753. /**
  754. * Adds hover and focus states to the card
  755. */
  756. position: 'left' | 'right';
  757. disabled?: boolean;
  758. };
  759. const MonitorCard = styled('div')<MonitorCardProps>`
  760. padding: ${space(1)} ${space(2)};
  761. display: flex;
  762. flex-grow: 1;
  763. flex-direction: column;
  764. cursor: ${p => (p.disabled || p.isSelected ? 'default' : 'pointer')};
  765. justify-content: center;
  766. background-color: ${p =>
  767. p.disabled && !p.isSelected ? p.theme.backgroundSecondary : p.theme.background};
  768. &:focus,
  769. &:hover {
  770. ${p =>
  771. p.disabled || p.isSelected
  772. ? ''
  773. : `
  774. outline: 1px solid ${p.theme.purple200};
  775. background-color: ${p.theme.backgroundSecondary};
  776. `}
  777. }
  778. border-top-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  779. border-bottom-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  780. border-top-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  781. border-bottom-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  782. margin: ${p =>
  783. p.isSelected ? (p.position === 'left' ? '1px 2px 1px 0' : '1px 0 1px 2px') : 0};
  784. outline: ${p => (p.isSelected ? `2px solid ${p.theme.purple400}` : 'none')};
  785. `;
  786. const ActivatedAlertFields = styled('div')`
  787. display: flex;
  788. align-items: center;
  789. justify-content: space-between;
  790. `;
  791. export default withApi(withProjects(RuleConditionsForm));