Skip to content

Commit 5e7cf02

Browse files
authored
[OPIK-3525] [FE] Fix table layout breaking with long categorical feedback scores (#4490)
* [OPIK-3525] [FE] Fix table layout breaking with long categorical feedback scores - Add min-w-0 and overflow-hidden to FeedbackScoreCellValue flex containers - Add min-w-0 and truncate to FeedbackScoreTag value span - Replace overflow-x-auto with truncate in FeedbackDefinitionsValueCell This prevents long categorical feedback score names from breaking the table layout in annotation queues and trace tables. * Revision 2: Add tooltip to FeedbackDefinitionsValueCell for truncated content Address PR review comment: Add CellTooltipWrapper to show full content on hover when values are truncated. * Revision 2: Add tooltip to FeedbackScoreCellValue for truncated scores
1 parent 0c8fd3d commit 5e7cf02

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

apps/opik-frontend/src/components/shared/DataTableCells/FeedbackDefinitionsValueCell.tsx

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,42 @@ import {
66
FeedbackDefinition,
77
} from "@/types/feedback-definitions";
88
import CellWrapper from "@/components/shared/DataTableCells/CellWrapper";
9+
import CellTooltipWrapper from "@/components/shared/DataTableCells/CellTooltipWrapper";
910

1011
const FeedbackDefinitionsValueCell = (
1112
context: CellContext<FeedbackDefinition, string>,
1213
) => {
1314
const feedbackDefinition = context.row.original;
1415

15-
let items = null;
16+
let items: React.ReactNode = null;
17+
let tooltipContent: string | undefined;
1618

1719
if (feedbackDefinition.type === FEEDBACK_DEFINITION_TYPE.categorical) {
18-
items = Object.keys(feedbackDefinition.details.categories || [])
20+
const categoryList = Object.keys(
21+
feedbackDefinition.details.categories || [],
22+
)
1923
.sort()
2024
.join(", ");
25+
items = categoryList;
26+
tooltipContent = categoryList;
2127
} else if (feedbackDefinition.type === FEEDBACK_DEFINITION_TYPE.numerical) {
22-
items = (
23-
<p>
24-
Min: {feedbackDefinition.details.min}, Max:{" "}
25-
{feedbackDefinition.details.max}
26-
</p>
27-
);
28+
const numericText = `Min: ${feedbackDefinition.details.min}, Max: ${feedbackDefinition.details.max}`;
29+
items = <p>{numericText}</p>;
30+
tooltipContent = numericText;
2831
} else if (feedbackDefinition.type === FEEDBACK_DEFINITION_TYPE.boolean) {
29-
items = `${feedbackDefinition.details.true_label}, ${feedbackDefinition.details.false_label}`;
32+
const booleanText = `${feedbackDefinition.details.true_label}, ${feedbackDefinition.details.false_label}`;
33+
items = booleanText;
34+
tooltipContent = booleanText;
3035
}
3136

3237
return (
3338
<CellWrapper
3439
metadata={context.column.columnDef.meta}
3540
tableMetadata={context.table.options.meta}
3641
>
37-
<div className="flex max-h-full flex-row gap-2 overflow-x-auto">
38-
{items}
39-
</div>
42+
<CellTooltipWrapper content={tooltipContent}>
43+
<div className="min-w-0 truncate">{items}</div>
44+
</CellTooltipWrapper>
4045
</CellWrapper>
4146
);
4247
};

apps/opik-frontend/src/components/shared/DataTableCells/FeedbackScoreCellValue.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { TAG_VARIANTS_COLOR_MAP } from "@/components/ui/tag";
44
import { TraceFeedbackScore } from "@/types/traces";
55
import { useState } from "react";
66
import FeedbackScoreEditDropdown from "./FeedbackScoreEditDropdown";
7+
import CellTooltipWrapper from "./CellTooltipWrapper";
78

89
const FeedbackScoreCellValue = ({
910
isUserFeedbackColumn = false,
@@ -26,7 +27,7 @@ const FeedbackScoreCellValue = ({
2627
// If no feedback score, show only dash with optional edit button
2728
if (!feedbackScore) {
2829
return (
29-
<div className="flex items-center gap-1">
30+
<div className="flex min-w-0 items-center gap-1 overflow-hidden">
3031
{shouldShowEditDropdown && (
3132
<FeedbackScoreEditDropdown
3233
feedbackScore={feedbackScore}
@@ -46,8 +47,10 @@ const FeedbackScoreCellValue = ({
4647
const value = feedbackScore.value;
4748
const category = feedbackScore.category_name;
4849

50+
const displayText = category ? `${category} (${value})` : String(value);
51+
4952
return (
50-
<div className="flex items-center gap-1">
53+
<div className="flex min-w-0 items-center gap-1 overflow-hidden">
5154
{shouldShowEditDropdown && (
5255
<FeedbackScoreEditDropdown
5356
feedbackScore={feedbackScore}
@@ -63,9 +66,9 @@ const FeedbackScoreCellValue = ({
6366
open={openHoverCard}
6467
onOpenChange={setOpenHoverCard}
6568
>
66-
<div className="truncate">
67-
{category ? `${category} (${value})` : value}
68-
</div>
69+
<CellTooltipWrapper content={displayText}>
70+
<div className="truncate">{displayText}</div>
71+
</CellTooltipWrapper>
6972
</MultiValueFeedbackScoreHoverCard>
7073
</div>
7174
);

apps/opik-frontend/src/components/shared/FeedbackScoreTag/FeedbackScoreTag.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const FeedbackScoreTag: React.FunctionComponent<FeedbackScoreTagProps> = ({
9797
{/* Value */}
9898
<span
9999
data-testid="feedback-score-tag-value"
100-
className="comet-body-s-accented"
100+
className="comet-body-s-accented min-w-0 truncate"
101101
>
102102
{displayValue}
103103
</span>

0 commit comments

Comments
 (0)