Skip to content

Commit 952aa78

Browse files
committed
truncate rows
Signed-off-by: bdjulbic <bdjulbic@foursquare.com>
1 parent 489f2b6 commit 952aa78

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

src/components/src/map/layer-hover-info.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import React, {useMemo} from 'react';
55
import styled from 'styled-components';
6+
import truncate from 'lodash/truncate';
67
import {CompareType, Field, Merge, TooltipField} from '@kepler.gl/types';
78
import {CenterFlexbox} from '../common/styled-components';
89
import {Layers} from '../common/icons';
@@ -66,12 +67,22 @@ interface RowProps {
6667
url?: string;
6768
}
6869

70+
/** Max length before truncation is applied */
71+
const TOOLTIP_VALUE_MAX_LENGTH = 60;
72+
/** Length to truncate to (including ellipsis) */
73+
const TOOLTIP_VALUE_TRUNCATE_LENGTH = 30;
74+
6975
const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
7076
// Set 'url' to 'value' if it looks like a url
7177
if (!url && value && typeof value === 'string' && value.match(/^http/)) {
7278
url = value;
7379
}
7480

81+
const displayValue =
82+
typeof value === 'string' && value.length > TOOLTIP_VALUE_MAX_LENGTH
83+
? truncate(value, {length: TOOLTIP_VALUE_TRUNCATE_LENGTH})
84+
: value;
85+
7586
const asImg = /<img>/.test(name);
7687
return (
7788
<tr className="layer-hover-info__row" key={name}>
@@ -81,11 +92,11 @@ const Row: React.FC<RowProps> = ({name, value, deltaValue, url}) => {
8192
<img src={value} />
8293
) : url ? (
8394
<a target="_blank" rel="noopener noreferrer" href={url}>
84-
{value}
95+
{displayValue}
8596
</a>
8697
) : (
8798
<>
88-
<span>{value}</span>
99+
<span>{displayValue}</span>
89100
{notNullorUndefined(deltaValue) ? (
90101
<span
91102
className={`row__delta-value ${

0 commit comments

Comments
 (0)