mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? Feat: Display agent version in pages #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
24
web/src/hooks/logic-hooks/use-pagination.ts
Normal file
24
web/src/hooks/logic-hooks/use-pagination.ts
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
|
export function useClientPagination(list: Array<any>) {
|
||||||
|
const [page, setPage] = useState(1);
|
||||||
|
const [pageSize, setPageSize] = useState(10);
|
||||||
|
|
||||||
|
const onPaginationChange = useCallback((page: number, pageSize: number) => {
|
||||||
|
setPage(page);
|
||||||
|
setPageSize(pageSize);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const pagedList = useMemo(() => {
|
||||||
|
return list?.slice((page - 1) * pageSize, page * pageSize);
|
||||||
|
}, [list, page, pageSize]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
page,
|
||||||
|
pageSize,
|
||||||
|
setPage,
|
||||||
|
setPageSize,
|
||||||
|
onPaginationChange,
|
||||||
|
pagedList,
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -6,7 +6,9 @@ import {
|
|||||||
DialogHeader,
|
DialogHeader,
|
||||||
DialogTitle,
|
DialogTitle,
|
||||||
} from '@/components/ui/dialog';
|
} from '@/components/ui/dialog';
|
||||||
|
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
|
||||||
import { Spin } from '@/components/ui/spin';
|
import { Spin } from '@/components/ui/spin';
|
||||||
|
import { useClientPagination } from '@/hooks/logic-hooks/use-pagination';
|
||||||
import {
|
import {
|
||||||
useFetchVersion,
|
useFetchVersion,
|
||||||
useFetchVersionList,
|
useFetchVersionList,
|
||||||
@ -34,6 +36,9 @@ export function VersionDialog({
|
|||||||
const [selectedId, setSelectedId] = useState<string>('');
|
const [selectedId, setSelectedId] = useState<string>('');
|
||||||
const { data: agent, loading: versionLoading } = useFetchVersion(selectedId);
|
const { data: agent, loading: versionLoading } = useFetchVersion(selectedId);
|
||||||
|
|
||||||
|
const { page, pageSize, onPaginationChange, pagedList } =
|
||||||
|
useClientPagination(data);
|
||||||
|
|
||||||
const handleClick = useCallback(
|
const handleClick = useCallback(
|
||||||
(id: string) => () => {
|
(id: string) => () => {
|
||||||
setSelectedId(id);
|
setSelectedId(id);
|
||||||
@ -58,19 +63,21 @@ export function VersionDialog({
|
|||||||
<Dialog open onOpenChange={hideModal}>
|
<Dialog open onOpenChange={hideModal}>
|
||||||
<DialogContent className="max-w-[60vw]">
|
<DialogContent className="max-w-[60vw]">
|
||||||
<DialogHeader>
|
<DialogHeader>
|
||||||
<DialogTitle>{t('flow.historyversion')}</DialogTitle>
|
<DialogTitle className="text-base">
|
||||||
|
{t('flow.historyversion')}
|
||||||
|
</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
<section className="flex gap-2 relative">
|
<section className="flex gap-8 relative">
|
||||||
<div className="w-1/3 max-h-[60vh] overflow-auto min-h-[40vh]">
|
<div className="w-1/3 max-h-[60vh] overflow-auto min-h-[40vh]">
|
||||||
{loading ? (
|
{loading ? (
|
||||||
<Spin className="top-1/2"></Spin>
|
<Spin className="top-1/2"></Spin>
|
||||||
) : (
|
) : (
|
||||||
<ul className="space-y-2">
|
<ul className="space-y-4 text-sm">
|
||||||
{data.map((x) => (
|
{pagedList.map((x) => (
|
||||||
<li
|
<li
|
||||||
key={x.id}
|
key={x.id}
|
||||||
className={cn('cursor-pointer', {
|
className={cn('cursor-pointer p-2', {
|
||||||
'bg-card rounded p-1': x.id === selectedId,
|
'bg-card rounded-md ': x.id === selectedId,
|
||||||
})}
|
})}
|
||||||
onClick={handleClick(x.id)}
|
onClick={handleClick(x.id)}
|
||||||
>
|
>
|
||||||
@ -80,51 +87,59 @@ export function VersionDialog({
|
|||||||
</ul>
|
</ul>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="relative flex-1 ">
|
<div className="relative flex-1 ">
|
||||||
{versionLoading ? (
|
{versionLoading ? (
|
||||||
<Spin className="top-1/2" />
|
<Spin className="top-1/2" />
|
||||||
) : (
|
) : (
|
||||||
<Card className="h-full">
|
<Card className="h-full">
|
||||||
<CardContent className="h-full p-5">
|
<CardContent className="h-full p-5 flex flex-col">
|
||||||
<section className="flex justify-between">
|
<section className="flex justify-between">
|
||||||
<div>
|
<div>
|
||||||
<div className="pb-1">{agent?.title}</div>
|
<div className="pb-1 truncate">{agent?.title}</div>
|
||||||
<p className="text-text-sub-title text-xs">
|
<p className="text-text-sub-title text-xs">
|
||||||
{formatDate(agent?.create_date)}
|
Created: {formatDate(agent?.create_date)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<Button variant={'ghost'} onClick={downloadFile}>
|
<Button variant={'ghost'} onClick={downloadFile}>
|
||||||
<ArrowDownToLine />
|
<ArrowDownToLine />
|
||||||
</Button>
|
</Button>
|
||||||
</section>
|
</section>
|
||||||
<ReactFlowProvider key={`flow-${selectedId}`}>
|
<section className="relative flex-1">
|
||||||
<ReactFlow
|
<ReactFlowProvider key={`flow-${selectedId}`}>
|
||||||
connectionMode={ConnectionMode.Loose}
|
<ReactFlow
|
||||||
nodes={agent?.dsl.graph?.nodes || []}
|
connectionMode={ConnectionMode.Loose}
|
||||||
edges={
|
nodes={agent?.dsl.graph?.nodes || []}
|
||||||
agent?.dsl.graph?.edges.flatMap((x) => ({
|
edges={
|
||||||
...x,
|
agent?.dsl.graph?.edges.flatMap((x) => ({
|
||||||
type: 'default',
|
...x,
|
||||||
})) || []
|
type: 'default',
|
||||||
}
|
})) || []
|
||||||
fitView
|
}
|
||||||
nodeTypes={nodeTypes}
|
fitView
|
||||||
edgeTypes={{}}
|
nodeTypes={nodeTypes}
|
||||||
zoomOnScroll={true}
|
edgeTypes={{}}
|
||||||
panOnDrag={true}
|
zoomOnScroll={true}
|
||||||
zoomOnDoubleClick={false}
|
panOnDrag={true}
|
||||||
preventScrolling={true}
|
zoomOnDoubleClick={false}
|
||||||
minZoom={0.1}
|
preventScrolling={true}
|
||||||
>
|
minZoom={0.1}
|
||||||
<Background />
|
className="!bg-background-agent"
|
||||||
</ReactFlow>
|
>
|
||||||
</ReactFlowProvider>
|
<Background />
|
||||||
|
</ReactFlow>
|
||||||
|
</ReactFlowProvider>
|
||||||
|
</section>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<RAGFlowPagination
|
||||||
|
total={data.length}
|
||||||
|
current={page}
|
||||||
|
pageSize={pageSize}
|
||||||
|
onChange={onPaginationChange}
|
||||||
|
></RAGFlowPagination>
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -52,6 +52,7 @@ module.exports = {
|
|||||||
'background-card': 'var(--background-card)',
|
'background-card': 'var(--background-card)',
|
||||||
'background-checked': 'var(--background-checked)',
|
'background-checked': 'var(--background-checked)',
|
||||||
'background-highlight': 'var(--background-highlight)',
|
'background-highlight': 'var(--background-highlight)',
|
||||||
|
'background-agent': 'var(--background-agent)',
|
||||||
|
|
||||||
'input-border': 'var(--input-border)',
|
'input-border': 'var(--input-border)',
|
||||||
'dot-green': 'var(--dot-green)',
|
'dot-green': 'var(--dot-green)',
|
||||||
|
|||||||
Reference in New Issue
Block a user