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-timezone';
  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 {MetricAggregation, MetricsQueryApiResponse} from 'sentry/types/metrics';
  31. import {defined} from 'sentry/utils';
  32. import {
  33. areResultsLimited,
  34. getDefaultAggregation,
  35. getDefaultMetricDisplayType,
  36. getFormattedMQL,
  37. getMetricsSeriesId,
  38. getMetricsSeriesName,
  39. isNotQueryOnly,
  40. unescapeMetricsFormula,
  41. } from 'sentry/utils/metrics';
  42. import {metricDisplayTypeOptions} from 'sentry/utils/metrics/constants';
  43. import {formatMRIField, MRIToField, parseMRI} from 'sentry/utils/metrics/mri';
  44. import {
  45. type FocusedMetricsSeries,
  46. MetricChartOverlayType,
  47. type MetricDisplayType,
  48. type MetricSeriesFilterUpdateType,
  49. type MetricsQueryWidget,
  50. type MetricsWidget,
  51. type SortState,
  52. } from 'sentry/utils/metrics/types';
  53. import {
  54. isMetricFormula,
  55. type MetricsQueryApiQueryParams,
  56. type MetricsQueryApiRequestQuery,
  57. useMetricsQuery,
  58. } from 'sentry/utils/metrics/useMetricsQuery';
  59. import type {MetricsSamplesResults} from 'sentry/utils/metrics/useMetricsSamples';
  60. import useRouter from 'sentry/utils/useRouter';
  61. import type {FocusAreaProps} from 'sentry/views/metrics/context';
  62. import {SummaryTable} from 'sentry/views/metrics/summaryTable';
  63. import {useSeriesHover} from 'sentry/views/metrics/useSeriesHover';
  64. import {updateQueryWithSeriesFilter} from 'sentry/views/metrics/utils';
  65. import {createChartPalette} from 'sentry/views/metrics/utils/metricsChartPalette';
  66. import {useMetricsIntervalParam} from 'sentry/views/metrics/utils/useMetricsIntervalParam';
  67. import {METRIC_CHART_GROUP, MIN_WIDGET_WIDTH} from './constants';
  68. type MetricWidgetProps = {
  69. displayType: MetricDisplayType;
  70. filters: PageFilters;
  71. focusAreaProps: FocusAreaProps;
  72. onChange: (index: number, data: Partial<MetricsWidget>) => void;
  73. queries: MetricsQueryApiQueryParams[];
  74. chartHeight?: number;
  75. context?: 'ddm' | 'dashboard';
  76. focusedSeries?: FocusedMetricsSeries[];
  77. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  78. hasSiblings?: boolean;
  79. highlightedSampleId?: string;
  80. index?: number;
  81. isSelected?: boolean;
  82. metricsSamples?: MetricsSamplesResults<Field>['data'];
  83. onSampleClick?: (sample: MetricsSamplesResults<Field>['data'][number]) => void;
  84. onSelect?: (index: number) => void;
  85. overlays?: MetricChartOverlayType[];
  86. queryId?: number;
  87. showQuerySymbols?: boolean;
  88. tableSort?: SortState;
  89. };
  90. export type Sample = {
  91. projectId: number;
  92. spanId: string;
  93. transactionId: string;
  94. transactionSpanId: string;
  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. <EquationFormatter equation={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.aggregation))
  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. highlightedSampleId,
  138. }: MetricWidgetProps) => {
  139. const firstQuery = queries
  140. .filter(isNotQueryOnly)
  141. .find((query): query is MetricsQueryApiRequestQuery => !isMetricFormula(query));
  142. const handleChange = useCallback(
  143. (data: Partial<MetricsWidget>) => {
  144. onChange(index, data);
  145. },
  146. [index, onChange]
  147. );
  148. const handleQueryChange = useCallback(
  149. (queryIndex, data: Partial<MetricsWidget>) => {
  150. onChange(queryIndex, data);
  151. },
  152. [onChange]
  153. );
  154. const handleDisplayTypeChange = ({value}: SelectOption<MetricDisplayType>) => {
  155. Sentry.metrics.increment('ddm.widget.display');
  156. onChange(index, {displayType: value});
  157. };
  158. const handleOverlayChange = (options: SelectOption<MetricChartOverlayType>[]) => {
  159. const values = options.map(({value}) => value);
  160. Sentry.metrics.increment('ddm.widget.overlay', 1, {
  161. tags: {
  162. releases: values.includes(MetricChartOverlayType.RELEASES),
  163. samples: values.includes(MetricChartOverlayType.SAMPLES),
  164. },
  165. });
  166. onChange(index, {overlays: values});
  167. };
  168. const samples = useMemo(() => {
  169. if (!defined(metricsSamples)) {
  170. return undefined;
  171. }
  172. if (!firstQuery) {
  173. return undefined;
  174. }
  175. return {
  176. data: metricsSamples,
  177. onSampleClick,
  178. unit: parseMRI(firstQuery?.mri)?.unit ?? '',
  179. aggregation: firstQuery.aggregation ?? getDefaultAggregation(firstQuery.mri),
  180. highlightedId: highlightedSampleId,
  181. };
  182. }, [metricsSamples, firstQuery, onSampleClick, highlightedSampleId]);
  183. const widgetTitle = getWidgetTitle(queries);
  184. const queriesAreComplete = queries.every(q =>
  185. isMetricFormula(q) ? !!q.formula : !!q.mri
  186. );
  187. return (
  188. <MetricWidgetPanel
  189. // show the selection border only if we have more widgets than one
  190. isHighlighted={isSelected && hasSiblings}
  191. isHighlightable={hasSiblings}
  192. onClick={() => onSelect?.(index)}
  193. >
  194. <PanelBody>
  195. <MetricWidgetHeader>
  196. {showQuerySymbols && queryId !== undefined && queries[0] && (
  197. <span>{queries[0].name}:</span>
  198. )}
  199. <WidgetTitle>
  200. <StyledTooltip
  201. title={widgetTitle}
  202. showOnlyOnOverflow
  203. delay={500}
  204. overlayStyle={{maxWidth: '90vw'}}
  205. >
  206. {widgetTitle}
  207. </StyledTooltip>
  208. </WidgetTitle>
  209. <CompactSelect
  210. size="xs"
  211. triggerProps={{prefix: t('Display')}}
  212. value={
  213. displayType ??
  214. getDefaultMetricDisplayType(firstQuery?.mri, firstQuery?.aggregation)
  215. }
  216. options={metricDisplayTypeOptions}
  217. onChange={handleDisplayTypeChange}
  218. />
  219. <CompactSelect
  220. size="xs"
  221. triggerProps={{prefix: t('Overlay')}}
  222. multiple
  223. value={overlays}
  224. options={[
  225. {
  226. label: t('Samples'),
  227. value: MetricChartOverlayType.SAMPLES,
  228. },
  229. {
  230. label: t('Releases'),
  231. value: MetricChartOverlayType.RELEASES,
  232. },
  233. ]}
  234. onChange={handleOverlayChange}
  235. />
  236. </MetricWidgetHeader>
  237. <MetricWidgetBodyWrapper>
  238. {queriesAreComplete ? (
  239. <ErrorBoundary mini>
  240. <MetricWidgetBody
  241. widgetIndex={index}
  242. getChartPalette={getChartPalette}
  243. onChange={handleChange}
  244. onQueryChange={handleQueryChange}
  245. focusAreaProps={focusAreaProps}
  246. samples={isSelected ? samples : undefined}
  247. chartHeight={chartHeight}
  248. chartGroup={METRIC_CHART_GROUP}
  249. queries={queries}
  250. filters={filters}
  251. displayType={displayType}
  252. tableSort={tableSort}
  253. focusedSeries={focusedSeries}
  254. overlays={overlays}
  255. />
  256. </ErrorBoundary>
  257. ) : (
  258. <StyledMetricWidgetBody>
  259. <EmptyMessage
  260. icon={<IconSearch size="xxl" />}
  261. title={t('Nothing to show!')}
  262. description={t('Choose a metric and an operation to display data.')}
  263. />
  264. </StyledMetricWidgetBody>
  265. )}
  266. </MetricWidgetBodyWrapper>
  267. </PanelBody>
  268. </MetricWidgetPanel>
  269. );
  270. }
  271. );
  272. interface MetricWidgetBodyProps {
  273. displayType: MetricDisplayType;
  274. filters: PageFilters;
  275. focusAreaProps: FocusAreaProps;
  276. queries: MetricsQueryApiQueryParams[];
  277. widgetIndex: number;
  278. chartGroup?: string;
  279. chartHeight?: number;
  280. focusedSeries?: FocusedMetricsSeries[];
  281. getChartPalette?: (seriesNames: string[]) => Record<string, string>;
  282. onChange?: (data: Partial<MetricsWidget>) => void;
  283. onQueryChange?: (queryIndex: number, data: Partial<MetricsQueryWidget>) => void;
  284. overlays?: MetricChartOverlayType[];
  285. samples?: SamplesProps;
  286. tableSort?: SortState;
  287. }
  288. export interface SamplesProps {
  289. aggregation: MetricAggregation;
  290. unit: string;
  291. data?: MetricsSamplesResults<Field>['data'];
  292. highlightedId?: string;
  293. onSampleClick?: (sample: MetricsSamplesResults<Field>['data'][number]) => void;
  294. }
  295. const MetricWidgetBody = memo(
  296. ({
  297. onChange,
  298. onQueryChange,
  299. displayType,
  300. focusedSeries,
  301. tableSort,
  302. widgetIndex,
  303. getChartPalette = createChartPalette,
  304. focusAreaProps,
  305. chartHeight,
  306. chartGroup,
  307. samples,
  308. filters,
  309. queries,
  310. overlays,
  311. }: MetricWidgetBodyProps) => {
  312. const router = useRouter();
  313. const {interval} = useMetricsIntervalParam();
  314. const orderedQueries = useMemo(() => {
  315. return queries.map(q => {
  316. if (isMetricFormula(q)) {
  317. return q;
  318. }
  319. return {
  320. ...q,
  321. orderBy: q.orderBy ? q.orderBy : q.groupBy?.length ? 'desc' : undefined,
  322. };
  323. });
  324. }, [queries]);
  325. // Pause refetching if focus area is drawn
  326. const enableRefetch = !focusAreaProps.selection;
  327. const {
  328. data: timeseriesData,
  329. isLoading,
  330. isError,
  331. error,
  332. } = useMetricsQuery(orderedQueries, filters, {interval}, enableRefetch);
  333. const limitedResults = useMemo(() => {
  334. if (!timeseriesData) {
  335. return false;
  336. }
  337. return areResultsLimited(timeseriesData);
  338. }, [timeseriesData]);
  339. const {chartRef, setHoveredSeries} = useSeriesHover();
  340. const handleHoverSeries = useCallback(
  341. (seriesId: string) => {
  342. setHoveredSeries([seriesId, getIngestionSeriesId(seriesId)]);
  343. },
  344. [setHoveredSeries]
  345. );
  346. const chartSeries = useMemo(() => {
  347. return timeseriesData
  348. ? getChartTimeseries(timeseriesData, queries, {
  349. getChartPalette,
  350. focusedSeries: focusedSeries && new Set(focusedSeries?.map(s => s.id)),
  351. })
  352. : [];
  353. }, [timeseriesData, queries, getChartPalette, focusedSeries]);
  354. const chartSamples = useMetricChartSamples({
  355. samples: samples?.data,
  356. highlightedSampleId: samples?.highlightedId,
  357. aggregation: samples?.aggregation,
  358. onSampleClick: samples?.onSampleClick,
  359. timeseries: chartSeries,
  360. unit: samples?.unit,
  361. });
  362. const samplesProp = useMemo(() => {
  363. if (!overlays?.includes(MetricChartOverlayType.SAMPLES)) {
  364. return undefined;
  365. }
  366. return chartSamples;
  367. }, [chartSamples, overlays]);
  368. const releaseSeries = useReleaseSeries();
  369. const releasesProp = useMemo(() => {
  370. if (!overlays?.includes(MetricChartOverlayType.RELEASES)) {
  371. return undefined;
  372. }
  373. return releaseSeries;
  374. }, [releaseSeries, overlays]);
  375. const handleZoom = useCallback(
  376. (range: DateTimeObject) => {
  377. Sentry.metrics.increment('ddm.enhance.zoom');
  378. updateDateTime(range, router, {save: true});
  379. },
  380. [router]
  381. );
  382. const handleRowFilter = useCallback(
  383. (
  384. queryIndex: number,
  385. series: FocusedMetricsSeries,
  386. updateType: MetricSeriesFilterUpdateType
  387. ) => {
  388. const queryToUpdate = queries[queryIndex];
  389. if (!queryToUpdate || !series.groupBy) {
  390. return;
  391. }
  392. if (isMetricFormula(queryToUpdate)) {
  393. // TODO(metrics): filtering on an equation series should extend all conditions of all queries in the equation
  394. return;
  395. }
  396. const newQuery = updateQueryWithSeriesFilter(
  397. queryToUpdate,
  398. series.groupBy,
  399. updateType
  400. );
  401. const indexToUpdate = queries.length > 1 ? queryIndex : widgetIndex;
  402. onQueryChange?.(indexToUpdate, newQuery);
  403. },
  404. [queries, onQueryChange, widgetIndex]
  405. );
  406. const firstScalingFactor = chartSeries.find(s => !s.hidden)?.scalingFactor || 1;
  407. const focusArea = useFocusArea({
  408. ...focusAreaProps,
  409. scalingFactor: firstScalingFactor,
  410. chartRef,
  411. opts: {
  412. widgetIndex,
  413. // The focus area relies on the chart samples to calculate its position
  414. isDisabled: chartSamples === undefined || !focusAreaProps.onAdd,
  415. useFullYAxis: true,
  416. },
  417. onZoom: handleZoom,
  418. });
  419. const toggleSeriesVisibility = useCallback(
  420. (series: FocusedMetricsSeries) => {
  421. setHoveredSeries('');
  422. // The focused series array is not populated yet, so we can add all series except the one that was de-selected
  423. if (!focusedSeries || focusedSeries.length === 0) {
  424. onChange?.({
  425. focusedSeries: chartSeries
  426. .filter(s => s.id !== series.id)
  427. .map(s => ({
  428. id: s.id,
  429. groupBy: s.groupBy,
  430. })),
  431. });
  432. return;
  433. }
  434. const filteredSeries = focusedSeries.filter(s => s.id !== series.id);
  435. if (filteredSeries.length === focusedSeries.length) {
  436. // The series was not focused before so we can add it
  437. filteredSeries.push(series);
  438. }
  439. onChange?.({
  440. focusedSeries: filteredSeries,
  441. });
  442. },
  443. [chartSeries, focusedSeries, onChange, setHoveredSeries]
  444. );
  445. const setSeriesVisibility = useCallback(
  446. (series: FocusedMetricsSeries) => {
  447. setHoveredSeries('');
  448. if (focusedSeries?.length === 1 && focusedSeries[0].id === series.id) {
  449. onChange?.({
  450. focusedSeries: [],
  451. });
  452. return;
  453. }
  454. onChange?.({
  455. focusedSeries: [series],
  456. });
  457. },
  458. [focusedSeries, onChange, setHoveredSeries]
  459. );
  460. const handleSortChange = useCallback(
  461. newSort => {
  462. onChange?.({sort: newSort});
  463. },
  464. [onChange]
  465. );
  466. if (!chartSeries || !timeseriesData || isError) {
  467. return (
  468. <StyledMetricWidgetBody>
  469. {isLoading && <LoadingIndicator />}
  470. {isError && (
  471. <Alert type="error">
  472. {(error?.responseJSON?.detail as string) ||
  473. t('Error while fetching metrics data')}
  474. </Alert>
  475. )}
  476. </StyledMetricWidgetBody>
  477. );
  478. }
  479. if (timeseriesData.data.length === 0) {
  480. return (
  481. <StyledMetricWidgetBody>
  482. <EmptyMessage
  483. icon={<IconSearch size="xxl" />}
  484. title={t('No results')}
  485. description={t('No results found for the given query')}
  486. />
  487. </StyledMetricWidgetBody>
  488. );
  489. }
  490. return (
  491. <StyledMetricWidgetBody>
  492. {limitedResults && (
  493. <LimitAlert type="warning" showIcon>
  494. {tct(
  495. 'The queries in this chart generate a large number of result groups. Only the first [numOfGroups] groups are displayed.',
  496. {numOfGroups: chartSeries.length}
  497. )}
  498. </LimitAlert>
  499. )}
  500. <TransparentLoadingMask visible={isLoading} />
  501. <GuideAnchor target="metrics_chart" disabled={widgetIndex !== 0}>
  502. <MetricChart
  503. ref={chartRef}
  504. series={chartSeries}
  505. displayType={displayType}
  506. height={chartHeight}
  507. samples={samplesProp}
  508. focusArea={focusArea}
  509. releases={releasesProp}
  510. group={chartGroup}
  511. />
  512. </GuideAnchor>
  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.aggregation;
  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. aggregate: item.operation,
  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. `;