diff --git a/frontend/src/components/DocumentChunks.tsx b/frontend/src/components/DocumentChunks.tsx index e4dbc4a8..d2c402a9 100644 --- a/frontend/src/components/DocumentChunks.tsx +++ b/frontend/src/components/DocumentChunks.tsx @@ -39,11 +39,10 @@ const DocumentChunks: React.FC = ({ const [totalChunks, setTotalChunks] = useState(0); const [loading, setLoading] = useLoaderState(true); const [searchTerm, setSearchTerm] = useState(''); - const [addModal, setAddModal] = useState('INACTIVE'); - const [editModal, setEditModal] = useState<{ - state: ActiveState; - chunk: ChunkType | null; - }>({ state: 'INACTIVE', chunk: null }); + const [editingChunk, setEditingChunk] = useState(null); + const [editingTitle, setEditingTitle] = useState(''); + const [editingText, setEditingText] = useState(''); + const [isAddingChunk, setIsAddingChunk] = useState(false); @@ -132,7 +131,7 @@ const DocumentChunks: React.FC = ({ if (!response.ok) { throw new Error('Failed to delete chunk'); } - setEditModal({ state: 'INACTIVE', chunk: null }); + setEditingChunk(null); fetchChunks(); }); } catch (e) { @@ -153,36 +152,67 @@ const DocumentChunks: React.FC = ({ const renderPathNavigation = () => { return ( -
- +
+
+ -
- source - - {documentName} - +
+ source + + {documentName} + - {pathParts.length > 0 && ( - <> - / - {pathParts.map((part, index) => ( - - - {part} - - {index < pathParts.length - 1 && ( - / - )} - - ))} - - )} + {pathParts.length > 0 && ( + <> + / + {pathParts.map((part, index) => ( + + + {part} + + {index < pathParts.length - 1 && ( + / + )} + + ))} + + )} +
+ + {editingChunk && ( +
+ + + +
+ )}
); }; @@ -193,92 +223,161 @@ const DocumentChunks: React.FC = ({ {renderPathNavigation()}
- {renderFileSearch && ( - renderFileSearch() - )} + {renderFileSearch && renderFileSearch()} {/* Right side: Chunks content */}
-
-
-
- {totalChunks > 999999 - ? `${(totalChunks / 1000000).toFixed(2)}M` - : totalChunks > 999 - ? `${(totalChunks / 1000).toFixed(2)}K` - : totalChunks} {t('settings.documents.chunks')} + {!editingChunk && !isAddingChunk ? ( + <> +
+
+
+ {totalChunks > 999999 + ? `${(totalChunks / 1000000).toFixed(2)}M` + : totalChunks > 999 + ? `${(totalChunks / 1000).toFixed(2)}K` + : totalChunks} {t('settings.documents.chunks')} +
+
+
+ setSearchTerm(e.target.value)} + className="w-full h-full px-3 py-2 bg-transparent border-none outline-none font-normal text-[13.56px] leading-[100%] dark:text-[#E0E0E0]" + /> +
+
+
-
-
- setSearchTerm(e.target.value)} - className="w-full h-full px-3 py-2 bg-transparent border-none outline-none font-normal text-[13.56px] leading-[100%] dark:text-[#E0E0E0]" - /> -
-
- -
- {loading ? ( -
- -
- ) : ( -
- {filteredChunks.length === 0 ? ( -
- {t('settings.documents.noChunksAlt')} - {t('settings.documents.noChunks')} + {loading ? ( +
+
) : ( - filteredChunks.map((chunk, index) => ( -
-
-
-
- {chunk.metadata.token_count ? chunk.metadata.token_count.toLocaleString() : '-'} tokens -
- -
-
-

- {chunk.text} -

-
+
+ {filteredChunks.length === 0 ? ( +
+ {t('settings.documents.noChunksAlt')} + {t('settings.documents.noChunks')}
-
- )) + ) : ( + filteredChunks.map((chunk, index) => ( +
+
+
+
+ {chunk.metadata.token_count ? chunk.metadata.token_count.toLocaleString() : '-'} tokens +
+ +
+
+

+ {chunk.text} +

+
+
+
+ )) + )} +
)} + + ) : isAddingChunk ? ( + // Add new chunk view +
+
+
+ + + {t('settings.documents.addNewChunk')} + +
+
+ +
+
+ +
+
+ +
+ + +
+
+ ) : editingChunk && ( +
+
+
+
+ {editingChunk.metadata.token_count ? editingChunk.metadata.token_count.toLocaleString() : '-'} tokens +
+
+
+ +
+
)} - {!loading && filteredChunks.length > 0 && ( + {!loading && filteredChunks.length > 0 && !editingChunk && !isAddingChunk && ( = ({ }} /> )} - - - {editModal.chunk && ( - - setEditModal((prev) => ({ ...prev, state })) - } - handleSubmit={(title, text) => { - handleUpdateChunk(title, text, editModal.chunk as ChunkType); - }} - originalText={editModal.chunk?.text ?? ''} - originalTitle={editModal.chunk?.metadata?.title ?? ''} - handleDelete={() => { - handleDeleteChunk(editModal.chunk as ChunkType); - }} - /> - )}
-
-
- ); +
+
+ ); }; - export default DocumentChunks; +export default DocumentChunks;