Skip to content

Commit edd1447

Browse files
committed
fix: address PR review feedback for IndexingStatusBadge
- Fixed useEffect dependency array by removing tooltipTimeout - Internationalized all user-facing strings with translation keys - Moved IndexingStatus types to shared/ExtensionMessage.ts - Created reusable useTooltip hook for tooltip management - Memoized progress calculation with useMemo - Added comprehensive test suite with 10 tests All review comments from PR #4532 have been addressed.
1 parent f357b44 commit edd1447

File tree

6 files changed

+378
-51
lines changed

6 files changed

+378
-51
lines changed

src/shared/ExtensionMessage.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ import { McpServer } from "./mcp"
1717
import { Mode } from "./modes"
1818
import { RouterModels } from "./api"
1919

20+
// Indexing status types
21+
export interface IndexingStatus {
22+
systemStatus: string
23+
message?: string
24+
processedItems: number
25+
totalItems: number
26+
currentItemUnit?: string
27+
}
28+
29+
export interface IndexingStatusUpdateMessage {
30+
type: "indexingStatusUpdate"
31+
values: IndexingStatus
32+
}
33+
2034
export interface LanguageModelChatSelector {
2135
vendor?: string
2236
family?: string

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

Lines changed: 23 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,25 @@
1-
import React, { useState, useEffect } from "react"
1+
import React, { useState, useEffect, useMemo } from "react"
22
import { cn } from "@src/lib/utils"
33
import { vscode } from "@src/utils/vscode"
4-
5-
interface IndexingStatus {
6-
systemStatus: string
7-
message?: string
8-
processedItems: number
9-
totalItems: number
10-
currentItemUnit?: string
11-
}
12-
13-
interface IndexingStatusUpdateMessage {
14-
type: "indexingStatusUpdate"
15-
values: IndexingStatus
16-
}
4+
import { useAppTranslation } from "@/i18n/TranslationContext"
5+
import { useTooltip } from "@/hooks/useTooltip"
6+
import type { IndexingStatus, IndexingStatusUpdateMessage } from "@roo/ExtensionMessage"
177

188
interface IndexingStatusDotProps {
199
onNavigateToSettings?: () => void
2010
className?: string
2111
}
2212

2313
export const IndexingStatusDot: React.FC<IndexingStatusDotProps> = ({ onNavigateToSettings, className }) => {
14+
const { t } = useAppTranslation()
15+
const { showTooltip, handleMouseEnter, handleMouseLeave, cleanup } = useTooltip({ delay: 300 })
16+
2417
const [indexingStatus, setIndexingStatus] = useState<IndexingStatus>({
2518
systemStatus: "Standby",
2619
processedItems: 0,
2720
totalItems: 0,
2821
currentItemUnit: "items",
2922
})
30-
const [showTooltip, setShowTooltip] = useState(false)
31-
const [tooltipTimeout, setTooltipTimeout] = useState<NodeJS.Timeout | null>(null)
3223

3324
useEffect(() => {
3425
// Request initial indexing status
@@ -46,44 +37,35 @@ export const IndexingStatusDot: React.FC<IndexingStatusDotProps> = ({ onNavigate
4637

4738
return () => {
4839
window.removeEventListener("message", handleMessage)
49-
if (tooltipTimeout) clearTimeout(tooltipTimeout)
40+
cleanup()
5041
}
51-
}, [tooltipTimeout])
42+
}, [cleanup])
5243

53-
// Calculate progress percentage
54-
const progressPercentage =
55-
indexingStatus.totalItems > 0
56-
? Math.round((indexingStatus.processedItems / indexingStatus.totalItems) * 100)
57-
: 0
44+
// Calculate progress percentage with memoization
45+
const progressPercentage = useMemo(
46+
() =>
47+
indexingStatus.totalItems > 0
48+
? Math.round((indexingStatus.processedItems / indexingStatus.totalItems) * 100)
49+
: 0,
50+
[indexingStatus.processedItems, indexingStatus.totalItems],
51+
)
5852

59-
// Get tooltip text
53+
// Get tooltip text with internationalization
6054
const getTooltipText = () => {
6155
switch (indexingStatus.systemStatus) {
6256
case "Standby":
63-
return "Index ready"
57+
return t("chat:indexingStatus.ready")
6458
case "Indexing":
65-
return `Indexing ${progressPercentage}%`
59+
return t("chat:indexingStatus.indexing", { percentage: progressPercentage })
6660
case "Indexed":
67-
return "Indexed"
61+
return t("chat:indexingStatus.indexed")
6862
case "Error":
69-
return "Index error"
63+
return t("chat:indexingStatus.error")
7064
default:
71-
return "Index status"
65+
return t("chat:indexingStatus.status")
7266
}
7367
}
7468

75-
// Handle mouse events for tooltip
76-
const handleMouseEnter = () => {
77-
if (tooltipTimeout) clearTimeout(tooltipTimeout)
78-
const timeout = setTimeout(() => setShowTooltip(true), 300) // 300ms delay
79-
setTooltipTimeout(timeout)
80-
}
81-
82-
const handleMouseLeave = () => {
83-
if (tooltipTimeout) clearTimeout(tooltipTimeout)
84-
setShowTooltip(false)
85-
}
86-
8769
// Navigate to settings when clicked
8870
const handleClick = () => {
8971
if (onNavigateToSettings) {

0 commit comments

Comments
 (0)