[7.x] [Lens] Use first decimal when required for data summaries (#88463) (#88662)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marco Liberati 2021-01-19 19:04:06 +01:00 committed by GitHub
parent 9e933fc796
commit b518aaf9d7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -468,6 +468,9 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
}
if (props.topValues && props.topValues.buckets.length) {
const digitsRequired = props.topValues.buckets.some(
(topValue) => !Number.isInteger(topValue.count / props.sampledValues!)
);
return wrapInPopover(
<div data-test-subj="lnsFieldListPanel-topValues">
{props.topValues.buckets.map((topValue) => {
@ -494,7 +497,10 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="xs" textAlign="left" color="accent">
{Math.round((topValue.count / props.sampledValues!) * 100)}%
{(Math.round((topValue.count / props.sampledValues!) * 1000) / 10).toFixed(
digitsRequired ? 1 : 0
)}
%
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
@ -522,7 +528,10 @@ function FieldItemPopoverContents(props: State & FieldItemProps) {
<EuiFlexItem grow={false} className="eui-textTruncate">
<EuiText size="xs" color="subdued">
{Math.round((otherCount / props.sampledValues!) * 100)}%
{(Math.round((otherCount / props.sampledValues!) * 1000) / 10).toFixed(
digitsRequired ? 1 : 0
)}
%
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>