ruleConditionsForm.tsx 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. })
  404. }
  405. >
  406. <strong>{t('Continuous')}</strong>
  407. <div>{t('Continuously monitor trends for the metrics outlined below')}</div>
  408. </MonitorCard>
  409. <MonitorCard
  410. disabled={isEditing}
  411. position="right"
  412. isSelected={monitorType === MonitorType.ACTIVATED}
  413. onClick={() =>
  414. isEditing
  415. ? null
  416. : onMonitorTypeSelect({
  417. monitorType: MonitorType.ACTIVATED,
  418. })
  419. }
  420. >
  421. <strong>Conditional</strong>
  422. {monitorType === MonitorType.ACTIVATED ? (
  423. <ActivatedAlertFields>
  424. {`${t('Monitor')} `}
  425. <SelectControl
  426. name="activationCondition"
  427. styles={this.selectControlStyles}
  428. disabled={isEditing}
  429. options={[
  430. {
  431. value: ActivationConditionType.RELEASE_CREATION,
  432. label: t('New Release'),
  433. },
  434. {
  435. value: ActivationConditionType.DEPLOY_CREATION,
  436. label: t('New Deploy'),
  437. },
  438. ]}
  439. required
  440. value={activationCondition}
  441. onChange={({value}) =>
  442. onMonitorTypeSelect({activationCondition: value})
  443. }
  444. inline={false}
  445. flexibleControlStateSize
  446. size="xs"
  447. />
  448. {` ${t('for')} `}
  449. <SelectControl
  450. name="timeWindow"
  451. styles={this.selectControlStyles}
  452. options={this.timeWindowOptions}
  453. value={timeWindow}
  454. onChange={({value}) => onTimeWindowChange(value)}
  455. inline={false}
  456. flexibleControlStateSize
  457. size="xs"
  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. metricAlert
  607. {...getSupportedAndOmittedTags(dataset, organization)}
  608. includeSessionTagsValues={dataset === Dataset.SESSIONS}
  609. disabled={disabled || isErrorMigration}
  610. useFormWrapper={false}
  611. organization={organization}
  612. placeholder={this.searchPlaceholder}
  613. onChange={onChange}
  614. query={initialData.query}
  615. // We only need strict validation for Transaction queries, everything else is fine
  616. highlightUnsupportedTags={
  617. organization.features.includes('alert-allow-indexed') ||
  618. (hasOnDemandMetricAlertFeature(organization) &&
  619. isOnDemandQueryString(initialData.query))
  620. ? false
  621. : dataset === Dataset.GENERIC_METRICS
  622. }
  623. onKeyDown={e => {
  624. /**
  625. * Do not allow enter key to submit the alerts form since it is unlikely
  626. * users will be ready to create the rule as this sits above required fields.
  627. */
  628. if (e.key === 'Enter') {
  629. e.preventDefault();
  630. e.stopPropagation();
  631. }
  632. onKeyDown?.(e);
  633. }}
  634. onClose={(query, {validSearch}) => {
  635. onFilterSearch(query, validSearch);
  636. onBlur(query);
  637. }}
  638. onSearch={query => {
  639. onFilterSearch(query, true);
  640. onChange(query, {});
  641. }}
  642. hasRecentSearches={dataset !== Dataset.SESSIONS}
  643. />
  644. {isExtrapolatedChartData && isOnDemandQueryString(value) && (
  645. <OnDemandWarningIcon
  646. color="gray500"
  647. msg={tct(
  648. `We don’t routinely collect metrics from [fields]. However, we’ll do so [strong:once this alert has been saved.]`,
  649. {
  650. fields: (
  651. <strong>
  652. {getOnDemandKeys(value)
  653. .map(key => `"${key}"`)
  654. .join(', ')}
  655. </strong>
  656. ),
  657. strong: <strong />,
  658. }
  659. )}
  660. />
  661. )}
  662. </SearchContainer>
  663. );
  664. }}
  665. </FormField>
  666. </FormRow>
  667. </Fragment>
  668. )}
  669. </Fragment>
  670. );
  671. }
  672. }
  673. const StyledListTitle = styled('div')`
  674. display: flex;
  675. span {
  676. margin-left: ${space(1)};
  677. }
  678. `;
  679. // This is a temporary hacky solution to hide list items without changing the numbering of the rest of the list
  680. // TODO(issues): Remove this once the migration is complete
  681. const HiddenListItem = styled(ListItem)`
  682. position: absolute;
  683. width: 0px;
  684. height: 0px;
  685. opacity: 0;
  686. pointer-events: none;
  687. `;
  688. const Spacer = styled('div')`
  689. margin-bottom: ${space(2)};
  690. `;
  691. const ChartPanel = styled(Panel)`
  692. margin-bottom: ${space(1)};
  693. `;
  694. const StyledPanelBody = styled(PanelBody)`
  695. ol,
  696. h4 {
  697. margin-bottom: ${space(1)};
  698. }
  699. `;
  700. const SearchContainer = styled('div')`
  701. display: flex;
  702. align-items: center;
  703. gap: ${space(1)};
  704. `;
  705. const StyledSearchBar = styled(SearchBar)`
  706. flex-grow: 1;
  707. ${p =>
  708. p.disabled &&
  709. `
  710. background: ${p.theme.backgroundSecondary};
  711. color: ${p.theme.disabled};
  712. cursor: not-allowed;
  713. `}
  714. `;
  715. const StyledListItem = styled(ListItem)`
  716. margin-bottom: ${space(0.5)};
  717. font-size: ${p => p.theme.fontSizeExtraLarge};
  718. line-height: 1.3;
  719. `;
  720. const FormRow = styled('div')<{columns?: number; noMargin?: boolean}>`
  721. display: flex;
  722. flex-direction: row;
  723. align-items: center;
  724. flex-wrap: wrap;
  725. margin-bottom: ${p => (p.noMargin ? 0 : space(4))};
  726. ${p =>
  727. p.columns !== undefined &&
  728. css`
  729. display: grid;
  730. grid-template-columns: repeat(${p.columns}, auto);
  731. `}
  732. `;
  733. const MonitorSelect = styled('div')`
  734. border-radius: ${p => p.theme.borderRadius};
  735. border: 1px solid ${p => p.theme.border};
  736. width: 100%;
  737. display: grid;
  738. grid-template-columns: 1fr 1fr;
  739. height: 5rem;
  740. `;
  741. type MonitorCardProps = {
  742. isSelected: boolean;
  743. /**
  744. * Adds hover and focus states to the card
  745. */
  746. position: 'left' | 'right';
  747. disabled?: boolean;
  748. };
  749. const MonitorCard = styled('div')<MonitorCardProps>`
  750. padding: ${space(1)} ${space(2)};
  751. display: flex;
  752. flex-grow: 1;
  753. flex-direction: column;
  754. cursor: ${p => (p.disabled || p.isSelected ? 'default' : 'pointer')};
  755. justify-content: center;
  756. background-color: ${p =>
  757. p.disabled && !p.isSelected ? p.theme.backgroundSecondary : p.theme.background};
  758. &:focus,
  759. &:hover {
  760. ${p =>
  761. p.disabled || p.isSelected
  762. ? ''
  763. : `
  764. outline: 1px solid ${p.theme.purple200};
  765. background-color: ${p.theme.backgroundSecondary};
  766. `}
  767. }
  768. border-top-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  769. border-bottom-left-radius: ${p => (p.position === 'left' ? p.theme.borderRadius : 0)};
  770. border-top-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  771. border-bottom-right-radius: ${p => (p.position !== 'left' ? p.theme.borderRadius : 0)};
  772. margin: ${p =>
  773. p.isSelected ? (p.position === 'left' ? '1px 2px 1px 0' : '1px 0 1px 2px') : 0};
  774. outline: ${p => (p.isSelected ? `2px solid ${p.theme.purple400}` : 'none')};
  775. `;
  776. const ActivatedAlertFields = styled('div')`
  777. display: flex;
  778. align-items: center;
  779. justify-content: space-between;
  780. `;
  781. export default withApi(withProjects(RuleConditionsForm));