(feat:chunks) redesigned

This commit is contained in:
ManishMadan2882
2025-07-17 02:16:40 +05:30
parent a9baf7436a
commit 29698ca169

View File

@@ -7,11 +7,13 @@ import userService from '../api/services/userService';
import ArrowLeft from '../assets/arrow-left.svg'; import ArrowLeft from '../assets/arrow-left.svg';
import NoFilesIcon from '../assets/no-files.svg'; import NoFilesIcon from '../assets/no-files.svg';
import NoFilesDarkIcon from '../assets/no-files-dark.svg'; import NoFilesDarkIcon from '../assets/no-files-dark.svg';
import OutlineSource from '../assets/outline-source.svg';
import Spinner from '../components/Spinner'; import Spinner from '../components/Spinner';
import Input from '../components/Input';
import ChunkModal from '../modals/ChunkModal'; import ChunkModal from '../modals/ChunkModal';
import { ActiveState } from '../models/misc'; import { ActiveState } from '../models/misc';
import { ChunkType } from '../settings/types'; import { ChunkType } from '../settings/types';
import EditIcon from '../assets/edit.svg';
import Pagination from './DocumentPagination';
interface DocumentChunksProps { interface DocumentChunksProps {
documentId: string; documentId: string;
@@ -43,6 +45,8 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
chunk: ChunkType | null; chunk: ChunkType | null;
}>({ state: 'INACTIVE', chunk: null }); }>({ state: 'INACTIVE', chunk: null });
const pathParts = path ? path.split('/') : [];
const fetchChunks = () => { const fetchChunks = () => {
setLoading(true); setLoading(true);
try { try {
@@ -138,40 +142,71 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
fetchChunks(); fetchChunks();
}, [page, perPage]); }, [page, perPage]);
const filteredChunks = paginatedChunks.filter((chunk) => {
if (!chunk.metadata?.title) return true;
return chunk.metadata.title
.toLowerCase()
.includes(searchTerm.toLowerCase());
});
return ( return (
<div className="mt-8 flex flex-col"> <div className="mt-8 flex flex-col">
<div className="mb-4 flex items-center">
{showHeader && ( {showHeader && (
<div className="text-eerie-black dark:text-bright-gray mb-3 flex items-center gap-3 text-sm">
<button <button
className="rounded-full border p-3 text-sm text-gray-400 dark:border-0 dark:bg-[#28292D] dark:text-gray-500 dark:hover:bg-[#2E2F34]" className="mr-3 flex h-[29px] w-[29px] items-center justify-center rounded-full border p-2 text-sm text-gray-400 dark:border-0 dark:bg-[#28292D] dark:text-gray-500 dark:hover:bg-[#2E2F34]"
onClick={handleGoBack} onClick={handleGoBack}
> >
<img src={ArrowLeft} alt="left-arrow" className="h-3 w-3" /> <img src={ArrowLeft} alt="left-arrow" className="h-3 w-3" />
</button> </button>
<p className="mt-px">{t('settings.documents.backToAll')}</p>
</div>
)} )}
<div className="my-3 flex items-center justify-between gap-1">
<div className="text-eerie-black dark:text-bright-gray flex w-full items-center gap-2 sm:w-auto"> <div className="flex items-center">
<p className="hidden text-2xl font-semibold sm:flex">{`${totalChunks} ${t('settings.documents.chunks')}`}</p> <img src={OutlineSource} alt="source" className="mr-2 h-5 w-5" />
<label htmlFor="chunk-search-input" className="sr-only"> <span className="text-[#7D54D1] font-semibold text-base leading-6">
{t('settings.documents.searchPlaceholder')} {documentName}
</label> </span>
<Input
maxLength={256} {pathParts.length > 0 && (
placeholder={t('settings.documents.searchPlaceholder')} <>
name="chunk-search-input" <span className="mx-1 text-gray-500">/</span>
{pathParts.map((part, index) => (
<React.Fragment key={index}>
<span className="font-normal text-base leading-6 text-gray-700 dark:text-gray-300">
{part}
</span>
{index < pathParts.length - 1 && (
<span className="mx-1 text-gray-500">/</span>
)}
</React.Fragment>
))}
</>
)}
</div>
</div>
<div className="my-3 flex items-center justify-between gap-3">
<div className="flex-1 flex items-center border border-[#D1D9E0] dark:border-[#6A6A6A] rounded-md overflow-hidden h-[38px]">
<div className="px-4 flex items-center text-gray-700 dark:text-[#E0E0E0] font-medium whitespace-nowrap h-full">
{totalChunks > 999999
? `${(totalChunks / 1000000).toFixed(2)}M`
: totalChunks > 999
? `${(totalChunks / 1000).toFixed(2)}K`
: totalChunks} {t('settings.documents.chunks')}
</div>
<div className="h-full w-[1px] bg-[#D1D9E0] dark:bg-[#6A6A6A]"></div>
<div className="flex-1 h-full">
<input
type="text" type="text"
id="chunk-search-input" placeholder={t('settings.documents.searchPlaceholder')}
value={searchTerm} value={searchTerm}
onChange={(e) => { onChange={(e) => setSearchTerm(e.target.value)}
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]"
}}
borderVariant="thin"
/> />
</div> </div>
</div>
<button <button
className="bg-purple-30 hover:bg-violets-are-blue flex h-[32px] min-w-[108px] items-center justify-center rounded-full px-4 text-sm whitespace-normal text-white" className="bg-purple-30 hover:bg-violets-are-blue flex h-[38px] min-w-[108px] items-center justify-center rounded-full px-4 text-sm whitespace-normal text-white shrink-0"
title={t('settings.documents.addNew')} title={t('settings.documents.addNew')}
onClick={() => setAddModal('ACTIVE')} onClick={() => setAddModal('ACTIVE')}
> >
@@ -185,14 +220,9 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
</div> </div>
</div> </div>
) : ( ) : (
<div className="grid grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3"> <div className="flex flex-wrap gap-4">
{paginatedChunks.filter((chunk) => { {filteredChunks.length === 0 ? (
if (!chunk.metadata?.title) return true; <div className="w-full flex flex-col items-center justify-center mt-24 text-center text-gray-500 dark:text-gray-400">
return chunk.metadata.title
.toLowerCase()
.includes(searchTerm.toLowerCase());
}).length === 0 ? (
<div className="col-span-2 mt-24 text-center text-gray-500 lg:col-span-3 dark:text-gray-400">
<img <img
src={isDarkTheme ? NoFilesDarkIcon : NoFilesIcon} src={isDarkTheme ? NoFilesDarkIcon : NoFilesIcon}
alt={t('settings.documents.noChunksAlt')} alt={t('settings.documents.noChunksAlt')}
@@ -201,20 +231,16 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
{t('settings.documents.noChunks')} {t('settings.documents.noChunks')}
</div> </div>
) : ( ) : (
paginatedChunks filteredChunks.map((chunk, index) => (
.filter((chunk) => {
if (!chunk.metadata?.title) return true;
return chunk.metadata.title
.toLowerCase()
.includes(searchTerm.toLowerCase());
})
.map((chunk, index) => (
<div <div
key={index} key={index}
className="border-silver dark:border-silver/40 relative flex h-56 w-full flex-col justify-between rounded-2xl border p-6" className="relative flex h-[208px] w-[486px] flex-col justify-between rounded-[5.86px] border border-[#D1D9E0] dark:border-[#6A6A6A] overflow-hidden"
> >
<div className="w-full"> <div className="w-full">
<div className="flex w-full items-center justify-between"> <div className="flex w-full items-center justify-between border-b border-[#D1D9E0] bg-[#F6F8FA] dark:bg-[#27282D] dark:border-[#6A6A6A] px-4 py-3">
<div className="text-[#59636E] text-sm dark:text-[#E0E0E0]">
{chunk.metadata.token_count ? chunk.metadata.token_count.toLocaleString() : '-'} tokens
</div>
<button <button
aria-label={'edit'} aria-label={'edit'}
onClick={() => { onClick={() => {
@@ -225,14 +251,11 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
}} }}
className="text-left" className="text-left"
> >
<h3 className="text-eerie-black dark:text-bright-gray line-clamp-2 text-base font-semibold"> <img src={EditIcon} alt="edit" className="h-4 w-4" />
{chunk.metadata?.title ||
t('settings.documents.untitled')}
</h3>
</button> </button>
</div> </div>
<div className="mt-2 h-[80px] overflow-hidden"> <div className="p-4">
<p className="text-eerie-black dark:text-bright-gray line-clamp-4 text-sm"> <p className="font-['Inter'] text-[13.68px] leading-[19.93px] text-[#18181B] dark:text-[#E0E0E0] line-clamp-7 font-normal">
{chunk.text} {chunk.text}
</p> </p>
</div> </div>
@@ -243,6 +266,19 @@ const DocumentChunks: React.FC<DocumentChunksProps> = ({
</div> </div>
)} )}
{!loading && filteredChunks.length > 0 && (
<Pagination
currentPage={page}
totalPages={Math.ceil(totalChunks / perPage)}
rowsPerPage={perPage}
onPageChange={setPage}
onRowsPerPageChange={(rows) => {
setPerPage(rows);
setPage(1);
}}
/>
)}
<ChunkModal <ChunkModal
type="ADD" type="ADD"
modalState={addModal} modalState={addModal}