widget.tsx 21 KB

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