widget.tsx 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709
  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 type {Field} from 'sentry/components/metrics/metricSamplesTable';
  17. import Panel from 'sentry/components/panels/panel';
  18. import PanelBody from 'sentry/components/panels/panelBody';
  19. import {Tooltip} from 'sentry/components/tooltip';
  20. import {IconSearch} from 'sentry/icons';
  21. import {t, tct} from 'sentry/locale';
  22. import {space} from 'sentry/styles/space';
  23. import type {MetricsQueryApiResponse, PageFilters} from 'sentry/types';
  24. import {defined} from 'sentry/utils';
  25. import {
  26. areResultsLimited,
  27. getDefaultMetricDisplayType,
  28. getFormattedMQL,
  29. getMetricsSeriesId,
  30. getMetricsSeriesName,
  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 firstScalingFactor = chartSeries.find(s => !s.hidden)?.scalingFactor || 1;
  408. const focusArea = useFocusArea({
  409. ...focusAreaProps,
  410. scalingFactor: firstScalingFactor,
  411. chartRef,
  412. opts: {
  413. widgetIndex,
  414. // The focus area relies on the chart samples to calculate its position
  415. isDisabled: chartSamples === undefined || !focusAreaProps.onAdd,
  416. useFullYAxis: true,
  417. },
  418. onZoom: handleZoom,
  419. });
  420. const toggleSeriesVisibility = useCallback(
  421. (series: FocusedMetricsSeries) => {
  422. setHoveredSeries('');
  423. // The focused series array is not populated yet, so we can add all series except the one that was de-selected
  424. if (!focusedSeries || focusedSeries.length === 0) {
  425. onChange?.({
  426. focusedSeries: chartSeries
  427. .filter(s => s.id !== series.id)
  428. .map(s => ({
  429. id: s.id,
  430. groupBy: s.groupBy,
  431. })),
  432. });
  433. return;
  434. }
  435. const filteredSeries = focusedSeries.filter(s => s.id !== series.id);
  436. if (filteredSeries.length === focusedSeries.length) {
  437. // The series was not focused before so we can add it
  438. filteredSeries.push(series);
  439. }
  440. onChange?.({
  441. focusedSeries: filteredSeries,
  442. });
  443. },
  444. [chartSeries, focusedSeries, onChange, setHoveredSeries]
  445. );
  446. const setSeriesVisibility = useCallback(
  447. (series: FocusedMetricsSeries) => {
  448. setHoveredSeries('');
  449. if (focusedSeries?.length === 1 && focusedSeries[0].id === series.id) {
  450. onChange?.({
  451. focusedSeries: [],
  452. });
  453. return;
  454. }
  455. onChange?.({
  456. focusedSeries: [series],
  457. });
  458. },
  459. [focusedSeries, onChange, setHoveredSeries]
  460. );
  461. const handleSortChange = useCallback(
  462. newSort => {
  463. onChange?.({sort: newSort});
  464. },
  465. [onChange]
  466. );
  467. if (!chartSeries || !timeseriesData || isError) {
  468. return (
  469. <StyledMetricWidgetBody>
  470. {isLoading && <LoadingIndicator />}
  471. {isError && (
  472. <Alert type="error">
  473. {(error?.responseJSON?.detail as string) ||
  474. t('Error while fetching metrics data')}
  475. </Alert>
  476. )}
  477. </StyledMetricWidgetBody>
  478. );
  479. }
  480. if (timeseriesData.data.length === 0) {
  481. return (
  482. <StyledMetricWidgetBody>
  483. <EmptyMessage
  484. icon={<IconSearch size="xxl" />}
  485. title={t('No results')}
  486. description={t('No results found for the given query')}
  487. />
  488. </StyledMetricWidgetBody>
  489. );
  490. }
  491. return (
  492. <StyledMetricWidgetBody>
  493. {limitedResults && (
  494. <LimitAlert type="warning" showIcon>
  495. {tct(
  496. 'The queries in this chart generate a large number of result groups. Only the first [numOfGroups] groups are displayed.',
  497. {numOfGroups: chartSeries.length}
  498. )}
  499. </LimitAlert>
  500. )}
  501. <TransparentLoadingMask visible={isLoading} />
  502. <GuideAnchor target="metrics_chart" disabled={widgetIndex !== 0}>
  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. </GuideAnchor>
  514. <SummaryTable
  515. series={chartSeries}
  516. onSortChange={handleSortChange}
  517. sort={tableSort}
  518. onRowClick={setSeriesVisibility}
  519. onColorDotClick={toggleSeriesVisibility}
  520. onRowHover={handleHoverSeries}
  521. onRowFilter={handleRowFilter}
  522. />
  523. </StyledMetricWidgetBody>
  524. );
  525. }
  526. );
  527. export function getChartTimeseries(
  528. data: MetricsQueryApiResponse,
  529. queries: MetricsQueryApiQueryParams[],
  530. {
  531. getChartPalette = createChartPalette,
  532. focusedSeries,
  533. }: {
  534. focusedSeries?: Set<string>;
  535. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  536. showQuerySymbol?: boolean;
  537. }
  538. ) {
  539. const filteredQueries = queries.filter(isNotQueryOnly);
  540. const series = data.data.flatMap((group, index) => {
  541. const query = filteredQueries[index];
  542. const meta = data.meta[index];
  543. const lastMetaEntry = meta[meta.length - 1];
  544. const unit =
  545. (lastMetaEntry && 'unit' in lastMetaEntry && lastMetaEntry.unit) || 'none';
  546. const scalingFactor =
  547. (lastMetaEntry &&
  548. 'scaling_factor' in lastMetaEntry &&
  549. lastMetaEntry.scaling_factor) ||
  550. 1;
  551. const isEquationSeries = isMetricFormula(query);
  552. const operation = isEquationSeries ? 'count' : query.op;
  553. const isMultiQuery = filteredQueries.length > 1;
  554. return group.map(entry => ({
  555. unit: unit,
  556. operation: operation,
  557. values: entry.series,
  558. scalingFactor: scalingFactor,
  559. name: getMetricsSeriesName(query, entry.by, isMultiQuery),
  560. id: getMetricsSeriesId(query, entry.by),
  561. queryIndex: index,
  562. isEquationSeries,
  563. groupBy: entry.by,
  564. transaction: entry.by.transaction,
  565. release: entry.by.release,
  566. total: entry.totals,
  567. }));
  568. });
  569. const chartPalette = getChartPalette(series.map(s => s.id));
  570. return series.map(item => ({
  571. id: item.id,
  572. seriesName: item.name,
  573. groupBy: item.groupBy,
  574. unit: item.unit,
  575. scalingFactor: item.scalingFactor,
  576. operation: item.operation,
  577. color: chartPalette[item.id],
  578. hidden: focusedSeries && focusedSeries.size > 0 && !focusedSeries.has(item.id),
  579. data: item.values.map((value, index) => ({
  580. name: moment(data.intervals[index]).valueOf(),
  581. value,
  582. })),
  583. transaction: item.transaction as string | undefined,
  584. release: item.release as string | undefined,
  585. isEquationSeries: item.isEquationSeries,
  586. queryIndex: item.queryIndex,
  587. total: item.total,
  588. emphasis: {
  589. focus: 'series',
  590. } as SeriesOption['emphasis'],
  591. })) as Series[];
  592. }
  593. const MetricWidgetPanel = styled(Panel)<{
  594. isHighlightable: boolean;
  595. isHighlighted: boolean;
  596. }>`
  597. padding-bottom: 0;
  598. margin-bottom: 0;
  599. min-width: ${MIN_WIDGET_WIDTH}px;
  600. position: relative;
  601. transition: box-shadow 0.2s ease;
  602. ${p =>
  603. p.isHighlightable &&
  604. `
  605. &:focus,
  606. &:hover {
  607. box-shadow: 0px 0px 0px 3px
  608. ${p.isHighlighted ? p.theme.purple200 : 'rgba(209, 202, 216, 0.2)'};
  609. }
  610. `}
  611. ${p =>
  612. p.isHighlighted &&
  613. `
  614. box-shadow: 0px 0px 0px 3px ${p.theme.purple200};
  615. border-color: transparent;
  616. `}
  617. `;
  618. const StyledMetricWidgetBody = styled('div')`
  619. padding: ${space(1)};
  620. gap: ${space(3)};
  621. display: flex;
  622. flex-direction: column;
  623. justify-content: center;
  624. height: 100%;
  625. `;
  626. const MetricWidgetBodyWrapper = styled('div')`
  627. padding: ${space(1)};
  628. `;
  629. const MetricWidgetHeader = styled('div')`
  630. display: flex;
  631. justify-content: space-between;
  632. align-items: center;
  633. gap: ${space(0.5)};
  634. padding-left: ${space(2)};
  635. padding-top: ${space(1.5)};
  636. padding-right: ${space(2)};
  637. `;
  638. const WidgetTitle = styled('div')`
  639. flex-grow: 1;
  640. font-size: ${p => p.theme.fontSizeMedium};
  641. display: inline-grid;
  642. grid-auto-flow: column;
  643. `;
  644. const LimitAlert = styled(Alert)`
  645. margin-bottom: 0;
  646. `;
  647. const StyledTooltip = styled(Tooltip)`
  648. ${p => p.theme.overflowEllipsis};
  649. `;