Skip to content

Commit fdee5e5

Browse files
[CSM] Fix core vital legend background (#78273)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 406c47a commit fdee5e5

File tree

8 files changed

+126
-24
lines changed

8 files changed

+126
-24
lines changed

x-pack/plugins/apm/public/components/app/RumDashboard/CoreVitals/CoreVitalItem.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ import { i18n } from '@kbn/i18n';
1515
import { PaletteLegends } from './PaletteLegends';
1616
import { ColorPaletteFlexItem } from './ColorPaletteFlexItem';
1717
import {
18-
AVERAGE_LABEL,
19-
GOOD_LABEL,
18+
CV_AVERAGE_LABEL,
19+
CV_GOOD_LABEL,
2020
LESS_LABEL,
2121
MORE_LABEL,
22-
POOR_LABEL,
22+
CV_POOR_LABEL,
2323
} from './translations';
2424

2525
export interface Thresholds {
@@ -51,7 +51,7 @@ export function getCoreVitalTooltipMessage(
5151
values: {
5252
percentage,
5353
title: title?.toLowerCase(),
54-
exp: good ? GOOD_LABEL : bad ? POOR_LABEL : AVERAGE_LABEL,
54+
exp: good ? CV_GOOD_LABEL : bad ? CV_POOR_LABEL : CV_AVERAGE_LABEL,
5555
moreOrLess: bad || average ? MORE_LABEL : LESS_LABEL,
5656
value: good || average ? thresholds.good : thresholds.bad,
5757
averageMessage: average
@@ -90,7 +90,7 @@ export function CoreVitalItem({
9090
<EuiFlexGroup
9191
gutterSize="none"
9292
alignItems="flexStart"
93-
style={{ maxWidth: 340 }}
93+
style={{ maxWidth: 350 }}
9494
responsive={false}
9595
>
9696
{palette.map((hexCode, ind) => (

x-pack/plugins/apm/public/components/app/RumDashboard/CoreVitals/PaletteLegends.tsx

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,36 @@ import {
1010
EuiFlexItem,
1111
EuiHealth,
1212
euiPaletteForStatus,
13+
EuiText,
1314
EuiToolTip,
1415
} from '@elastic/eui';
1516
import styled from 'styled-components';
17+
import { FormattedMessage } from '@kbn/i18n/react';
18+
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
19+
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
1620
import { getCoreVitalTooltipMessage, Thresholds } from './CoreVitalItem';
21+
import { useUiSetting$ } from '../../../../../../../../src/plugins/kibana_react/public';
22+
import {
23+
LEGEND_NEEDS_IMPROVEMENT_LABEL,
24+
LEGEND_GOOD_LABEL,
25+
LEGEND_POOR_LABEL,
26+
} from './translations';
1727

1828
const PaletteLegend = styled(EuiHealth)`
1929
&:hover {
2030
cursor: pointer;
2131
text-decoration: underline;
22-
background-color: #e7f0f7;
32+
}
33+
`;
34+
35+
const StyledSpan = styled.span<{
36+
darkMode: boolean;
37+
}>`
38+
&:hover {
39+
background-color: ${(props) =>
40+
props.darkMode
41+
? euiDarkVars.euiColorLightestShade
42+
: euiLightVars.euiColorLightestShade};
2343
}
2444
`;
2545

@@ -36,10 +56,17 @@ export function PaletteLegends({
3656
onItemHover,
3757
thresholds,
3858
}: Props) {
59+
const [darkMode] = useUiSetting$<boolean>('theme:darkMode');
60+
3961
const palette = euiPaletteForStatus(3);
62+
const labels = [
63+
LEGEND_GOOD_LABEL,
64+
LEGEND_NEEDS_IMPROVEMENT_LABEL,
65+
LEGEND_POOR_LABEL,
66+
];
4067

4168
return (
42-
<EuiFlexGroup responsive={false}>
69+
<EuiFlexGroup responsive={false} gutterSize="s">
4370
{palette.map((color, ind) => (
4471
<EuiFlexItem
4572
key={ind}
@@ -60,7 +87,21 @@ export function PaletteLegends({
6087
)}
6188
position="bottom"
6289
>
63-
<PaletteLegend color={color}>{ranks?.[ind]}%</PaletteLegend>
90+
<StyledSpan darkMode={darkMode}>
91+
<PaletteLegend color={color}>
92+
<EuiText size="xs">
93+
{labels[ind]} ({ranks?.[ind]}%)
94+
<FormattedMessage
95+
id="xpack.apm.rum.coreVitals.paletteLegend.rankPercentage"
96+
defaultMessage="{labelsInd} ({ranksInd}%)"
97+
values={{
98+
labelsInd: labels[ind],
99+
ranksInd: ranks?.[ind],
100+
}}
101+
/>
102+
</EuiText>
103+
</PaletteLegend>
104+
</StyledSpan>
64105
</EuiToolTip>
65106
</EuiFlexItem>
66107
))}

x-pack/plugins/apm/public/components/app/RumDashboard/CoreVitals/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
88
import { CLS_LABEL, FID_LABEL, LCP_LABEL } from './translations';
99
import { CoreVitalItem } from './CoreVitalItem';
1010
import { UXMetrics } from '../UXMetrics';
11+
import { formatToSec } from '../UXMetrics/KeyUXMetrics';
1112

1213
const CoreVitalsThresholds = {
1314
LCP: { good: '2.5s', bad: '4.0s' },
@@ -28,7 +29,7 @@ export function CoreVitals({ data, loading }: Props) {
2829
<EuiFlexItem>
2930
<CoreVitalItem
3031
title={LCP_LABEL}
31-
value={lcp ? lcp + ' s' : '0'}
32+
value={formatToSec(lcp, 'ms')}
3233
ranks={lcpRanks}
3334
loading={loading}
3435
thresholds={CoreVitalsThresholds.LCP}
@@ -37,7 +38,7 @@ export function CoreVitals({ data, loading }: Props) {
3738
<EuiFlexItem>
3839
<CoreVitalItem
3940
title={FID_LABEL}
40-
value={fid ? fid + ' s' : '0'}
41+
value={formatToSec(fid, 'ms')}
4142
ranks={fidRanks}
4243
loading={loading}
4344
thresholds={CoreVitalsThresholds.FID}

x-pack/plugins/apm/public/components/app/RumDashboard/CoreVitals/translations.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,21 +47,42 @@ export const SUM_LONG_TASKS = i18n.translate(
4747
}
4848
);
4949

50-
export const POOR_LABEL = i18n.translate('xpack.apm.rum.coreVitals.poor', {
50+
export const CV_POOR_LABEL = i18n.translate('xpack.apm.rum.coreVitals.poor', {
5151
defaultMessage: 'a poor',
5252
});
5353

54-
export const GOOD_LABEL = i18n.translate('xpack.apm.rum.coreVitals.good', {
54+
export const CV_GOOD_LABEL = i18n.translate('xpack.apm.rum.coreVitals.good', {
5555
defaultMessage: 'a good',
5656
});
5757

58-
export const AVERAGE_LABEL = i18n.translate(
58+
export const CV_AVERAGE_LABEL = i18n.translate(
5959
'xpack.apm.rum.coreVitals.average',
6060
{
6161
defaultMessage: 'an average',
6262
}
6363
);
6464

65+
export const LEGEND_POOR_LABEL = i18n.translate(
66+
'xpack.apm.rum.coreVitals.legends.poor',
67+
{
68+
defaultMessage: 'Poor',
69+
}
70+
);
71+
72+
export const LEGEND_GOOD_LABEL = i18n.translate(
73+
'xpack.apm.rum.coreVitals.legends.good',
74+
{
75+
defaultMessage: 'Good',
76+
}
77+
);
78+
79+
export const LEGEND_NEEDS_IMPROVEMENT_LABEL = i18n.translate(
80+
'xpack.apm.rum.coreVitals.legends.needsImprovement',
81+
{
82+
defaultMessage: 'Needs improvement',
83+
}
84+
);
85+
6586
export const MORE_LABEL = i18n.translate('xpack.apm.rum.coreVitals.more', {
6687
defaultMessage: 'more',
6788
});

x-pack/plugins/apm/public/components/app/RumDashboard/UXMetrics/index.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import React from 'react';
7+
import React, { useState } from 'react';
88
import {
9+
EuiButtonIcon,
910
EuiFlexGroup,
1011
EuiFlexItem,
1112
EuiHorizontalRule,
13+
EuiLink,
1214
EuiPanel,
15+
EuiPopover,
1316
EuiSpacer,
1417
EuiTitle,
18+
EuiText,
1519
} from '@elastic/eui';
20+
import { FormattedMessage } from '@kbn/i18n/react';
1621
import { I18LABELS } from '../translations';
1722
import { CoreVitals } from '../CoreVitals';
1823
import { KeyUXMetrics } from './KeyUXMetrics';
@@ -21,8 +26,8 @@ import { useFetcher } from '../../../../hooks/useFetcher';
2126

2227
export interface UXMetrics {
2328
cls: string;
24-
fid: string;
25-
lcp: string;
29+
fid: number;
30+
lcp: number;
2631
tbt: number;
2732
fcp: number;
2833
lcpRanks: number[];
@@ -56,6 +61,10 @@ export function UXMetrics() {
5661
[start, end, uiFilters, searchTerm]
5762
);
5863

64+
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
65+
66+
const closePopover = () => setIsPopoverOpen(false);
67+
5968
return (
6069
<EuiPanel>
6170
<EuiFlexGroup justifyContent="spaceBetween">
@@ -72,7 +81,37 @@ export function UXMetrics() {
7281
<EuiFlexGroup justifyContent="spaceBetween">
7382
<EuiFlexItem grow={1} data-cy={`client-metrics`}>
7483
<EuiTitle size="xs">
75-
<h3>{I18LABELS.coreWebVitals}</h3>
84+
<h3>
85+
{I18LABELS.coreWebVitals}
86+
<EuiPopover
87+
isOpen={isPopoverOpen}
88+
button={
89+
<EuiButtonIcon
90+
onClick={() => setIsPopoverOpen(true)}
91+
color={'text'}
92+
iconType={'questionInCircle'}
93+
/>
94+
}
95+
closePopover={closePopover}
96+
>
97+
<div style={{ width: '300px' }}>
98+
<EuiText>
99+
<FormattedMessage
100+
id="xpack.apm.ux.dashboard.webCoreVitals.help"
101+
defaultMessage="Learn more about"
102+
/>
103+
<EuiLink
104+
href="https://web.dev/vitals/"
105+
external
106+
target="_blank"
107+
>
108+
{' '}
109+
{I18LABELS.coreWebVitals}
110+
</EuiLink>
111+
</EuiText>
112+
</div>
113+
</EuiPopover>
114+
</h3>
76115
</EuiTitle>
77116
<EuiSpacer size="s" />
78117
<CoreVitals data={data} loading={status !== 'success'} />

x-pack/plugins/apm/server/lib/rum_client/get_long_task_metrics.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function getLongTaskMetrics({
8181
}
8282
}
8383
});
84+
8485
return {
8586
noOfLongTasks,
8687
sumOfLongTasks,

x-pack/plugins/apm/server/lib/rum_client/get_web_core_vitals.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,12 @@ export async function getWebCoreVitals({
124124
{ value: 0, key: 0 },
125125
];
126126

127-
// Divide by 1000 to convert ms into seconds
128127
return {
129128
cls: String(cls?.values['50.0']?.toFixed(2) || 0),
130-
fid: ((fid?.values['50.0'] || 0) / 1000).toFixed(2),
131-
lcp: ((lcp?.values['50.0'] || 0) / 1000).toFixed(2),
132-
tbt: tbt?.values['50.0'] || 0,
133-
fcp: fcp?.values['50.0'] || 0,
129+
fid: fid?.values['50.0'] ?? 0,
130+
lcp: lcp?.values['50.0'] ?? 0,
131+
tbt: tbt?.values['50.0'] ?? 0,
132+
fcp: fcp?.values['50.0'] ?? 0,
134133

135134
lcpRanks: getRanksPercentages(lcpRanks?.values ?? defaultRanks),
136135
fidRanks: getRanksPercentages(fidRanks?.values ?? defaultRanks),

x-pack/test/apm_api_integration/trial/tests/csm/web_core_vitals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,13 @@ export default function rumServicesApiTests({ getService }: FtrProviderContext)
5959
0,
6060
],
6161
"fcp": 1072,
62-
"fid": "1.35",
62+
"fid": 1352.13,
6363
"fidRanks": Array [
6464
0,
6565
0,
6666
100,
6767
],
68-
"lcp": "1.27",
68+
"lcp": 1270.5,
6969
"lcpRanks": Array [
7070
100,
7171
0,

0 commit comments

Comments
 (0)