ruleConditionsForm.tsx 26 KB

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