| 1 | import { |
| 2 | ArrowTopRightOnSquareIcon, |
| 3 | ChevronRightIcon, |
| 4 | ClipboardIcon, |
| 5 | XCircleIcon, |
| 6 | } from "@heroicons/react/24/outline"; |
| 7 | import { IndexingProgressUpdate } from "core"; |
| 8 | import { useContext, useState } from "react"; |
| 9 | import { GhostButton } from "../../../../components"; |
| 10 | import { IdeMessengerContext } from "../../../../context/IdeMessenger"; |
| 11 | import { useAppSelector } from "../../../../redux/hooks"; |
| 12 | |
| 13 | export interface IndexingProgressErrorTextProps { |
| 14 | update: IndexingProgressUpdate; |
| 15 | } |
| 16 | |
| 17 | const copyWarningsToClipboard = (warnings: string[] = []) => { |
| 18 | const warningsText = warnings.join("\n"); |
| 19 | void navigator.clipboard.writeText(warningsText); |
| 20 | }; |
| 21 | |
| 22 | function IndexingProgressErrorText({ update }: IndexingProgressErrorTextProps) { |
| 23 | const ideMessenger = useContext(IdeMessengerContext); |
| 24 | const [showWarnings, setShowWarnings] = useState(false); |
| 25 | const embeddingsProvider = useAppSelector( |
| 26 | (state) => state.config.config.selectedModelByRole.embed, |
| 27 | ); |
| 28 | |
| 29 | if (!embeddingsProvider) { |
| 30 | return ( |
| 31 | <div className="flex items-center gap-2 italic"> |
| 32 | <XCircleIcon className="h-4 w-4 min-w-[10%]" /> |
| 33 | <span className="leading-relaxed"> |
| 34 | Add an Embeddings model to enable codebase indexing. See the docs for |
| 35 | examples: |
| 36 | <a |
| 37 | href="https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers" |
| 38 | target="_blank" |
| 39 | className="cursor-pointer text-inherit underline hover:text-inherit" |
| 40 | > |
| 41 | https://docs.continue.dev/walkthroughs/codebase-embeddings#embeddings-providers |
| 42 | </a> |
| 43 | </span> |
| 44 | </div> |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | // Show warnings if they exist (for completed indexing with warnings) |
| 49 | if ( |
| 50 | update.warnings && |
| 51 | update.warnings.length > 0 && |
| 52 | update.status !== "failed" |
| 53 | ) { |
| 54 | return ( |
| 55 | <div> |
| 56 | <div |
| 57 | className="flex cursor-pointer items-center gap-2 italic text-yellow-600" |
| 58 | onClick={() => setShowWarnings(!showWarnings)} |
| 59 | > |
| 60 | <span className="leading-relaxed"> |
| 61 | {update.warnings.length} warning |
| 62 | {update.warnings.length > 1 ? "s" : ""} during indexing |
| 63 | </span> |
| 64 | <ChevronRightIcon |
| 65 | className={`h-3 w-3 transition-transform duration-300 ${ |
| 66 | showWarnings ? "rotate-90" : "" |
| 67 | }`} |
| 68 | /> |
| 69 | </div> |
| 70 | |
| 71 | <div |
| 72 | className={`ml-3 overflow-hidden transition-all duration-300 ease-in-out ${ |
| 73 | showWarnings ? "mt-2 max-h-96 opacity-100" : "max-h-0 opacity-0" |
| 74 | }`} |
| 75 | > |
| 76 | {/* Warning messages */} |
| 77 | <div className="space-y-1"> |
| 78 | {update.warnings.map((warning, index) => ( |
| 79 | <div key={index} className="text-xs"> |
| 80 | • {warning} |
| 81 | </div> |
| 82 | ))} |
| 83 | </div> |
| 84 | |
| 85 | {/* Action Buttons */} |
| 86 | <div className="flex flex-row items-center justify-end gap-2 pt-4"> |
| 87 | {/* Copy all warnings to clipboard */} |
| 88 | <GhostButton |
| 89 | onClick={() => copyWarningsToClipboard(update.warnings)} |
| 90 | className="flex items-center !px-1.5 !py-0.5 text-xs" |
| 91 | > |
| 92 | <ClipboardIcon className="mr-1 h-3 w-3" /> |
| 93 | <span>Copy output</span> |
| 94 | </GhostButton> |
| 95 | |
| 96 | {/* Open dev tools to view logs */} |
| 97 | <GhostButton |
| 98 | onClick={() => { |
| 99 | ideMessenger.post("toggleDevTools", undefined); |
| 100 | }} |
| 101 | className="flex items-center !px-1.5 !py-0.5 text-xs" |
| 102 | > |
| 103 | <ArrowTopRightOnSquareIcon className="mr-1 h-3 w-3" /> |
| 104 | <span>View Logs</span> |
| 105 | </GhostButton> |
| 106 | </div> |
| 107 | </div> |
| 108 | </div> |
| 109 | ); |
| 110 | } |
| 111 | |
| 112 | // Show error for failed status |
| 113 | return ( |
| 114 | <div className="flex items-center gap-2 italic text-red-600"> |
| 115 | <XCircleIcon className="h-4 w-4" /> |
| 116 | <span className="leading-relaxed">{update.desc}</span> |
| 117 | </div> |
| 118 | ); |
| 119 | } |
| 120 | |
| 121 | export default IndexingProgressErrorText; |