metricChart.tsx 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. import {Fragment, PureComponent} from 'react';
  2. import styled from '@emotion/styled';
  3. import color from 'color';
  4. import type {LineSeriesOption} from 'echarts';
  5. import moment from 'moment-timezone';
  6. import type {Client} from 'sentry/api';
  7. import Feature from 'sentry/components/acl/feature';
  8. import {OnDemandMetricAlert} from 'sentry/components/alerts/onDemandMetricAlert';
  9. import {Button} from 'sentry/components/button';
  10. import type {AreaChartSeries} from 'sentry/components/charts/areaChart';
  11. import {AreaChart} from 'sentry/components/charts/areaChart';
  12. import ChartZoom from 'sentry/components/charts/chartZoom';
  13. import MarkArea from 'sentry/components/charts/components/markArea';
  14. import MarkLine from 'sentry/components/charts/components/markLine';
  15. import EventsRequest from 'sentry/components/charts/eventsRequest';
  16. import LineSeries from 'sentry/components/charts/series/lineSeries';
  17. import SessionsRequest from 'sentry/components/charts/sessionsRequest';
  18. import {
  19. ChartControls,
  20. HeaderTitleLegend,
  21. InlineContainer,
  22. SectionHeading,
  23. SectionValue,
  24. } from 'sentry/components/charts/styles';
  25. import {isEmptySeries} from 'sentry/components/charts/utils';
  26. import CircleIndicator from 'sentry/components/circleIndicator';
  27. import type {StatsPeriodType} from 'sentry/components/organizations/pageFilters/parse';
  28. import {parseStatsPeriod} from 'sentry/components/organizations/pageFilters/parse';
  29. import Panel from 'sentry/components/panels/panel';
  30. import PanelBody from 'sentry/components/panels/panelBody';
  31. import Placeholder from 'sentry/components/placeholder';
  32. import {Tooltip} from 'sentry/components/tooltip';
  33. import {IconCheckmark, IconClock, IconFire, IconWarning} from 'sentry/icons';
  34. import {t} from 'sentry/locale';
  35. import ConfigStore from 'sentry/stores/configStore';
  36. import {space} from 'sentry/styles/space';
  37. import {ActivationConditionType, MonitorType} from 'sentry/types/alerts';
  38. import type {DateString} from 'sentry/types/core';
  39. import type {ReactEchartsRef, Series} from 'sentry/types/echarts';
  40. import type {WithRouterProps} from 'sentry/types/legacyReactRouter';
  41. import type {Organization} from 'sentry/types/organization';
  42. import type {Project} from 'sentry/types/project';
  43. import toArray from 'sentry/utils/array/toArray';
  44. import {browserHistory} from 'sentry/utils/browserHistory';
  45. import {getUtcDateString} from 'sentry/utils/dates';
  46. import {DiscoverDatasets, SavedQueryDatasets} from 'sentry/utils/discover/types';
  47. import getDuration from 'sentry/utils/duration/getDuration';
  48. import getDynamicText from 'sentry/utils/getDynamicText';
  49. import {getForceMetricsLayerQueryExtras} from 'sentry/utils/metrics/features';
  50. import {shouldShowOnDemandMetricAlertUI} from 'sentry/utils/onDemandMetrics/features';
  51. import {MINUTES_THRESHOLD_TO_DISPLAY_SECONDS} from 'sentry/utils/sessions';
  52. import {capitalize} from 'sentry/utils/string/capitalize';
  53. import theme from 'sentry/utils/theme';
  54. import normalizeUrl from 'sentry/utils/url/normalizeUrl';
  55. // eslint-disable-next-line no-restricted-imports
  56. import withSentryRouter from 'sentry/utils/withSentryRouter';
  57. import {COMPARISON_DELTA_OPTIONS} from 'sentry/views/alerts/rules/metric/constants';
  58. import {makeDefaultCta} from 'sentry/views/alerts/rules/metric/metricRulePresets';
  59. import type {MetricRule} from 'sentry/views/alerts/rules/metric/types';
  60. import {
  61. AlertRuleTriggerType,
  62. Dataset,
  63. TimePeriod,
  64. } from 'sentry/views/alerts/rules/metric/types';
  65. import {getChangeStatus} from 'sentry/views/alerts/utils/getChangeStatus';
  66. import {AlertWizardAlertNames} from 'sentry/views/alerts/wizard/options';
  67. import {getAlertTypeFromAggregateDataset} from 'sentry/views/alerts/wizard/utils';
  68. import {hasDatasetSelector} from 'sentry/views/dashboards/utils';
  69. import type {Anomaly, Incident} from '../../../types';
  70. import {
  71. alertDetailsLink,
  72. alertTooltipValueFormatter,
  73. isSessionAggregate,
  74. SESSION_AGGREGATE_TO_FIELD,
  75. } from '../../../utils';
  76. import {getMetricDatasetQueryExtras} from '../utils/getMetricDatasetQueryExtras';
  77. import {isCrashFreeAlert} from '../utils/isCrashFreeAlert';
  78. import type {TimePeriodType} from './constants';
  79. import {
  80. getMetricAlertChartOption,
  81. transformSessionResponseToSeries,
  82. } from './metricChartOption';
  83. type Props = WithRouterProps & {
  84. api: Client;
  85. filter: string[] | null;
  86. interval: string;
  87. organization: Organization;
  88. project: Project;
  89. query: string;
  90. rule: MetricRule;
  91. timePeriod: TimePeriodType;
  92. anomalies?: Anomaly[];
  93. formattedAggregate?: string;
  94. incidents?: Incident[];
  95. isOnDemandAlert?: boolean;
  96. selectedIncident?: Incident | null;
  97. };
  98. type State = Record<string, never>;
  99. function formatTooltipDate(date: moment.MomentInput, format: string): string {
  100. const {
  101. options: {timezone},
  102. } = ConfigStore.get('user');
  103. return moment.tz(date, timezone).format(format);
  104. }
  105. function getRuleChangeSeries(
  106. rule: MetricRule,
  107. data: AreaChartSeries[]
  108. ): LineSeriesOption[] {
  109. const {dateModified} = rule;
  110. if (!data.length || !data[0].data.length || !dateModified) {
  111. return [];
  112. }
  113. const seriesData = data[0].data;
  114. const seriesStart = new Date(seriesData[0].name).getTime();
  115. const ruleChanged = new Date(dateModified).getTime();
  116. if (ruleChanged < seriesStart) {
  117. return [];
  118. }
  119. return [
  120. {
  121. type: 'line',
  122. markLine: MarkLine({
  123. silent: true,
  124. animation: false,
  125. lineStyle: {color: theme.gray200, type: 'solid', width: 1},
  126. data: [{xAxis: ruleChanged}],
  127. label: {
  128. show: false,
  129. },
  130. }),
  131. markArea: MarkArea({
  132. silent: true,
  133. itemStyle: {
  134. color: color(theme.gray100).alpha(0.42).rgb().string(),
  135. },
  136. data: [[{xAxis: seriesStart}, {xAxis: ruleChanged}]],
  137. }),
  138. data: [],
  139. },
  140. ];
  141. }
  142. function shouldUseErrorsDataset(dataset: Dataset, query: string): boolean {
  143. return dataset === Dataset.ERRORS && /\bis:unresolved\b/.test(query);
  144. }
  145. class MetricChart extends PureComponent<Props, State> {
  146. ref: null | ReactEchartsRef = null;
  147. handleZoom = (start: DateString, end: DateString) => {
  148. const {location} = this.props;
  149. browserHistory.push({
  150. pathname: location.pathname,
  151. query: {
  152. start,
  153. end,
  154. },
  155. });
  156. };
  157. renderChartActions(
  158. totalDuration: number,
  159. criticalDuration: number,
  160. warningDuration: number,
  161. waitingForDataDuration: number
  162. ) {
  163. const {rule, organization, project, timePeriod, query} = this.props;
  164. let dataset: DiscoverDatasets | undefined = undefined;
  165. if (shouldUseErrorsDataset(rule.dataset, query)) {
  166. dataset = DiscoverDatasets.ERRORS;
  167. }
  168. let openInDiscoverDataset: SavedQueryDatasets | undefined = undefined;
  169. if (hasDatasetSelector(organization)) {
  170. if (rule.dataset === Dataset.ERRORS) {
  171. openInDiscoverDataset = SavedQueryDatasets.ERRORS;
  172. } else if (
  173. rule.dataset === Dataset.TRANSACTIONS ||
  174. rule.dataset === Dataset.GENERIC_METRICS
  175. ) {
  176. openInDiscoverDataset = SavedQueryDatasets.TRANSACTIONS;
  177. }
  178. }
  179. const {buttonText, ...props} = makeDefaultCta({
  180. organization,
  181. projects: [project],
  182. rule,
  183. timePeriod,
  184. query,
  185. dataset,
  186. openInDiscoverDataset,
  187. });
  188. const resolvedPercent =
  189. (100 *
  190. Math.max(
  191. totalDuration - waitingForDataDuration - criticalDuration - warningDuration,
  192. 0
  193. )) /
  194. totalDuration;
  195. const criticalPercent = 100 * Math.min(criticalDuration / totalDuration, 1);
  196. const warningPercent = 100 * Math.min(warningDuration / totalDuration, 1);
  197. const waitingForDataPercent =
  198. 100 *
  199. Math.min(
  200. (waitingForDataDuration - criticalDuration - warningDuration) / totalDuration,
  201. 1
  202. );
  203. return (
  204. <StyledChartControls>
  205. <StyledInlineContainer>
  206. <Fragment>
  207. <SectionHeading>{t('Summary')}</SectionHeading>
  208. <StyledSectionValue>
  209. <ValueItem>
  210. <IconCheckmark color="successText" isCircled />
  211. {resolvedPercent ? resolvedPercent.toFixed(2) : 0}%
  212. </ValueItem>
  213. <ValueItem>
  214. <IconWarning color="warningText" />
  215. {warningPercent ? warningPercent.toFixed(2) : 0}%
  216. </ValueItem>
  217. <ValueItem>
  218. <IconFire color="errorText" />
  219. {criticalPercent ? criticalPercent.toFixed(2) : 0}%
  220. </ValueItem>
  221. {waitingForDataPercent > 0 && (
  222. <StyledTooltip
  223. underlineColor="gray200"
  224. showUnderline
  225. title={t(
  226. 'The time spent waiting for metrics matching the filters used.'
  227. )}
  228. >
  229. <ValueItem>
  230. <IconClock />
  231. {waitingForDataPercent.toFixed(2)}%
  232. </ValueItem>
  233. </StyledTooltip>
  234. )}
  235. </StyledSectionValue>
  236. </Fragment>
  237. </StyledInlineContainer>
  238. {!isSessionAggregate(rule.aggregate) && (
  239. <Feature features="discover-basic">
  240. <Button size="sm" {...props}>
  241. {buttonText}
  242. </Button>
  243. </Feature>
  244. )}
  245. </StyledChartControls>
  246. );
  247. }
  248. renderChart(
  249. loading: boolean,
  250. timeseriesData?: Series[],
  251. minutesThresholdToDisplaySeconds?: number,
  252. comparisonTimeseriesData?: Series[]
  253. ) {
  254. const {
  255. anomalies,
  256. router,
  257. selectedIncident,
  258. interval,
  259. filter,
  260. incidents,
  261. rule,
  262. organization,
  263. timePeriod: {start, end},
  264. formattedAggregate,
  265. } = this.props;
  266. const {dateModified, timeWindow} = rule;
  267. if (loading || !timeseriesData) {
  268. return this.renderEmpty();
  269. }
  270. const handleIncidentClick = (incident: Incident) => {
  271. router.push(
  272. normalizeUrl({
  273. pathname: alertDetailsLink(organization, incident),
  274. query: {alert: incident.identifier},
  275. })
  276. );
  277. };
  278. const {
  279. criticalDuration,
  280. warningDuration,
  281. totalDuration,
  282. waitingForDataDuration,
  283. chartOption,
  284. } = getMetricAlertChartOption({
  285. timeseriesData,
  286. rule,
  287. seriesName: formattedAggregate,
  288. incidents,
  289. anomalies,
  290. selectedIncident,
  291. showWaitingForData:
  292. shouldShowOnDemandMetricAlertUI(organization) && this.props.isOnDemandAlert,
  293. handleIncidentClick,
  294. });
  295. const comparisonSeriesName = capitalize(
  296. COMPARISON_DELTA_OPTIONS.find(({value}) => value === rule.comparisonDelta)?.label ||
  297. ''
  298. );
  299. const additionalSeries: LineSeriesOption[] = [
  300. ...(comparisonTimeseriesData || []).map(({data: _data, ...otherSeriesProps}) =>
  301. LineSeries({
  302. name: comparisonSeriesName,
  303. data: _data.map(({name, value}) => [name, value]),
  304. lineStyle: {color: theme.gray200, type: 'dashed', width: 1},
  305. itemStyle: {color: theme.gray200},
  306. animation: false,
  307. animationThreshold: 1,
  308. animationDuration: 0,
  309. ...otherSeriesProps,
  310. })
  311. ),
  312. ...getRuleChangeSeries(rule, timeseriesData),
  313. ];
  314. const queryFilter =
  315. filter?.join(' ') + t(' over ') + getDuration(rule.timeWindow * 60);
  316. return (
  317. <ChartPanel>
  318. <StyledPanelBody withPadding>
  319. <ChartHeader>
  320. <HeaderTitleLegend>
  321. {AlertWizardAlertNames[getAlertTypeFromAggregateDataset(rule)]}
  322. </HeaderTitleLegend>
  323. </ChartHeader>
  324. <ChartFilters>
  325. <StyledCircleIndicator size={8} />
  326. <Filters>{formattedAggregate ?? rule.aggregate}</Filters>
  327. <Tooltip
  328. title={queryFilter}
  329. isHoverable
  330. skipWrapper
  331. overlayStyle={{maxWidth: '90vw', lineBreak: 'anywhere', textAlign: 'left'}}
  332. showOnlyOnOverflow
  333. >
  334. <QueryFilters>{queryFilter}</QueryFilters>
  335. </Tooltip>
  336. </ChartFilters>
  337. {getDynamicText({
  338. value: (
  339. <ChartZoom
  340. start={start}
  341. end={end}
  342. onZoom={zoomArgs => this.handleZoom(zoomArgs.start, zoomArgs.end)}
  343. >
  344. {zoomRenderProps => (
  345. <AreaChart
  346. {...zoomRenderProps}
  347. {...chartOption}
  348. showTimeInTooltip
  349. minutesThresholdToDisplaySeconds={minutesThresholdToDisplaySeconds}
  350. additionalSeries={additionalSeries}
  351. tooltip={{
  352. formatter: seriesParams => {
  353. // seriesParams can be object instead of array
  354. const pointSeries = toArray(seriesParams);
  355. const {marker, data: pointData} = pointSeries[0];
  356. const seriesName =
  357. formattedAggregate ?? pointSeries[0].seriesName ?? '';
  358. const [pointX, pointY] = pointData as [number, number];
  359. const pointYFormatted = alertTooltipValueFormatter(
  360. pointY,
  361. seriesName,
  362. rule.aggregate
  363. );
  364. const isModified =
  365. dateModified && pointX <= new Date(dateModified).getTime();
  366. const startTime = formatTooltipDate(moment(pointX), 'MMM D LT');
  367. const {period, periodLength} = parseStatsPeriod(interval) ?? {
  368. periodLength: 'm',
  369. period: `${timeWindow}`,
  370. };
  371. const endTime = formatTooltipDate(
  372. moment(pointX).add(
  373. parseInt(period, 10),
  374. periodLength as StatsPeriodType
  375. ),
  376. 'MMM D LT'
  377. );
  378. const comparisonSeries =
  379. pointSeries.length > 1
  380. ? pointSeries.find(
  381. ({seriesName: _sn}) => _sn === comparisonSeriesName
  382. )
  383. : undefined;
  384. const comparisonPointY = comparisonSeries?.data[1] as
  385. | number
  386. | undefined;
  387. const comparisonPointYFormatted =
  388. comparisonPointY !== undefined
  389. ? alertTooltipValueFormatter(
  390. comparisonPointY,
  391. seriesName,
  392. rule.aggregate
  393. )
  394. : undefined;
  395. const changePercentage =
  396. comparisonPointY === undefined
  397. ? NaN
  398. : ((pointY - comparisonPointY) * 100) / comparisonPointY;
  399. const changeStatus = getChangeStatus(
  400. changePercentage,
  401. rule.thresholdType,
  402. rule.triggers
  403. );
  404. const changeStatusColor =
  405. changeStatus === AlertRuleTriggerType.CRITICAL
  406. ? theme.red300
  407. : changeStatus === AlertRuleTriggerType.WARNING
  408. ? theme.yellow300
  409. : theme.green300;
  410. return [
  411. `<div class="tooltip-series">`,
  412. isModified &&
  413. `<div><span class="tooltip-label"><strong>${t(
  414. 'Alert Rule Modified'
  415. )}</strong></span></div>`,
  416. `<div><span class="tooltip-label">${marker} <strong>${seriesName}</strong></span>${pointYFormatted}</div>`,
  417. comparisonSeries &&
  418. `<div><span class="tooltip-label">${comparisonSeries.marker} <strong>${comparisonSeriesName}</strong></span>${comparisonPointYFormatted}</div>`,
  419. `</div>`,
  420. `<div class="tooltip-footer">`,
  421. `<span>${startTime} &mdash; ${endTime}</span>`,
  422. comparisonPointY !== undefined &&
  423. Math.abs(changePercentage) !== Infinity &&
  424. !isNaN(changePercentage) &&
  425. `<span style="color:${changeStatusColor};margin-left:10px;">${
  426. Math.sign(changePercentage) === 1 ? '+' : '-'
  427. }${Math.abs(changePercentage).toFixed(2)}%</span>`,
  428. `</div>`,
  429. '<div class="tooltip-arrow"></div>',
  430. ]
  431. .filter(e => e)
  432. .join('');
  433. },
  434. }}
  435. />
  436. )}
  437. </ChartZoom>
  438. ),
  439. fixed: <Placeholder height="200px" testId="skeleton-ui" />,
  440. })}
  441. </StyledPanelBody>
  442. {this.renderChartActions(
  443. totalDuration,
  444. criticalDuration,
  445. warningDuration,
  446. waitingForDataDuration
  447. )}
  448. </ChartPanel>
  449. );
  450. }
  451. renderEmptyOnDemandAlert(
  452. organization: Organization,
  453. timeseriesData: Series[] = [],
  454. loading?: boolean
  455. ) {
  456. if (
  457. loading ||
  458. !this.props.isOnDemandAlert ||
  459. !shouldShowOnDemandMetricAlertUI(organization) ||
  460. !isEmptySeries(timeseriesData[0])
  461. ) {
  462. return null;
  463. }
  464. return (
  465. <OnDemandMetricAlert
  466. dismissable
  467. message={t(
  468. 'This alert lacks historical data due to filters for which we don’t routinely extract metrics.'
  469. )}
  470. />
  471. );
  472. }
  473. renderEmpty(placeholderText = '') {
  474. return (
  475. <ChartPanel>
  476. <PanelBody withPadding>
  477. <TriggerChartPlaceholder>{placeholderText}</TriggerChartPlaceholder>
  478. </PanelBody>
  479. </ChartPanel>
  480. );
  481. }
  482. render() {
  483. const {
  484. api,
  485. rule,
  486. organization,
  487. timePeriod,
  488. project,
  489. interval,
  490. query,
  491. location,
  492. isOnDemandAlert,
  493. selectedIncident,
  494. } = this.props;
  495. const {aggregate, timeWindow, environment, dataset} = rule;
  496. // Fix for 7 days * 1m interval being over the max number of results from events api
  497. // 10k events is the current max
  498. if (
  499. timePeriod.usingPeriod &&
  500. timePeriod.period === TimePeriod.SEVEN_DAYS &&
  501. interval === '1m'
  502. ) {
  503. timePeriod.start = getUtcDateString(
  504. // -5 minutes provides a small cushion for rounding up minutes. This might be able to be smaller
  505. moment(moment.utc(timePeriod.end).subtract(10000 - 5, 'minutes'))
  506. );
  507. }
  508. // If the chart duration isn't as long as the rollup duration the events-stats
  509. // endpoint will return an invalid timeseriesData dataset
  510. const viableStartDate = getUtcDateString(
  511. moment.min(
  512. moment.utc(timePeriod.start),
  513. moment.utc(timePeriod.end).subtract(timeWindow, 'minutes')
  514. )
  515. );
  516. const viableEndDate = getUtcDateString(
  517. moment.utc(timePeriod.end).add(timeWindow, 'minutes')
  518. );
  519. let activationFilter = '';
  520. if (
  521. rule.monitorType === MonitorType.ACTIVATED &&
  522. selectedIncident &&
  523. selectedIncident.activation
  524. ) {
  525. const {activation} = selectedIncident;
  526. const {activator, conditionType} = activation;
  527. switch (conditionType) {
  528. case String(ActivationConditionType.RELEASE_CREATION):
  529. activationFilter = ` AND (release:${activator})`;
  530. break;
  531. case String(ActivationConditionType.DEPLOY_CREATION):
  532. activationFilter = ` AND (deploy:${activator})`;
  533. break;
  534. default:
  535. break;
  536. }
  537. }
  538. const alertType = getAlertTypeFromAggregateDataset(rule);
  539. const queryExtras: Record<string, string> = {
  540. ...getMetricDatasetQueryExtras({
  541. organization,
  542. location,
  543. dataset,
  544. newAlertOrQuery: false,
  545. useOnDemandMetrics: isOnDemandAlert,
  546. }),
  547. ...getForceMetricsLayerQueryExtras(organization, dataset, alertType),
  548. };
  549. if (shouldUseErrorsDataset(dataset, query)) {
  550. queryExtras.dataset = 'errors';
  551. }
  552. return isCrashFreeAlert(dataset) ? (
  553. <SessionsRequest
  554. api={api}
  555. organization={organization}
  556. project={project.id ? [Number(project.id)] : []}
  557. environment={environment ? [environment] : undefined}
  558. start={viableStartDate}
  559. end={viableEndDate}
  560. query={query + activationFilter}
  561. interval={interval}
  562. field={SESSION_AGGREGATE_TO_FIELD[aggregate]}
  563. groupBy={['session.status']}
  564. >
  565. {({loading, response}) =>
  566. this.renderChart(
  567. loading,
  568. transformSessionResponseToSeries(response, rule),
  569. MINUTES_THRESHOLD_TO_DISPLAY_SECONDS
  570. )
  571. }
  572. </SessionsRequest>
  573. ) : (
  574. <EventsRequest
  575. api={api}
  576. organization={organization}
  577. query={query + activationFilter}
  578. environment={environment ? [environment] : undefined}
  579. project={project.id ? [Number(project.id)] : []}
  580. interval={interval}
  581. comparisonDelta={rule.comparisonDelta ? rule.comparisonDelta * 60 : undefined}
  582. start={viableStartDate}
  583. end={viableEndDate}
  584. yAxis={aggregate}
  585. includePrevious={false}
  586. currentSeriesNames={[aggregate]}
  587. partial={false}
  588. queryExtras={queryExtras}
  589. referrer="api.alerts.alert-rule-chart"
  590. useOnDemandMetrics
  591. >
  592. {({loading, timeseriesData, comparisonTimeseriesData}) => (
  593. <Fragment>
  594. {this.renderEmptyOnDemandAlert(organization, timeseriesData, loading)}
  595. {this.renderChart(
  596. loading,
  597. timeseriesData,
  598. undefined,
  599. comparisonTimeseriesData
  600. )}
  601. </Fragment>
  602. )}
  603. </EventsRequest>
  604. );
  605. }
  606. }
  607. export default withSentryRouter(MetricChart);
  608. const ChartPanel = styled(Panel)`
  609. margin-top: ${space(2)};
  610. `;
  611. const ChartHeader = styled('div')`
  612. margin-bottom: ${space(3)};
  613. `;
  614. const StyledChartControls = styled(ChartControls)`
  615. display: flex;
  616. justify-content: space-between;
  617. flex-wrap: wrap;
  618. `;
  619. const StyledInlineContainer = styled(InlineContainer)`
  620. grid-auto-flow: column;
  621. grid-column-gap: ${space(1)};
  622. `;
  623. const StyledCircleIndicator = styled(CircleIndicator)`
  624. background: ${p => p.theme.formText};
  625. height: ${space(1)};
  626. margin-right: ${space(0.5)};
  627. `;
  628. const ChartFilters = styled('div')`
  629. font-size: ${p => p.theme.fontSizeSmall};
  630. font-family: ${p => p.theme.text.family};
  631. color: ${p => p.theme.textColor};
  632. display: inline-grid;
  633. grid-template-columns: max-content max-content auto;
  634. align-items: center;
  635. `;
  636. const Filters = styled('span')`
  637. margin-right: ${space(1)};
  638. `;
  639. const QueryFilters = styled('span')`
  640. min-width: 0px;
  641. ${p => p.theme.overflowEllipsis}
  642. `;
  643. const StyledSectionValue = styled(SectionValue)`
  644. display: grid;
  645. grid-template-columns: repeat(4, auto);
  646. gap: ${space(1.5)};
  647. margin: 0 0 0 ${space(1.5)};
  648. `;
  649. const ValueItem = styled('div')`
  650. display: grid;
  651. grid-template-columns: repeat(2, auto);
  652. gap: ${space(0.5)};
  653. align-items: center;
  654. font-variant-numeric: tabular-nums;
  655. text-underline-offset: ${space(4)};
  656. `;
  657. /* Override padding to make chart appear centered */
  658. const StyledPanelBody = styled(PanelBody)`
  659. padding-right: 6px;
  660. `;
  661. const TriggerChartPlaceholder = styled(Placeholder)`
  662. height: 200px;
  663. text-align: center;
  664. padding: ${space(3)};
  665. `;
  666. const StyledTooltip = styled(Tooltip)`
  667. text-underline-offset: ${space(0.5)} !important;
  668. `;