-
Notifications
You must be signed in to change notification settings - Fork 146
Expand file tree
/
Copy pathIndexingStatusBadge.tsx
More file actions
112 lines (96 loc) · 3.3 KB
/
IndexingStatusBadge.tsx
File metadata and controls
112 lines (96 loc) · 3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import React, { useState, useEffect, useMemo } from "react"
import { Database } from "lucide-react"
import { cn } from "@src/lib/utils"
import { vscode } from "@src/utils/vscode"
import { useAppTranslation } from "@/i18n/TranslationContext"
import type { IndexingStatus, IndexingStatusUpdateMessage } from "@roo/ExtensionMessage"
import { useExtensionState } from "@src/context/ExtensionStateContext"
import { PopoverTrigger, StandardTooltip, Button } from "@src/components/ui"
import { CodeIndexPopover } from "./CodeIndexPopover"
interface IndexingStatusBadgeProps {
className?: string
}
export const IndexingStatusBadge: React.FC<IndexingStatusBadgeProps> = ({ className }) => {
const { t } = useAppTranslation()
const { cwd } = useExtensionState()
const [indexingStatus, setIndexingStatus] = useState<IndexingStatus>({
systemStatus: "Standby",
processedItems: 0,
totalItems: 0,
currentItemUnit: "items",
})
useEffect(() => {
// Request initial indexing status.
vscode.postMessage({ type: "requestIndexingStatus" })
// Set up message listener for status updates.
const handleMessage = (event: MessageEvent<IndexingStatusUpdateMessage>) => {
if (event.data.type === "indexingStatusUpdate") {
const status = event.data.values
if (!status.workspacePath || status.workspacePath === cwd) {
setIndexingStatus(status)
}
}
}
window.addEventListener("message", handleMessage)
return () => {
window.removeEventListener("message", handleMessage)
}
}, [cwd])
const progressPercentage = useMemo(
() =>
indexingStatus.totalItems > 0
? Math.round((indexingStatus.processedItems / indexingStatus.totalItems) * 100)
: 0,
[indexingStatus.processedItems, indexingStatus.totalItems],
)
const tooltipText = useMemo(() => {
switch (indexingStatus.systemStatus) {
case "Standby":
return t("chat:indexingStatus.ready")
case "Indexing":
return t("chat:indexingStatus.indexing", { percentage: progressPercentage })
case "Indexed":
return t("chat:indexingStatus.indexed")
case "Error":
return t("chat:indexingStatus.error")
default:
return t("chat:indexingStatus.status")
}
}, [indexingStatus.systemStatus, progressPercentage, t])
const statusColorClass = useMemo(() => {
const statusColors = {
Standby: "bg-vscode-descriptionForeground/60",
Indexing: "bg-yellow-500 animate-pulse",
Indexed: "bg-green-500",
Error: "bg-red-500",
}
return statusColors[indexingStatus.systemStatus as keyof typeof statusColors] || statusColors.Standby
}, [indexingStatus.systemStatus])
return (
<CodeIndexPopover indexingStatus={indexingStatus}>
<StandardTooltip content={tooltipText}>
<PopoverTrigger asChild>
<Button
variant="ghost"
size="sm"
aria-label={tooltipText}
className={cn(
"relative h-5 w-5 p-0",
"text-vscode-foreground opacity-85",
"hover:opacity-100 hover:bg-[rgba(255,255,255,0.03)]",
"focus:outline-none focus-visible:ring-1 focus-visible:ring-vscode-focusBorder",
className,
)}>
<Database className="w-4 h-4" />
<span
className={cn(
"absolute top-0 right-0 w-1.5 h-1.5 rounded-full transition-colors duration-200",
statusColorClass,
)}
/>
</Button>
</PopoverTrigger>
</StandardTooltip>
</CodeIndexPopover>
)
}