| 1 | import { |
| 2 | ArrowPathIcon, |
| 3 | CheckCircleIcon, |
| 4 | PauseCircleIcon, |
| 5 | } from "@heroicons/react/24/outline"; |
| 6 | import { IndexingProgressUpdate } from "core"; |
| 7 | import { getProgressPercentage } from "./IndexingProgress"; |
| 8 | |
| 9 | export interface IndexingProgressIndicatorProps { |
| 10 | update: IndexingProgressUpdate; |
| 11 | } |
| 12 | |
| 13 | const STATUS_TO_ICON: Record<IndexingProgressUpdate["status"], any> = { |
| 14 | disabled: null, |
| 15 | loading: null, |
| 16 | waiting: null, |
| 17 | indexing: ArrowPathIcon, |
| 18 | paused: PauseCircleIcon, |
| 19 | done: CheckCircleIcon, |
| 20 | failed: null, // Since we show an erorr message below |
| 21 | cancelled: null, |
| 22 | }; |
| 23 | |
| 24 | function IndexingProgressIndicator({ update }: IndexingProgressIndicatorProps) { |
| 25 | const progressPercentage = getProgressPercentage(update.progress).toFixed(0); |
| 26 | const Icon = STATUS_TO_ICON[update.status]; |
| 27 | const animateIcon = update.status === "indexing"; |
| 28 | const showProgress = |
| 29 | update.status !== "disabled" && progressPercentage !== "100"; |
| 30 | |
| 31 | return ( |
| 32 | <div className="text-lightgray flex items-center justify-between gap-1"> |
| 33 | {showProgress && <span className="text-xs">{progressPercentage}%</span>} |
| 34 | |
| 35 | {Icon && ( |
| 36 | <div className="flex items-center"> |
| 37 | <Icon |
| 38 | className={`text-lightgray inline-block h-4 w-4 align-top ${ |
| 39 | animateIcon ? "animate-spin-slow" : "" |
| 40 | }`} |
| 41 | ></Icon> |
| 42 | </div> |
| 43 | )} |
| 44 | </div> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | export default IndexingProgressIndicator; |