Skip to content

Commit

Permalink
enhance(ui): MetricRunInfo - show metric title on hovercard
Browse files Browse the repository at this point in the history
  • Loading branch information
vio committed Sep 22, 2023
1 parent ca6c59c commit 695de79
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.metricHoverCardTitle {
font-weight: bold;
font-size: 1em;
}

.readMoreLink {
appearance: none;
background: none;
Expand All @@ -15,4 +20,3 @@
color: var(--color-primary-dark);
text-decoration: none;
}

33 changes: 22 additions & 11 deletions packages/ui/src/components/metric-run-info/metric-run-info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import React, { useCallback, useMemo } from 'react';
import { getGlobalMetricType, getMetricRunInfo } from '@bundle-stats/utils';

import { Stack } from '../../layout/stack';
import { FlexStack } from '../../layout/flex-stack';
import { Icon } from '../../ui/icon';
import { RunInfo, RunInfoProps } from '../run-info';
import css from './metric-run-info.module.css';

interface MetricInfoProps {
title: string;
description: string;
url?: string;
}

const MetricHoverCard = ({ description, url }: MetricInfoProps) => {
const MetricHoverCard = ({ title, description, url }: MetricInfoProps) => {
// The component parent can be rendered inside a link, use button to avoid using nested links
const onClick = useCallback(() => {
if (url) {
Expand All @@ -19,15 +22,21 @@ const MetricHoverCard = ({ description, url }: MetricInfoProps) => {
}, [url]);

return (
<Stack space="xxxsmall">
<p>{description}</p>
{url && (
<p>
<button type="button" onClick={onClick} className={css.readMoreLink}>
Read more
</button>
</p>
)}
<Stack space="xxsmall" className={css.metricHoverCard}>
<h3 className={css.metricHoverCardTitle}>{title}</h3>
<Stack space="xxxsmall">
<p className={css.metricHoverCardDescription}>{description}</p>
{url && (
<div>
<button type="button" onClick={onClick} className={css.readMoreLink}>
<FlexStack alignItems="center" space="xxxsmall">
<span>Read more</span>
<Icon glyph={Icon.ICONS.EXTERNAL_LINK} size="small" />
</FlexStack>
</button>
</div>
)}
</Stack>
</Stack>
);
};
Expand Down Expand Up @@ -59,7 +68,9 @@ export const MetricRunInfo = (props: MetricRunInfoProps & React.ComponentProps<'

const titleHoverCard = useMemo(() => {
if (showMetricDescription) {
return <MetricHoverCard description={metric.description} url={metric.url} />;
return (
<MetricHoverCard title={metric.label} description={metric.description} url={metric.url} />
);
}

return null;
Expand Down

0 comments on commit 695de79

Please sign in to comment.