diff --git a/frontend/src/components/DocumentChunks.tsx b/frontend/src/components/DocumentChunks.tsx index 90718473..f994b6f7 100644 --- a/frontend/src/components/DocumentChunks.tsx +++ b/frontend/src/components/DocumentChunks.tsx @@ -140,7 +140,7 @@ const DocumentChunks: React.FC = ({ useEffect(() => { fetchChunks(); - }, [page, perPage]); + }, [page, perPage, path]); const filteredChunks = paginatedChunks.filter((chunk) => { if (!chunk.metadata?.title) return true; @@ -150,7 +150,7 @@ const DocumentChunks: React.FC = ({ }); return ( -
+
{showHeader && (
)} -
+
{totalChunks > 999999 @@ -234,7 +234,7 @@ const DocumentChunks: React.FC = ({ filteredChunks.map((chunk, index) => (
diff --git a/frontend/src/components/FileTreeComponent.tsx b/frontend/src/components/FileTreeComponent.tsx index 170c4cb9..6a61ca12 100644 --- a/frontend/src/components/FileTreeComponent.tsx +++ b/frontend/src/components/FileTreeComponent.tsx @@ -11,6 +11,7 @@ import ThreeDots from '../assets/three-dots.svg'; import EyeView from '../assets/eye-view.svg'; import OutlineSource from '../assets/outline-source.svg'; import Trash from '../assets/red-trash.svg'; +import SearchIcon from '../assets/search.svg'; interface FileNode { type?: string; @@ -29,6 +30,12 @@ interface FileTreeComponentProps { onBackToDocuments?: () => void; } +interface SearchResult { + name: string; + path: string; + isFile: boolean; +} + const FileTreeComponent: React.FC = ({ docId, sourceName, @@ -49,6 +56,8 @@ const FileTreeComponent: React.FC = ({ id: string; name: string; } | null>(null); + const [searchQuery, setSearchQuery] = useState(''); + const [searchResults, setSearchResults] = useState([]); const handleFileClick = (fileName: string) => { const fullPath = [...currentPath, fileName].join('/'); @@ -189,7 +198,7 @@ const FileTreeComponent: React.FC = ({ > left-arrow - +
source {sourceName} @@ -385,20 +394,116 @@ const FileTreeComponent: React.FC = ({ }; const currentDirectory = getCurrentDirectory(); + const searchFiles = (query: string, structure: DirectoryStructure, currentPath: string[] = []): SearchResult[] => { + let results: SearchResult[] = []; + + Object.entries(structure).forEach(([name, node]) => { + const fullPath = [...currentPath, name].join('/'); + + if (name.toLowerCase().includes(query.toLowerCase())) { + results.push({ + name, + path: fullPath, + isFile: !!node.type + }); + } + + if (!node.type) { + // If it's a directory, search recursively + results = [...results, ...searchFiles(query, node as DirectoryStructure, [...currentPath, name])]; + } + }); + + return results; + }; + + + const handleSearchSelect = (result: SearchResult) => { + if (result.isFile) { + const pathParts = result.path.split('/'); + const fileName = pathParts.pop() || ''; + setCurrentPath(pathParts); + + setSelectedFile({ + id: result.path, + name: fileName + }); + } else { + setCurrentPath(result.path.split('/')); + setSelectedFile(null); + } + setSearchQuery(''); + setSearchResults([]); + }; + return ( <>
{renderPathNavigation()}
{selectedFile ? ( - setSelectedFile(null)} - path={selectedFile.id} - showHeader={false} - /> +
+ {/* Search Panel */} +
+
+ { + setSearchQuery(e.target.value); + if (directoryStructure) { + setSearchResults(searchFiles(e.target.value, directoryStructure)); + } + }} + placeholder={t('settings.documents.searchFiles')} + className={`w-full px-4 py-2 pl-10 border border-[#D1D9E0] dark:border-[#6A6A6A] ${searchQuery ? 'rounded-t-md rounded-b-none border-b-0' : 'rounded-md' + } bg-transparent dark:text-[#E0E0E0] focus:outline-none`} + /> + + Search + + {searchQuery && ( +
+ {searchResults.map((result, index) => ( +
handleSearchSelect(result)} + className={`flex items-center px-3 py-2 cursor-pointer hover:bg-[#ECEEEF] dark:hover:bg-[#27282D] ${index !== searchResults.length - 1 ? "border-b border-[#D1D9E0] dark:border-[#6A6A6A]" : "" + }`} + > + {result.isFile + + {result.path} + +
+ ))} + {searchResults.length === 0 && ( +
+ {t('settings.documents.noResults')} +
+ )} +
+ )} +
+
+
+ setSelectedFile(null)} + path={selectedFile.id} + showHeader={false} + /> +
+
) : (
-
@@ -429,3 +534,4 @@ const FileTreeComponent: React.FC = ({ }; export default FileTreeComponent; +