Skip to content

Commit 00bbef2

Browse files
authored
chore(ui): Use ellipsize helper in more places (#95540)
I introduced the helper in #94935 but didn't actually propagate it. I noticed another custom truncation recently, and decided now's the time to actually fix this.
1 parent d85e4ef commit 00bbef2

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

static/app/components/charts/eventsChart.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import {
4646
} from 'sentry/utils/discover/fields';
4747
import type {DiscoverDatasets} from 'sentry/utils/discover/types';
4848
import {decodeList, decodeScalar} from 'sentry/utils/queryString';
49+
import {ellipsize} from 'sentry/utils/string/ellipsize';
4950

5051
import EventsRequest from './eventsRequest';
5152

@@ -553,11 +554,8 @@ class EventsChart extends Component<EventsChartProps> {
553554
const forceChartType = decodeScalar(location.query.forceChartType);
554555
const yAxisArray = decodeList(yAxis);
555556
const yAxisSeriesNames = yAxisArray.map(name => {
556-
let yAxisLabel = name && isEquation(name) ? getEquation(name) : name;
557-
if (yAxisLabel && yAxisLabel.length > 60) {
558-
yAxisLabel = yAxisLabel.substring(0, 60) + '...';
559-
}
560-
return yAxisLabel;
557+
const yAxisLabel = name && isEquation(name) ? getEquation(name) : name;
558+
return ellipsize(yAxisLabel, 60);
561559
});
562560

563561
const previousSeriesNames = previousName

static/app/components/events/autofix/autofixInsightCards.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {trackAnalytics} from 'sentry/utils/analytics';
2020
import {singleLineRenderer} from 'sentry/utils/marked/marked';
2121
import {MarkedText} from 'sentry/utils/marked/markedText';
2222
import {useMutation, useQueryClient} from 'sentry/utils/queryClient';
23+
import {ellipsize} from 'sentry/utils/string/ellipsize';
2324
import useApi from 'sentry/utils/useApi';
2425
import useOrganization from 'sentry/utils/useOrganization';
2526

@@ -87,7 +88,7 @@ function AutofixInsightCard({
8788
const truncatedTitleHtml = useMemo(() => {
8889
let truncatedTitle = displayedInsightTitle;
8990
if (newlineIndex !== -1 && newlineIndex < displayedInsightTitle.length - 1) {
90-
truncatedTitle = displayedInsightTitle.substring(0, newlineIndex) + '...';
91+
truncatedTitle = ellipsize(truncatedTitle, newlineIndex);
9192
}
9293
return {
9394
__html: singleLineRenderer(truncatedTitle),

static/app/components/events/autofix/autofixInsightSources.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {t} from 'sentry/locale';
1919
import {space} from 'sentry/styles/space';
2020
import {defined} from 'sentry/utils';
2121
import {MarkedText} from 'sentry/utils/marked/markedText';
22+
import {ellipsize} from 'sentry/utils/string/ellipsize';
2223
import {SectionKey} from 'sentry/views/issueDetails/streamline/context';
2324

2425
interface AutofixInsightSourcesProps {
@@ -63,7 +64,7 @@ function getCodeSourceName(url: string): string {
6364
// Fallback if URL parsing fails or path is simple
6465
}
6566
// Fallback to a truncated version of the URL
66-
return url.length > 30 ? url.substring(0, 27) + '...' : url;
67+
return ellipsize(url, 30);
6768
}
6869

6970
function AutofixInsightSources({sources, title, codeUrls}: AutofixInsightSourcesProps) {

static/app/views/performance/newTraceDetails/traceDrawer/details/span/eapSections/attributes.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {trackAnalytics} from 'sentry/utils/analytics';
1414
import type {RenderFunctionBaggage} from 'sentry/utils/discover/fieldRenderers';
1515
import {FieldKey} from 'sentry/utils/fields';
1616
import {generateProfileFlamechartRoute} from 'sentry/utils/profiling/routes';
17+
import {ellipsize} from 'sentry/utils/string/ellipsize';
1718
import {looksLikeAJSONArray} from 'sentry/utils/string/looksLikeAJSONArray';
1819
import {useIsSentryEmployee} from 'sentry/utils/useIsSentryEmployee';
1920
import type {AttributesFieldRendererProps} from 'sentry/views/explore/components/traceItemAttributes/attributesTree';
@@ -75,9 +76,7 @@ const truncatedTextRenderer = (props: CustomRenderersProps) => {
7576
if (typeof props.item.value !== 'string') {
7677
return props.item.value;
7778
}
78-
return props.item.value.length > 100
79-
? props.item.value.slice(0, 100) + '...'
80-
: props.item.value;
79+
return ellipsize(props.item.value, 100);
8180
};
8281

8382
export function Attributes({

static/app/views/performance/newTraceDetails/traceDrawer/details/styles.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import type {Organization} from 'sentry/types/organization';
4747
import type {Project} from 'sentry/types/project';
4848
import {trackAnalytics} from 'sentry/utils/analytics';
4949
import getDuration from 'sentry/utils/duration/getDuration';
50+
import {ellipsize} from 'sentry/utils/string/ellipsize';
5051
import type {Color, ColorOrAlias} from 'sentry/utils/theme';
5152
import {useLocation} from 'sentry/utils/useLocation';
5253
import useOrganization from 'sentry/utils/useOrganization';
@@ -1288,7 +1289,7 @@ function MultilineText({children}: {children: string}) {
12881289
{isExpanded || !needsTruncation ? (
12891290
children
12901291
) : (
1291-
<Fragment>{children.slice(0, truncatePosition) + '...'}</Fragment>
1292+
<Fragment>{ellipsize(children, truncatePosition)}</Fragment>
12921293
)}
12931294
{needsTruncation ? (
12941295
<Flex style={{justifyContent: 'center', paddingTop: space(1)}}>

0 commit comments

Comments
 (0)