ruleConditionsForm.tsx 27 KB

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