ruleConditionsForm.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  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. />
  449. {` ${t('for')} `}
  450. <SelectControl
  451. name="timeWindow"
  452. styles={this.selectControlStyles}
  453. options={this.timeWindowOptions}
  454. value={timeWindow}
  455. onChange={({value}) => onTimeWindowChange(value)}
  456. inline={false}
  457. flexibleControlStateSize
  458. />
  459. </ActivatedAlertFields>
  460. ) : (
  461. <div>
  462. {t('Temporarily monitor specified query given activation condition')}
  463. </div>
  464. )}
  465. </MonitorCard>
  466. </MonitorSelect>
  467. </FormRow>
  468. </Fragment>
  469. );
  470. }
  471. render() {
  472. const {
  473. alertType,
  474. organization,
  475. disabled,
  476. onFilterSearch,
  477. allowChangeEventTypes,
  478. dataset,
  479. isExtrapolatedChartData,
  480. isTransactionMigration,
  481. isErrorMigration,
  482. aggregate,
  483. project,
  484. } = this.props;
  485. const {environments} = this.state;
  486. const hasActivatedAlerts = organization.features.includes('activated-alert-rules');
  487. const environmentOptions: SelectValue<string | null>[] = [
  488. {
  489. value: null,
  490. label: t('All Environments'),
  491. },
  492. ...(environments?.map(env => ({value: env.name, label: getDisplayName(env)})) ??
  493. []),
  494. ];
  495. return (
  496. <Fragment>
  497. <ChartPanel>
  498. <StyledPanelBody>{this.props.thresholdChart}</StyledPanelBody>
  499. </ChartPanel>
  500. {isTransactionMigration ? (
  501. <Fragment>
  502. <Spacer />
  503. <HiddenListItem />
  504. <HiddenListItem />
  505. </Fragment>
  506. ) : (
  507. <Fragment>
  508. {isExtrapolatedChartData && (
  509. <OnDemandMetricAlert
  510. message={t(
  511. 'The chart data above is an estimate based on the stored transactions that match the filters specified.'
  512. )}
  513. />
  514. )}
  515. {hasActivatedAlerts && this.renderMonitorTypeSelect()}
  516. {!isErrorMigration && this.renderInterval()}
  517. <StyledListItem>{t('Filter events')}</StyledListItem>
  518. <FormRow noMargin columns={1 + (allowChangeEventTypes ? 1 : 0) + 1}>
  519. {this.renderProjectSelector()}
  520. <SelectField
  521. name="environment"
  522. placeholder={t('All Environments')}
  523. style={{
  524. ...this.formElemBaseStyle,
  525. minWidth: 230,
  526. flex: 1,
  527. }}
  528. styles={{
  529. singleValue: (base: any) => ({
  530. ...base,
  531. }),
  532. option: (base: any) => ({
  533. ...base,
  534. }),
  535. }}
  536. options={environmentOptions}
  537. isDisabled={
  538. disabled || this.state.environments === null || isErrorMigration
  539. }
  540. isClearable
  541. inline={false}
  542. flexibleControlStateSize
  543. />
  544. {allowChangeEventTypes && this.renderEventTypeFilter()}
  545. </FormRow>
  546. <FormRow>
  547. <FormField
  548. name="query"
  549. inline={false}
  550. style={{
  551. ...this.formElemBaseStyle,
  552. flex: '6 0 500px',
  553. }}
  554. flexibleControlStateSize
  555. >
  556. {({onChange, onBlur, onKeyDown, initialData, value}) => {
  557. return hasCustomMetrics(organization) &&
  558. alertType === 'custom_metrics' ? (
  559. <MetricSearchBar
  560. mri={getMRI(aggregate)}
  561. projectIds={[project.id]}
  562. placeholder={this.searchPlaceholder}
  563. query={initialData.query}
  564. defaultQuery={initialData?.query ?? ''}
  565. useFormWrapper={false}
  566. searchSource="alert_builder"
  567. onChange={query => {
  568. onFilterSearch(query, true);
  569. onChange(query, {});
  570. }}
  571. />
  572. ) : (
  573. <SearchContainer>
  574. <StyledSearchBar
  575. disallowWildcard={dataset === Dataset.SESSIONS}
  576. disallowFreeText={[
  577. Dataset.GENERIC_METRICS,
  578. Dataset.TRANSACTIONS,
  579. ].includes(dataset)}
  580. invalidMessages={{
  581. [InvalidReason.WILDCARD_NOT_ALLOWED]: t(
  582. 'The wildcard operator is not supported here.'
  583. ),
  584. [InvalidReason.FREE_TEXT_NOT_ALLOWED]: t(
  585. 'Free text search is not allowed. If you want to partially match transaction names, use glob patterns like "transaction:*transaction-name*"'
  586. ),
  587. }}
  588. customInvalidTagMessage={item => {
  589. if (dataset !== Dataset.GENERIC_METRICS) {
  590. return null;
  591. }
  592. return (
  593. <SearchInvalidTag
  594. message={tct(
  595. "The field [field] isn't supported for performance alerts.",
  596. {
  597. field: <code>{item.desc}</code>,
  598. }
  599. )}
  600. docLink="https://docs.sentry.io/product/alerts/create-alerts/metric-alert-config/#tags--properties"
  601. />
  602. );
  603. }}
  604. searchSource="alert_builder"
  605. defaultQuery={initialData?.query ?? ''}
  606. {...getSupportedAndOmittedTags(dataset, organization)}
  607. includeSessionTagsValues={dataset === Dataset.SESSIONS}
  608. disabled={disabled || isErrorMigration}
  609. useFormWrapper={false}
  610. organization={organization}
  611. placeholder={this.searchPlaceholder}
  612. onChange={onChange}
  613. query={initialData.query}
  614. // We only need strict validation for Transaction queries, everything else is fine
  615. highlightUnsupportedTags={
  616. organization.features.includes('alert-allow-indexed') ||
  617. (hasOnDemandMetricAlertFeature(organization) &&
  618. isOnDemandQueryString(initialData.query))
  619. ? false
  620. : dataset === Dataset.GENERIC_METRICS
  621. }
  622. onKeyDown={e => {
  623. /**
  624. * Do not allow enter key to submit the alerts form since it is unlikely
  625. * users will be ready to create the rule as this sits above required fields.
  626. */
  627. if (e.key === 'Enter') {
  628. e.preventDefault();
  629. e.stopPropagation();
  630. }
  631. onKeyDown?.(e);
  632. }}
  633. onClose={(query, {validSearch}) => {
  634. onFilterSearch(query, validSearch);
  635. onBlur(query);
  636. }}
  637. onSearch={query => {
  638. onFilterSearch(query, true);
  639. onChange(query, {});
  640. }}
  641. hasRecentSearches={dataset !== Dataset.SESSIONS}
  642. />
  643. {isExtrapolatedChartData && isOnDemandQueryString(value) && (
  644. <OnDemandWarningIcon
  645. color="gray500"
  646. msg={tct(
  647. `We don’t routinely collect metrics from [fields]. However, we’ll do so [strong:once this alert has been saved.]`,
  648. {
  649. fields: (
  650. <strong>
  651. {getOnDemandKeys(value)
  652. .map(key => `"${key}"`)
  653. .join(', ')}
  654. </strong>
  655. ),
  656. strong: <strong />,
  657. }
  658. )}
  659. />
  660. )}
  661. </SearchContainer>
  662. );
  663. }}
  664. </FormField>
  665. </FormRow>
  666. </Fragment>
  667. )}
  668. </Fragment>
  669. );
  670. }
  671. }
  672. const StyledListTitle = styled('div')`
  673. display: flex;
  674. span {
  675. margin-left: ${space(1)};
  676. }
  677. `;
  678. // This is a temporary hacky solution to hide list items without changing the numbering of the rest of the list
  679. // TODO(issues): Remove this once the migration is complete
  680. const HiddenListItem = styled(ListItem)`
  681. position: absolute;
  682. width: 0px;
  683. height: 0px;
  684. opacity: 0;
  685. pointer-events: none;
  686. `;
  687. const Spacer = styled('div')`
  688. margin-bottom: ${space(2)};
  689. `;
  690. const ChartPanel = styled(Panel)`
  691. margin-bottom: ${space(1)};
  692. `;
  693. const StyledPanelBody = styled(PanelBody)`
  694. ol,
  695. h4 {
  696. margin-bottom: ${space(1)};
  697. }
  698. `;
  699. const SearchContainer = styled('div')`
  700. display: flex;
  701. align-items: center;
  702. gap: ${space(1)};
  703. `;
  704. const StyledSearchBar = styled(SearchBar)`
  705. flex-grow: 1;
  706. ${p =>
  707. p.disabled &&
  708. `
  709. background: ${p.theme.backgroundSecondary};
  710. color: ${p.theme.disabled};
  711. cursor: not-allowed;
  712. `}
  713. `;
  714. const StyledListItem = styled(ListItem)`
  715. margin-bottom: ${space(0.5)};
  716. font-size: ${p => p.theme.fontSizeExtraLarge};
  717. line-height: 1.3;
  718. `;
  719. const FormRow = styled('div')<{columns?: number; noMargin?: boolean}>`
  720. display: flex;
  721. flex-direction: row;
  722. align-items: center;
  723. flex-wrap: wrap;
  724. margin-bottom: ${p => (p.noMargin ? 0 : space(4))};
  725. ${p =>
  726. p.columns !== undefined &&
  727. css`
  728. display: grid;
  729. grid-template-columns: repeat(${p.columns}, auto);
  730. `}
  731. `;
  732. const MonitorSelect = styled('div')`
  733. border-radius: ${p => p.theme.borderRadius};
  734. border: 1px solid ${p => p.theme.border};
  735. width: 100%;
  736. display: grid;
  737. grid-template-columns: 1fr 1fr;
  738. height: 6rem;
  739. `;
  740. type MonitorCardProps = {
  741. isSelected: boolean;
  742. /**
  743. * Adds hover and focus states to the card
  744. */
  745. position: 'left' | 'right';
  746. disabled?: boolean;
  747. };
  748. const MonitorCard = styled('div')<MonitorCardProps>`
  749. padding: ${space(1)};
  750. display: flex;
  751. flex-grow: 1;
  752. flex-direction: column;
  753. cursor: ${p => (p.disabled || p.isSelected ? 'default' : 'pointer')};
  754. justify-content: center;
  755. background-color: ${p =>
  756. p.disabled && !p.isSelected ? p.theme.backgroundSecondary : p.theme.background};
  757. &:focus,
  758. &:hover {
  759. ${p =>
  760. p.disabled || p.isSelected
  761. ? ''
  762. : `
  763. outline: 1px solid ${p.theme.purple200};
  764. background-color: ${p.theme.backgroundSecondary};
  765. `}
  766. }
  767. border-top-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  768. border-bottom-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  769. border-top-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  770. border-bottom-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  771. margin: ${p =>
  772. p.isSelected ? (p.position === 'left' ? '1px 2px 1px 0' : '1px 0 1px 2px') : 0};
  773. outline: ${p => (p.isSelected ? `2px solid ${p.theme.purple400}` : 'none')};
  774. `;
  775. const ActivatedAlertFields = styled('div')`
  776. display: flex;
  777. align-items: center;
  778. justify-content: space-between;
  779. `;
  780. export default withApi(withProjects(RuleConditionsForm));