ruleConditionsForm.tsx 27 KB

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