widget.tsx 21 KB

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