Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CSM] Fix core vital legend background #78273

Merged
merged 14 commits into from
Sep 29, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import { i18n } from '@kbn/i18n';
import { PaletteLegends } from './PaletteLegends';
import { ColorPaletteFlexItem } from './ColorPaletteFlexItem';
import {
AVERAGE_LABEL,
GOOD_LABEL,
AN_AVERAGE_LABEL,
A_GOOD_LABEL,
LESS_LABEL,
MORE_LABEL,
POOR_LABEL,
A_POOR_LABEL,
} from './translations';

export interface Thresholds {
Expand Down Expand Up @@ -51,7 +51,7 @@ export function getCoreVitalTooltipMessage(
values: {
percentage,
title: title?.toLowerCase(),
exp: good ? GOOD_LABEL : bad ? POOR_LABEL : AVERAGE_LABEL,
exp: good ? A_GOOD_LABEL : bad ? A_POOR_LABEL : AN_AVERAGE_LABEL,
moreOrLess: bad || average ? MORE_LABEL : LESS_LABEL,
value: good || average ? thresholds.good : thresholds.bad,
averageMessage: average
Expand Down Expand Up @@ -90,7 +90,7 @@ export function CoreVitalItem({
<EuiFlexGroup
gutterSize="none"
alignItems="flexStart"
style={{ maxWidth: 340 }}
style={{ maxWidth: 350 }}
responsive={false}
>
{palette.map((hexCode, ind) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,35 @@ import {
EuiFlexItem,
EuiHealth,
euiPaletteForStatus,
EuiText,
EuiToolTip,
} from '@elastic/eui';
import styled from 'styled-components';
import euiLightVars from '@elastic/eui/dist/eui_theme_light.json';
import euiDarkVars from '@elastic/eui/dist/eui_theme_dark.json';
import { getCoreVitalTooltipMessage, Thresholds } from './CoreVitalItem';
import { useUiSetting$ } from '../../../../../../../../src/plugins/kibana_react/public';
import {
NEEDS_IMPROVEMENT_LABEL,
GOOD_LABEL,
POOR_LABEL,
} from './translations';

const PaletteLegend = styled(EuiHealth)`
&:hover {
cursor: pointer;
text-decoration: underline;
background-color: #e7f0f7;
}
`;

const StyledSpan = styled.span<{
darkMode: boolean;
}>`
&:hover {
background-color: ${(props) =>
props.darkMode
? euiDarkVars.euiColorLightestShade
: euiLightVars.euiColorLightestShade};
}
`;

Expand All @@ -36,10 +55,13 @@ export function PaletteLegends({
onItemHover,
thresholds,
}: Props) {
const [darkMode] = useUiSetting$<boolean>('theme:darkMode');

const palette = euiPaletteForStatus(3);
const labels = [GOOD_LABEL, NEEDS_IMPROVEMENT_LABEL, POOR_LABEL];

return (
<EuiFlexGroup responsive={false}>
<EuiFlexGroup responsive={false} gutterSize={'s'}>
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
{palette.map((color, ind) => (
<EuiFlexItem
key={ind}
Expand All @@ -60,7 +82,13 @@ export function PaletteLegends({
)}
position="bottom"
>
<PaletteLegend color={color}>{ranks?.[ind]}%</PaletteLegend>
<StyledSpan darkMode={darkMode}>
<PaletteLegend color={color}>
<EuiText size="xs">
{labels[ind]} ({ranks?.[ind]}%)
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
</EuiText>
</PaletteLegend>
</StyledSpan>
</EuiToolTip>
</EuiFlexItem>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { CLS_LABEL, FID_LABEL, LCP_LABEL } from './translations';
import { CoreVitalItem } from './CoreVitalItem';
import { UXMetrics } from '../UXMetrics';
import { formatToSec } from '../UXMetrics/KeyUXMetrics';

const CoreVitalsThresholds = {
LCP: { good: '2.5s', bad: '4.0s' },
Expand All @@ -28,7 +29,7 @@ export function CoreVitals({ data, loading }: Props) {
<EuiFlexItem>
<CoreVitalItem
title={LCP_LABEL}
value={lcp ? lcp + ' s' : '0'}
value={formatToSec(lcp, 'ms')}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the output of this function going to be a string presented to the user, or is 'ms' an enumerable string?

If this will cause ms to show to the user make sure the output is translated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already done in another PR

ranks={lcpRanks}
loading={loading}
thresholds={CoreVitalsThresholds.LCP}
Expand All @@ -37,7 +38,7 @@ export function CoreVitals({ data, loading }: Props) {
<EuiFlexItem>
<CoreVitalItem
title={FID_LABEL}
value={fid ? fid + ' s' : '0'}
value={formatToSec(fid, 'ms')}
ranks={fidRanks}
loading={loading}
thresholds={CoreVitalsThresholds.FID}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,42 @@ export const SUM_LONG_TASKS = i18n.translate(
}
);

export const POOR_LABEL = i18n.translate('xpack.apm.rum.coreVitals.poor', {
export const A_POOR_LABEL = i18n.translate('xpack.apm.rum.coreVitals.poor', {
defaultMessage: 'a poor',
});

export const GOOD_LABEL = i18n.translate('xpack.apm.rum.coreVitals.good', {
export const A_GOOD_LABEL = i18n.translate('xpack.apm.rum.coreVitals.good', {
defaultMessage: 'a good',
});

export const AVERAGE_LABEL = i18n.translate(
export const AN_AVERAGE_LABEL = i18n.translate(
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
'xpack.apm.rum.coreVitals.average',
{
defaultMessage: 'an average',
}
);

export const POOR_LABEL = i18n.translate(
'xpack.apm.rum.coreVitals.legends.poor',
{
defaultMessage: 'Poor',
}
);

export const GOOD_LABEL = i18n.translate(
'xpack.apm.rum.coreVitals.legends.good',
{
defaultMessage: 'Good',
}
);

export const NEEDS_IMPROVEMENT_LABEL = i18n.translate(
'xpack.apm.rum.coreVitals.legends.needsImprovement',
{
defaultMessage: 'Needs improvement',
}
);

export const MORE_LABEL = i18n.translate('xpack.apm.rum.coreVitals.more', {
defaultMessage: 'more',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React from 'react';
import React, { useState } from 'react';
import {
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiHorizontalRule,
EuiLink,
EuiPanel,
EuiPopover,
EuiSpacer,
EuiTitle,
EuiText,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { I18LABELS } from '../translations';
import { CoreVitals } from '../CoreVitals';
import { KeyUXMetrics } from './KeyUXMetrics';
Expand All @@ -21,8 +26,8 @@ import { useFetcher } from '../../../../hooks/useFetcher';

export interface UXMetrics {
cls: string;
fid: string;
lcp: string;
fid: number;
lcp: number;
tbt: number;
fcp: number;
lcpRanks: number[];
Expand Down Expand Up @@ -56,6 +61,10 @@ export function UXMetrics() {
[start, end, uiFilters, searchTerm]
);

const [isPopoverOpen, setIsPopoverOpen] = useState(false);

const closePopover = () => setIsPopoverOpen(false);

return (
<EuiPanel>
<EuiFlexGroup justifyContent="spaceBetween">
Expand All @@ -72,7 +81,37 @@ export function UXMetrics() {
<EuiFlexGroup justifyContent="spaceBetween">
<EuiFlexItem grow={1} data-cy={`client-metrics`}>
<EuiTitle size="xs">
<h3>{I18LABELS.coreWebVitals}</h3>
<h3>
{I18LABELS.coreWebVitals}
<EuiPopover
isOpen={isPopoverOpen}
button={
<EuiButtonIcon
onClick={() => setIsPopoverOpen(true)}
color={'text'}
iconType={'questionInCircle'}
/>
}
closePopover={closePopover}
>
<div style={{ width: '300px' }}>
<EuiText>
<FormattedMessage
id="xpack.apm.ux.dashboard.webCoreVitals.help"
defaultMessage="Learn more about"
/>
<EuiLink
href="https://web.dev/vitals/"
external
target="_blank"
>
{' '}
shahzad31 marked this conversation as resolved.
Show resolved Hide resolved
{I18LABELS.coreWebVitals}
</EuiLink>
</EuiText>
</div>
</EuiPopover>
</h3>
</EuiTitle>
<EuiSpacer size="s" />
<CoreVitals data={data} loading={status !== 'success'} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export async function getLongTaskMetrics({
}
}
});

return {
noOfLongTasks,
sumOfLongTasks,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,12 @@ export async function getWebCoreVitals({
{ value: 0, key: 0 },
];

// Divide by 1000 to convert ms into seconds
return {
cls: String(cls?.values['50.0']?.toFixed(2) || 0),
fid: ((fid?.values['50.0'] || 0) / 1000).toFixed(2),
lcp: ((lcp?.values['50.0'] || 0) / 1000).toFixed(2),
tbt: tbt?.values['50.0'] || 0,
fcp: fcp?.values['50.0'] || 0,
fid: fid?.values['50.0'] ?? 0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this value have > 2 decimal digits? Ignore if the answer is no, or formatting it as such is no longer important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's done in frontend

lcp: lcp?.values['50.0'] ?? 0,
tbt: tbt?.values['50.0'] ?? 0,
fcp: fcp?.values['50.0'] ?? 0,

lcpRanks: getRanksPercentages(lcpRanks?.values ?? defaultRanks),
fidRanks: getRanksPercentages(fidRanks?.values ?? defaultRanks),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,13 @@ export default function rumServicesApiTests({ getService }: FtrProviderContext)
0,
],
"fcp": 1072,
"fid": "1.35",
"fid": 1352.13,
"fidRanks": Array [
0,
0,
100,
],
"lcp": "1.27",
"lcp": 1270.5,
"lcpRanks": Array [
100,
0,
Expand Down