widget.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. import {Fragment, memo, useCallback, useMemo} from 'react';
  2. import styled from '@emotion/styled';
  3. import * as Sentry from '@sentry/react';
  4. import type {SeriesOption} from 'echarts';
  5. import moment from 'moment';
  6. import {updateDateTime} from 'sentry/actionCreators/pageFilters';
  7. import Alert from 'sentry/components/alert';
  8. import TransparentLoadingMask from 'sentry/components/charts/transparentLoadingMask';
  9. import type {DateTimeObject} from 'sentry/components/charts/utils';
  10. import type {SelectOption} from 'sentry/components/compactSelect';
  11. import {CompactSelect} from 'sentry/components/compactSelect';
  12. import EmptyMessage from 'sentry/components/emptyMessage';
  13. import ErrorBoundary from 'sentry/components/errorBoundary';
  14. import LoadingIndicator from 'sentry/components/loadingIndicator';
  15. import type {Field} from 'sentry/components/metrics/metricSamplesTable';
  16. import Panel from 'sentry/components/panels/panel';
  17. import PanelBody from 'sentry/components/panels/panelBody';
  18. import {Tooltip} from 'sentry/components/tooltip';
  19. import {IconSearch} from 'sentry/icons';
  20. import {t, tct} from 'sentry/locale';
  21. import {space} from 'sentry/styles/space';
  22. import type {MetricsQueryApiResponse, PageFilters} from 'sentry/types';
  23. import {defined} from 'sentry/utils';
  24. import {
  25. areResultsLimited,
  26. getDefaultMetricDisplayType,
  27. getFormattedMQL,
  28. getMetricsSeriesId,
  29. getMetricsSeriesName,
  30. isCumulativeOp,
  31. unescapeMetricsFormula,
  32. } from 'sentry/utils/metrics';
  33. import {metricDisplayTypeOptions} from 'sentry/utils/metrics/constants';
  34. import {formatMRIField, MRIToField, parseMRI} from 'sentry/utils/metrics/mri';
  35. import {
  36. type FocusedMetricsSeries,
  37. MetricChartOverlayType,
  38. type MetricDisplayType,
  39. type MetricSeriesFilterUpdateType,
  40. type MetricsQueryWidget,
  41. type MetricsWidget,
  42. type SortState,
  43. } from 'sentry/utils/metrics/types';
  44. import {
  45. isMetricFormula,
  46. type MetricsQueryApiQueryParams,
  47. type MetricsQueryApiRequestQuery,
  48. useMetricsQuery,
  49. } from 'sentry/utils/metrics/useMetricsQuery';
  50. import type {MetricsSamplesResults} from 'sentry/utils/metrics/useMetricsSamples';
  51. import useRouter from 'sentry/utils/useRouter';
  52. import {getIngestionSeriesId, MetricChart} from 'sentry/views/metrics/chart/chart';
  53. import type {Series} from 'sentry/views/metrics/chart/types';
  54. import {useFocusArea} from 'sentry/views/metrics/chart/useFocusArea';
  55. import {useMetricChartSamples} from 'sentry/views/metrics/chart/useMetricChartSamples';
  56. import {useReleaseSeries} from 'sentry/views/metrics/chart/useMetricReleases';
  57. import type {FocusAreaProps} from 'sentry/views/metrics/context';
  58. import {FormularFormatter} from 'sentry/views/metrics/formulaParser/formatter';
  59. import {SummaryTable} from 'sentry/views/metrics/summaryTable';
  60. import {useSeriesHover} from 'sentry/views/metrics/useSeriesHover';
  61. import {updateQueryWithSeriesFilter} from 'sentry/views/metrics/utils';
  62. import {createChartPalette} from 'sentry/views/metrics/utils/metricsChartPalette';
  63. import {useMetricsIntervalParam} from 'sentry/views/metrics/utils/useMetricsIntervalParam';
  64. import {METRIC_CHART_GROUP, MIN_WIDGET_WIDTH} from './constants';
  65. type MetricWidgetProps = {
  66. displayType: MetricDisplayType;
  67. filters: PageFilters;
  68. focusAreaProps: FocusAreaProps;
  69. onChange: (index: number, data: Partial<MetricsWidget>) => void;
  70. queries: MetricsQueryApiQueryParams[];
  71. chartHeight?: number;
  72. context?: 'ddm' | 'dashboard';
  73. focusedSeries?: FocusedMetricsSeries[];
  74. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  75. hasSiblings?: boolean;
  76. highlightedSampleId?: string;
  77. index?: number;
  78. isSelected?: boolean;
  79. metricsSamples?: MetricsSamplesResults<Field>['data'];
  80. onSampleClick?: (sample: MetricsSamplesResults<Field>['data'][number]) => void;
  81. onSelect?: (index: number) => void;
  82. overlays?: MetricChartOverlayType[];
  83. queryId?: number;
  84. showQuerySymbols?: boolean;
  85. tableSort?: SortState;
  86. };
  87. export type Sample = {
  88. projectId: number;
  89. spanId: string;
  90. transactionId: string;
  91. transactionSpanId: string;
  92. };
  93. function isNotQueryOnly(query: MetricsQueryApiQueryParams) {
  94. return !('isQueryOnly' in query) || !query.isQueryOnly;
  95. }
  96. export function getWidgetTitle(queries: MetricsQueryApiQueryParams[]) {
  97. const filteredQueries = queries.filter(isNotQueryOnly);
  98. if (filteredQueries.length === 1) {
  99. const firstQuery = filteredQueries[0];
  100. if (isMetricFormula(firstQuery)) {
  101. return (
  102. <Fragment>
  103. <FormularFormatter formula={unescapeMetricsFormula(firstQuery.formula)} />
  104. </Fragment>
  105. );
  106. }
  107. return getFormattedMQL(firstQuery);
  108. }
  109. return filteredQueries
  110. .map(q =>
  111. isMetricFormula(q)
  112. ? unescapeMetricsFormula(q.formula)
  113. : formatMRIField(MRIToField(q.mri, q.op))
  114. )
  115. .join(', ');
  116. }
  117. export const MetricWidget = memo(
  118. ({
  119. queryId,
  120. queries,
  121. filters,
  122. displayType,
  123. tableSort,
  124. index = 0,
  125. isSelected = false,
  126. getChartPalette,
  127. onSelect,
  128. onChange,
  129. hasSiblings = false,
  130. showQuerySymbols,
  131. focusAreaProps,
  132. onSampleClick,
  133. chartHeight = 300,
  134. focusedSeries,
  135. metricsSamples,
  136. overlays,
  137. }: MetricWidgetProps) => {
  138. const firstQuery = queries
  139. .filter(isNotQueryOnly)
  140. .find((query): query is MetricsQueryApiRequestQuery => !isMetricFormula(query));
  141. const handleChange = useCallback(
  142. (data: Partial<MetricsWidget>) => {
  143. onChange(index, data);
  144. },
  145. [index, onChange]
  146. );
  147. const handleQueryChange = useCallback(
  148. (queryIndex, data: Partial<MetricsWidget>) => {
  149. onChange(queryIndex, data);
  150. },
  151. [onChange]
  152. );
  153. const handleDisplayTypeChange = ({value}: SelectOption<MetricDisplayType>) => {
  154. Sentry.metrics.increment('ddm.widget.display');
  155. onChange(index, {displayType: value});
  156. };
  157. const handleOverlayChange = (options: SelectOption<MetricChartOverlayType>[]) => {
  158. const values = options.map(({value}) => value);
  159. Sentry.metrics.increment('ddm.widget.overlay', 1, {
  160. tags: {
  161. releases: values.includes(MetricChartOverlayType.RELEASES),
  162. samples: values.includes(MetricChartOverlayType.SAMPLES),
  163. },
  164. });
  165. onChange(index, {overlays: values});
  166. };
  167. const samples = useMemo(() => {
  168. if (!defined(metricsSamples)) {
  169. return undefined;
  170. }
  171. return {
  172. data: metricsSamples,
  173. onSampleClick,
  174. unit: parseMRI(firstQuery?.mri)?.unit ?? '',
  175. operation: firstQuery?.op ?? '',
  176. };
  177. }, [metricsSamples, firstQuery?.mri, firstQuery?.op, onSampleClick]);
  178. const widgetTitle = getWidgetTitle(queries);
  179. const queriesAreComplete = queries.every(q =>
  180. isMetricFormula(q) ? !!q.formula : !!q.mri
  181. );
  182. return (
  183. <MetricWidgetPanel
  184. // show the selection border only if we have more widgets than one
  185. isHighlighted={isSelected && hasSiblings}
  186. isHighlightable={hasSiblings}
  187. onClick={() => onSelect?.(index)}
  188. >
  189. <PanelBody>
  190. <MetricWidgetHeader>
  191. {showQuerySymbols && queryId !== undefined && queries[0] && (
  192. <span>{queries[0].name}:</span>
  193. )}
  194. <WidgetTitle>
  195. <StyledTooltip
  196. title={widgetTitle}
  197. showOnlyOnOverflow
  198. delay={500}
  199. overlayStyle={{maxWidth: '90vw'}}
  200. >
  201. {widgetTitle}
  202. </StyledTooltip>
  203. </WidgetTitle>
  204. <CompactSelect
  205. size="xs"
  206. triggerProps={{prefix: t('Display')}}
  207. value={
  208. displayType ??
  209. getDefaultMetricDisplayType(firstQuery?.mri, firstQuery?.op)
  210. }
  211. options={metricDisplayTypeOptions}
  212. onChange={handleDisplayTypeChange}
  213. />
  214. <CompactSelect
  215. size="xs"
  216. triggerProps={{prefix: t('Overlay')}}
  217. multiple
  218. value={overlays}
  219. options={[
  220. {
  221. label: t('Samples'),
  222. value: MetricChartOverlayType.SAMPLES,
  223. },
  224. {
  225. label: t('Releases'),
  226. value: MetricChartOverlayType.RELEASES,
  227. },
  228. ]}
  229. onChange={handleOverlayChange}
  230. />
  231. </MetricWidgetHeader>
  232. <MetricWidgetBodyWrapper>
  233. {queriesAreComplete ? (
  234. <ErrorBoundary mini>
  235. <MetricWidgetBody
  236. widgetIndex={index}
  237. getChartPalette={getChartPalette}
  238. onChange={handleChange}
  239. onQueryChange={handleQueryChange}
  240. focusAreaProps={focusAreaProps}
  241. samples={isSelected ? samples : undefined}
  242. chartHeight={chartHeight}
  243. chartGroup={METRIC_CHART_GROUP}
  244. queries={queries}
  245. filters={filters}
  246. displayType={displayType}
  247. tableSort={tableSort}
  248. focusedSeries={focusedSeries}
  249. overlays={overlays}
  250. />
  251. </ErrorBoundary>
  252. ) : (
  253. <StyledMetricWidgetBody>
  254. <EmptyMessage
  255. icon={<IconSearch size="xxl" />}
  256. title={t('Nothing to show!')}
  257. description={t('Choose a metric and an operation to display data.')}
  258. />
  259. </StyledMetricWidgetBody>
  260. )}
  261. </MetricWidgetBodyWrapper>
  262. </PanelBody>
  263. </MetricWidgetPanel>
  264. );
  265. }
  266. );
  267. interface MetricWidgetBodyProps {
  268. displayType: MetricDisplayType;
  269. filters: PageFilters;
  270. focusAreaProps: FocusAreaProps;
  271. queries: MetricsQueryApiQueryParams[];
  272. widgetIndex: number;
  273. chartGroup?: string;
  274. chartHeight?: number;
  275. focusedSeries?: FocusedMetricsSeries[];
  276. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  277. onChange?: (data: Partial<MetricsWidget>) => void;
  278. onQueryChange?: (queryIndex: number, data: Partial<MetricsQueryWidget>) => void;
  279. overlays?: MetricChartOverlayType[];
  280. samples?: SamplesProps;
  281. tableSort?: SortState;
  282. }
  283. export interface SamplesProps {
  284. operation: string;
  285. unit: string;
  286. data?: MetricsSamplesResults<Field>['data'];
  287. higlightedId?: string;
  288. onSampleClick?: (sample: MetricsSamplesResults<Field>['data'][number]) => void;
  289. }
  290. const MetricWidgetBody = memo(
  291. ({
  292. onChange,
  293. onQueryChange,
  294. displayType,
  295. focusedSeries,
  296. tableSort,
  297. widgetIndex,
  298. getChartPalette = createChartPalette,
  299. focusAreaProps,
  300. chartHeight,
  301. chartGroup,
  302. samples,
  303. filters,
  304. queries,
  305. overlays,
  306. }: MetricWidgetBodyProps) => {
  307. const router = useRouter();
  308. const {interval} = useMetricsIntervalParam();
  309. const orderedQueries = useMemo(() => {
  310. return queries.map(q => {
  311. if (isMetricFormula(q)) {
  312. return q;
  313. }
  314. return {
  315. ...q,
  316. orderBy: q.orderBy ? q.orderBy : q.groupBy?.length ? 'desc' : undefined,
  317. };
  318. });
  319. }, [queries]);
  320. // Pause refetching if focus area is drawn
  321. const enableRefetch = !focusAreaProps.selection;
  322. const {
  323. data: timeseriesData,
  324. isLoading,
  325. isError,
  326. error,
  327. } = useMetricsQuery(orderedQueries, filters, {interval}, enableRefetch);
  328. const limitedResults = useMemo(() => {
  329. if (!timeseriesData) {
  330. return false;
  331. }
  332. return areResultsLimited(timeseriesData);
  333. }, [timeseriesData]);
  334. const {chartRef, setHoveredSeries} = useSeriesHover();
  335. const handleHoverSeries = useCallback(
  336. (seriesId: string) => {
  337. setHoveredSeries([seriesId, getIngestionSeriesId(seriesId)]);
  338. },
  339. [setHoveredSeries]
  340. );
  341. const chartSeries = useMemo(() => {
  342. return timeseriesData
  343. ? getChartTimeseries(timeseriesData, queries, {
  344. getChartPalette,
  345. focusedSeries: focusedSeries && new Set(focusedSeries?.map(s => s.id)),
  346. })
  347. : [];
  348. }, [timeseriesData, queries, getChartPalette, focusedSeries]);
  349. const chartSamples = useMetricChartSamples({
  350. samples: samples?.data,
  351. highlightedSampleId: samples?.higlightedId,
  352. operation: samples?.operation,
  353. onSampleClick: samples?.onSampleClick,
  354. timeseries: chartSeries,
  355. unit: samples?.unit,
  356. });
  357. const samplesProp = useMemo(() => {
  358. if (!overlays?.includes(MetricChartOverlayType.SAMPLES)) {
  359. return undefined;
  360. }
  361. return chartSamples;
  362. }, [chartSamples, overlays]);
  363. const releaseSeries = useReleaseSeries();
  364. const releasesProp = useMemo(() => {
  365. if (!overlays?.includes(MetricChartOverlayType.RELEASES)) {
  366. return undefined;
  367. }
  368. return releaseSeries;
  369. }, [releaseSeries, overlays]);
  370. const handleZoom = useCallback(
  371. (range: DateTimeObject) => {
  372. Sentry.metrics.increment('ddm.enhance.zoom');
  373. updateDateTime(range, router, {save: true});
  374. },
  375. [router]
  376. );
  377. const handleRowFilter = useCallback(
  378. (
  379. queryIndex: number,
  380. series: FocusedMetricsSeries,
  381. updateType: MetricSeriesFilterUpdateType
  382. ) => {
  383. const queryToUpdate = queries[queryIndex];
  384. if (!queryToUpdate || !series.groupBy) {
  385. return;
  386. }
  387. if (isMetricFormula(queryToUpdate)) {
  388. // TODO(metrics): filtering on an equation series should extend all conditions of all queries in the equation
  389. return;
  390. }
  391. const newQuery = updateQueryWithSeriesFilter(
  392. queryToUpdate,
  393. series.groupBy,
  394. updateType
  395. );
  396. const indexToUpdate = queries.length > 1 ? queryIndex : widgetIndex;
  397. onQueryChange?.(indexToUpdate, newQuery);
  398. },
  399. [queries, onQueryChange, widgetIndex]
  400. );
  401. const isCumulativeSamplesOp =
  402. queries[0] && !isMetricFormula(queries[0]) && isCumulativeOp(queries[0].op);
  403. const firstScalingFactor = chartSeries.find(s => !s.hidden)?.scalingFactor || 1;
  404. const focusArea = useFocusArea({
  405. ...focusAreaProps,
  406. scalingFactor: firstScalingFactor,
  407. chartRef,
  408. opts: {
  409. widgetIndex,
  410. isDisabled: !focusAreaProps.onAdd,
  411. useFullYAxis: isCumulativeSamplesOp,
  412. },
  413. onZoom: handleZoom,
  414. });
  415. const toggleSeriesVisibility = useCallback(
  416. (series: FocusedMetricsSeries) => {
  417. setHoveredSeries('');
  418. // The focused series array is not populated yet, so we can add all series except the one that was de-selected
  419. if (!focusedSeries || focusedSeries.length === 0) {
  420. onChange?.({
  421. focusedSeries: chartSeries
  422. .filter(s => s.id !== series.id)
  423. .map(s => ({
  424. id: s.id,
  425. groupBy: s.groupBy,
  426. })),
  427. });
  428. return;
  429. }
  430. const filteredSeries = focusedSeries.filter(s => s.id !== series.id);
  431. if (filteredSeries.length === focusedSeries.length) {
  432. // The series was not focused before so we can add it
  433. filteredSeries.push(series);
  434. }
  435. onChange?.({
  436. focusedSeries: filteredSeries,
  437. });
  438. },
  439. [chartSeries, focusedSeries, onChange, setHoveredSeries]
  440. );
  441. const setSeriesVisibility = useCallback(
  442. (series: FocusedMetricsSeries) => {
  443. setHoveredSeries('');
  444. if (focusedSeries?.length === 1 && focusedSeries[0].id === series.id) {
  445. onChange?.({
  446. focusedSeries: [],
  447. });
  448. return;
  449. }
  450. onChange?.({
  451. focusedSeries: [series],
  452. });
  453. },
  454. [focusedSeries, onChange, setHoveredSeries]
  455. );
  456. const handleSortChange = useCallback(
  457. newSort => {
  458. onChange?.({sort: newSort});
  459. },
  460. [onChange]
  461. );
  462. if (!chartSeries || !timeseriesData || isError) {
  463. return (
  464. <StyledMetricWidgetBody>
  465. {isLoading && <LoadingIndicator />}
  466. {isError && (
  467. <Alert type="error">
  468. {(error?.responseJSON?.detail as string) ||
  469. t('Error while fetching metrics data')}
  470. </Alert>
  471. )}
  472. </StyledMetricWidgetBody>
  473. );
  474. }
  475. if (timeseriesData.data.length === 0) {
  476. return (
  477. <StyledMetricWidgetBody>
  478. <EmptyMessage
  479. icon={<IconSearch size="xxl" />}
  480. title={t('No results')}
  481. description={t('No results found for the given query')}
  482. />
  483. </StyledMetricWidgetBody>
  484. );
  485. }
  486. return (
  487. <StyledMetricWidgetBody>
  488. {limitedResults && (
  489. <LimitAlert type="warning" showIcon>
  490. {tct(
  491. 'The queries in this chart generate a large number of result groups. Only the first [numOfGroups] groups are displayed.',
  492. {numOfGroups: chartSeries.length}
  493. )}
  494. </LimitAlert>
  495. )}
  496. <TransparentLoadingMask visible={isLoading} />
  497. <MetricChart
  498. ref={chartRef}
  499. series={chartSeries}
  500. displayType={displayType}
  501. height={chartHeight}
  502. samples={samplesProp}
  503. focusArea={focusArea}
  504. releases={releasesProp}
  505. group={chartGroup}
  506. />
  507. <SummaryTable
  508. series={chartSeries}
  509. onSortChange={handleSortChange}
  510. sort={tableSort}
  511. onRowClick={setSeriesVisibility}
  512. onColorDotClick={toggleSeriesVisibility}
  513. onRowHover={handleHoverSeries}
  514. onRowFilter={handleRowFilter}
  515. />
  516. </StyledMetricWidgetBody>
  517. );
  518. }
  519. );
  520. export function getChartTimeseries(
  521. data: MetricsQueryApiResponse,
  522. queries: MetricsQueryApiQueryParams[],
  523. {
  524. getChartPalette = createChartPalette,
  525. focusedSeries,
  526. }: {
  527. focusedSeries?: Set<string>;
  528. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  529. showQuerySymbol?: boolean;
  530. }
  531. ) {
  532. const filteredQueries = queries.filter(isNotQueryOnly);
  533. const series = data.data.flatMap((group, index) => {
  534. const query = filteredQueries[index];
  535. const meta = data.meta[index];
  536. const lastMetaEntry = meta[meta.length - 1];
  537. const unit =
  538. (lastMetaEntry && 'unit' in lastMetaEntry && lastMetaEntry.unit) || 'none';
  539. const scalingFactor =
  540. (lastMetaEntry &&
  541. 'scaling_factor' in lastMetaEntry &&
  542. lastMetaEntry.scaling_factor) ||
  543. 1;
  544. const isEquationSeries = isMetricFormula(query);
  545. const operation = isEquationSeries ? 'count' : query.op;
  546. const isMultiQuery = filteredQueries.length > 1;
  547. return group.map(entry => ({
  548. unit: unit,
  549. operation: operation,
  550. values: entry.series,
  551. scalingFactor: scalingFactor,
  552. name: getMetricsSeriesName(query, entry.by, isMultiQuery),
  553. id: getMetricsSeriesId(query, entry.by),
  554. queryIndex: index,
  555. isEquationSeries,
  556. groupBy: entry.by,
  557. transaction: entry.by.transaction,
  558. release: entry.by.release,
  559. total: entry.totals,
  560. }));
  561. });
  562. const chartPalette = getChartPalette(series.map(s => s.id));
  563. return series.map(item => ({
  564. id: item.id,
  565. seriesName: item.name,
  566. groupBy: item.groupBy,
  567. unit: item.unit,
  568. scalingFactor: item.scalingFactor,
  569. operation: item.operation,
  570. color: chartPalette[item.id],
  571. hidden: focusedSeries && focusedSeries.size > 0 && !focusedSeries.has(item.id),
  572. data: item.values.map((value, index) => ({
  573. name: moment(data.intervals[index]).valueOf(),
  574. value,
  575. })),
  576. transaction: item.transaction as string | undefined,
  577. release: item.release as string | undefined,
  578. isEquationSeries: item.isEquationSeries,
  579. queryIndex: item.queryIndex,
  580. total: item.total,
  581. emphasis: {
  582. focus: 'series',
  583. } as SeriesOption['emphasis'],
  584. })) as Series[];
  585. }
  586. const MetricWidgetPanel = styled(Panel)<{
  587. isHighlightable: boolean;
  588. isHighlighted: boolean;
  589. }>`
  590. padding-bottom: 0;
  591. margin-bottom: 0;
  592. min-width: ${MIN_WIDGET_WIDTH}px;
  593. position: relative;
  594. transition: box-shadow 0.2s ease;
  595. ${p =>
  596. p.isHighlightable &&
  597. `
  598. &:focus,
  599. &:hover {
  600. box-shadow: 0px 0px 0px 3px
  601. ${p.isHighlighted ? p.theme.purple200 : 'rgba(209, 202, 216, 0.2)'};
  602. }
  603. `}
  604. ${p =>
  605. p.isHighlighted &&
  606. `
  607. box-shadow: 0px 0px 0px 3px ${p.theme.purple200};
  608. border-color: transparent;
  609. `}
  610. `;
  611. const StyledMetricWidgetBody = styled('div')`
  612. padding: ${space(1)};
  613. gap: ${space(3)};
  614. display: flex;
  615. flex-direction: column;
  616. justify-content: center;
  617. height: 100%;
  618. `;
  619. const MetricWidgetBodyWrapper = styled('div')`
  620. padding: ${space(1)};
  621. `;
  622. const MetricWidgetHeader = styled('div')`
  623. display: flex;
  624. justify-content: space-between;
  625. align-items: center;
  626. gap: ${space(0.5)};
  627. padding-left: ${space(2)};
  628. padding-top: ${space(1.5)};
  629. padding-right: ${space(2)};
  630. `;
  631. const WidgetTitle = styled('div')`
  632. flex-grow: 1;
  633. font-size: ${p => p.theme.fontSizeMedium};
  634. display: inline-grid;
  635. grid-auto-flow: column;
  636. `;
  637. const LimitAlert = styled(Alert)`
  638. margin-bottom: 0;
  639. `;
  640. const StyledTooltip = styled(Tooltip)`
  641. ${p => p.theme.overflowEllipsis};
  642. `;