Skip to content

Commit b9b8dd5

Browse files
feat: Add tooltip to API request text when cost is hidden
Refactor tooltip behavior in ChatRow component to show token stats on hover over api-request-text span when the cost badge is not displayed. Changes include: - Add conditional tooltip rendering on span when cost <= 0 - Extract shared constants to eliminate code duplication - Keep tooltip on badge when cost > 0 - Maintain original cursor behavior
1 parent 8fa4389 commit b9b8dd5

File tree

1 file changed

+55
-45
lines changed

1 file changed

+55
-45
lines changed

webview-ui/src/components/chat/ChatRow.tsx

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,46 @@ export const ChatRowContent = ({
11091109
)
11101110
const hasTokenData = tokensIn !== undefined || tokensOut !== undefined
11111111

1112+
const showPrice = cost !== null && cost !== undefined && cost > 0
1113+
1114+
const tooltipContent = (
1115+
<div className="flex flex-col gap-1">
1116+
<div className="flex items-center gap-2">
1117+
<span>{t("chat:task.tokenStats.inputLabel")}</span>
1118+
<span className="font-mono">{tokenStats.input}</span>
1119+
</div>
1120+
<div className="flex items-center gap-2">
1121+
<span>{t("chat:task.tokenStats.outputLabel")}</span>
1122+
<span className="font-mono">{tokenStats.output}</span>
1123+
</div>
1124+
</div>
1125+
)
1126+
1127+
const titleSpan = (
1128+
<span
1129+
className="api-request-text"
1130+
style={{
1131+
display: "inline-block",
1132+
fontWeight: "bold",
1133+
color: "var(--vscode-foreground)",
1134+
whiteSpace: "nowrap",
1135+
overflow: "hidden",
1136+
textOverflow: "ellipsis",
1137+
flexShrink: 1,
1138+
minWidth: 0,
1139+
}}>
1140+
{title}
1141+
</span>
1142+
)
1143+
1144+
const badgeStyle = {
1145+
opacity: showPrice ? 1 : 0,
1146+
flexShrink: 0,
1147+
...(hasTokenData ? { cursor: "default" } : {}),
1148+
}
1149+
1150+
const costBadge = <VSCodeBadge style={badgeStyle}>${Number(cost || 0)?.toFixed(4)}</VSCodeBadge>
1151+
11121152
return (
11131153
<>
11141154
<div
@@ -1136,54 +1176,24 @@ export const ChatRowContent = ({
11361176
minWidth: 0,
11371177
}}>
11381178
{icon}
1139-
<span
1140-
className="api-request-text"
1141-
style={{
1142-
display: "inline-block",
1143-
fontWeight: "bold",
1144-
color: "var(--vscode-foreground)",
1145-
whiteSpace: "nowrap",
1146-
overflow: "hidden",
1147-
textOverflow: "ellipsis",
1148-
flexShrink: 1,
1149-
minWidth: 0,
1150-
}}>
1151-
{title}
1152-
</span>
1179+
{hasTokenData && !showPrice ? (
1180+
<StandardTooltip content={tooltipContent} side="top">
1181+
{titleSpan}
1182+
</StandardTooltip>
1183+
) : (
1184+
titleSpan
1185+
)}
11531186
<div style={{ display: "flex", alignItems: "center", gap: "8px", flexShrink: 0 }}>
11541187
{hasTokenData ? (
1155-
<StandardTooltip
1156-
content={
1157-
<div className="flex flex-col gap-1">
1158-
<div className="flex items-center gap-2">
1159-
<span>{t("chat:task.tokenStats.inputLabel")}</span>
1160-
<span className="font-mono">{tokenStats.input}</span>
1161-
</div>
1162-
<div className="flex items-center gap-2">
1163-
<span>{t("chat:task.tokenStats.outputLabel")}</span>
1164-
<span className="font-mono">{tokenStats.output}</span>
1165-
</div>
1166-
</div>
1167-
}
1168-
side="top">
1169-
<VSCodeBadge
1170-
style={{
1171-
opacity:
1172-
cost !== null && cost !== undefined && cost > 0 ? 1 : 0,
1173-
flexShrink: 0,
1174-
cursor: "default",
1175-
}}>
1176-
${Number(cost || 0)?.toFixed(4)}
1177-
</VSCodeBadge>
1178-
</StandardTooltip>
1188+
showPrice ? (
1189+
<StandardTooltip content={tooltipContent} side="top">
1190+
{costBadge}
1191+
</StandardTooltip>
1192+
) : (
1193+
costBadge
1194+
)
11791195
) : (
1180-
<VSCodeBadge
1181-
style={{
1182-
opacity: cost !== null && cost !== undefined && cost > 0 ? 1 : 0,
1183-
flexShrink: 0,
1184-
}}>
1185-
${Number(cost || 0)?.toFixed(4)}
1186-
</VSCodeBadge>
1196+
costBadge
11871197
)}
11881198
</div>
11891199
</div>

0 commit comments

Comments
 (0)