mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Bind data to datasets page #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -1,87 +1,17 @@
|
||||
import { ConfirmDeleteDialog } from '@/components/confirm-delete-dialog';
|
||||
import ListFilterBar from '@/components/list-filter-bar';
|
||||
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { useInfiniteFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
||||
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
||||
import { IKnowledge } from '@/interfaces/database/knowledge';
|
||||
import { formatDate } from '@/utils/date';
|
||||
import { ChevronRight, Plus, Trash2 } from 'lucide-react';
|
||||
import { useMemo } from 'react';
|
||||
import { DatasetCreatingDialog } from './dataset-creating-dialog';
|
||||
import { useSaveKnowledge } from './hooks';
|
||||
|
||||
const datasets = [
|
||||
{
|
||||
id: 1,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
title: 'HR knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
title: 'IT knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 4,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 5,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 6,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 7,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 8,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
{
|
||||
id: 9,
|
||||
title: 'Legal knowledge base',
|
||||
files: '1,242 files',
|
||||
size: '152 MB',
|
||||
created: '12.02.2024',
|
||||
image: 'https://github.com/shadcn.png',
|
||||
},
|
||||
];
|
||||
|
||||
export default function Datasets() {
|
||||
const {
|
||||
visible,
|
||||
@ -92,6 +22,25 @@ export default function Datasets() {
|
||||
} = useSaveKnowledge();
|
||||
const { navigateToDataset } = useNavigatePage();
|
||||
|
||||
const {
|
||||
fetchNextPage,
|
||||
data,
|
||||
hasNextPage,
|
||||
searchString,
|
||||
handleInputChange,
|
||||
loading,
|
||||
} = useInfiniteFetchKnowledgeList();
|
||||
|
||||
const nextList: IKnowledge[] = useMemo(() => {
|
||||
const list =
|
||||
data?.pages?.flatMap((x) => (Array.isArray(x.kbs) ? x.kbs : [])) ?? [];
|
||||
return list;
|
||||
}, [data?.pages]);
|
||||
|
||||
const total = useMemo(() => {
|
||||
return data?.pages.at(-1).total ?? 0;
|
||||
}, [data?.pages]);
|
||||
|
||||
return (
|
||||
<section className="p-8 text-foreground">
|
||||
<ListFilterBar title="Datasets" showDialog={showModal}>
|
||||
@ -99,17 +48,17 @@ export default function Datasets() {
|
||||
Create dataset
|
||||
</ListFilterBar>
|
||||
<div className="grid gap-6 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-4 xl:grid-cols-6 2xl:grid-cols-8">
|
||||
{datasets.map((dataset) => (
|
||||
{nextList.map((dataset) => (
|
||||
<Card
|
||||
key={dataset.id}
|
||||
className="bg-colors-background-inverse-weak flex-1"
|
||||
>
|
||||
<CardContent className="p-4">
|
||||
<div className="flex justify-between mb-4">
|
||||
<div
|
||||
className="w-[70px] h-[70px] rounded-xl bg-cover"
|
||||
style={{ backgroundImage: `url(${dataset.image})` }}
|
||||
/>
|
||||
<Avatar className="w-[70px] h-[70px] rounded-lg">
|
||||
<AvatarImage src={dataset.avatar} />
|
||||
<AvatarFallback className="rounded-lg">CN</AvatarFallback>
|
||||
</Avatar>
|
||||
<ConfirmDeleteDialog>
|
||||
<Button variant="ghost" size="icon">
|
||||
<Trash2 />
|
||||
@ -118,20 +67,16 @@ export default function Datasets() {
|
||||
</div>
|
||||
<div className="flex justify-between items-end">
|
||||
<div>
|
||||
<h3 className="text-lg font-semibold mb-2">
|
||||
{dataset.title}
|
||||
</h3>
|
||||
<h3 className="text-lg font-semibold mb-2">{dataset.name}</h3>
|
||||
<p className="text-sm opacity-80">{dataset.doc_num} files</p>
|
||||
<p className="text-sm opacity-80">
|
||||
{dataset.files} | {dataset.size}
|
||||
</p>
|
||||
<p className="text-sm opacity-80">
|
||||
Created {dataset.created}
|
||||
Created {formatDate(dataset.update_time)}
|
||||
</p>
|
||||
</div>
|
||||
<Button
|
||||
variant="secondary"
|
||||
variant="icon"
|
||||
size="icon"
|
||||
onClick={navigateToDataset}
|
||||
onClick={navigateToDataset(dataset.id)}
|
||||
>
|
||||
<ChevronRight className="h-6 w-6" />
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user