mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-09-11 22:09:44 +00:00
feat: update getFlows API function to support pagination (#1868)
This commit is contained in:
@@ -275,8 +275,11 @@ export const addFlow = (data: IFlowUpdateParam) => {
|
||||
return POST<IFlowUpdateParam, IFlow>('/api/v2/serve/awel/flows', data);
|
||||
};
|
||||
|
||||
export const getFlows = () => {
|
||||
return GET<null, IFlowResponse>('/api/v2/serve/awel/flows');
|
||||
export const getFlows = (page?: number, page_size?: number) => {
|
||||
return GET<any, IFlowResponse>('/api/v2/serve/awel/flows', {
|
||||
page,
|
||||
page_size,
|
||||
});
|
||||
};
|
||||
|
||||
export const getFlowById = (id: string) => {
|
||||
|
@@ -122,7 +122,7 @@ const AddNodes: React.FC = () => {
|
||||
className="flex items-center justify-center rounded-full left-4 top-4"
|
||||
style={{ zIndex: 1050 }}
|
||||
icon={<PlusOutlined />}
|
||||
></Button>
|
||||
/>
|
||||
</Popover>
|
||||
);
|
||||
};
|
||||
|
@@ -80,8 +80,6 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
||||
}
|
||||
|
||||
async function updateDependsNodeValue(changedKey: string, changedVal: any) {
|
||||
if (!changedVal) return;
|
||||
|
||||
const dependParamNodes = parameters.filter(({ ui }) => ui?.refresh_depends?.includes(changedKey));
|
||||
|
||||
if (dependParamNodes?.length === 0) return;
|
||||
@@ -107,20 +105,34 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
||||
};
|
||||
|
||||
const [_, res] = await apiInterceptors(refreshFlowNodeById(params));
|
||||
// TODO: update node value
|
||||
console.log('res', res);
|
||||
|
||||
// update value of the node
|
||||
if (res) {
|
||||
reactFlow.setNodes((nodes) =>
|
||||
nodes.map((n) => {
|
||||
return n.id === node.id
|
||||
? {
|
||||
...n,
|
||||
data: {
|
||||
...n.data,
|
||||
parameters: res.parameters,
|
||||
},
|
||||
}
|
||||
: n;
|
||||
}),
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function onParameterValuesChange(changedValues: any, allValues: any) {
|
||||
// TODO: update node value
|
||||
console.log('Changed xxx', changedValues);
|
||||
console.log('All xxx', allValues);
|
||||
|
||||
const [changedKey, changedVal] = Object.entries(changedValues)[0];
|
||||
|
||||
updateCurrentNodeValue(changedKey, changedVal);
|
||||
updateDependsNodeValue(changedKey, changedVal);
|
||||
if (changedVal) {
|
||||
updateDependsNodeValue(changedKey, changedVal);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
@@ -132,9 +144,11 @@ const CanvasNode: React.FC<CanvasNodeProps> = ({ data }) => {
|
||||
<IconWrapper className="hover:text-blue-500">
|
||||
<CopyOutlined className="h-full text-lg cursor-pointer" onClick={copyNode} />
|
||||
</IconWrapper>
|
||||
|
||||
<IconWrapper className="mt-2 hover:text-red-500">
|
||||
<DeleteOutlined className="h-full text-lg cursor-pointer" onClick={deleteNode} />
|
||||
</IconWrapper>
|
||||
|
||||
<IconWrapper className="mt-2">
|
||||
<Tooltip
|
||||
title={
|
||||
|
@@ -12,7 +12,6 @@ type Props = {
|
||||
|
||||
export const renderCodeEditor = (data: IFlowNodeParameter) => {
|
||||
const { t } = useTranslation();
|
||||
// const { data, defaultValue } = params;
|
||||
const attr = convertKeysToCamelCase(data.ui?.attr || {});
|
||||
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
|
@@ -269,6 +269,7 @@ const Canvas: React.FC<Props> = () => {
|
||||
<AddNodes />
|
||||
</ReactFlow>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
title={t('flow_modal_title')}
|
||||
open={isModalVisible}
|
||||
|
@@ -4,7 +4,7 @@ import MuiLoading from '@/components/common/loading';
|
||||
import FlowCard from '@/components/flow/flow-card';
|
||||
import { IFlow, IFlowUpdateParam } from '@/types/flow';
|
||||
import { PlusOutlined } from '@ant-design/icons';
|
||||
import { Button, Checkbox, Form, Input, Modal, message } from 'antd';
|
||||
import { Button, Checkbox, Form, Input, Modal, message, Pagination, PaginationProps } from 'antd';
|
||||
import Link from 'next/link';
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -16,22 +16,25 @@ function Flow() {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [flowList, setFlowList] = useState<Array<IFlow>>([]);
|
||||
const [deploy, setDeploy] = useState(false);
|
||||
const [page, setPage] = useState<number>(1);
|
||||
const [pageSize, setPageSize] = useState<number>(10);
|
||||
const [total, setTotal] = useState<number>(0);
|
||||
|
||||
const [messageApi, contextHolder] = message.useMessage();
|
||||
const [form] = Form.useForm<Pick<IFlow, 'label' | 'name'>>();
|
||||
|
||||
const copyFlowTemp = useRef<IFlow>();
|
||||
|
||||
async function getFlowList() {
|
||||
setLoading(true);
|
||||
const [_, data] = await apiInterceptors(getFlows());
|
||||
const [_, data] = await apiInterceptors(getFlows(page, pageSize));
|
||||
setTotal(data?.total_count ?? 0);
|
||||
setLoading(false);
|
||||
setFlowList(data?.items ?? []);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
getFlowList();
|
||||
}, []);
|
||||
}, [page, pageSize]);
|
||||
|
||||
function updateFlowList(uid: string) {
|
||||
setFlowList((flows) => flows.filter((flow) => flow.uid !== uid));
|
||||
@@ -62,10 +65,16 @@ function Flow() {
|
||||
}
|
||||
};
|
||||
|
||||
const onPageChange: PaginationProps['onChange'] = (page: number, pageSize: number) => {
|
||||
setPage(page);
|
||||
setPageSize(pageSize);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="relative p-4 md:p-6 min-h-full overflow-y-auto">
|
||||
<div className="flex flex-col justify-between relative p-4 md:p-6 min-h-full overflow-y-auto">
|
||||
{contextHolder}
|
||||
<MuiLoading visible={loading} />
|
||||
|
||||
<div className="mb-4">
|
||||
<Link href="/flow/canvas">
|
||||
<Button type="primary" className="flex items-center" icon={<PlusOutlined />}>
|
||||
@@ -73,12 +82,29 @@ function Flow() {
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 md:gap-4 justify-start items-stretch">
|
||||
{flowList.map((flow) => (
|
||||
<FlowCard key={flow.uid} flow={flow} deleteCallback={updateFlowList} onCopy={handleCopy} />
|
||||
))}
|
||||
{flowList.length === 0 && <MyEmpty description="No flow found" />}
|
||||
|
||||
<div className="flex flex-col justify-between flex-1">
|
||||
<div className="flex flex-wrap gap-2 md:gap-4 justify-start items-stretch">
|
||||
{flowList.map((flow) => (
|
||||
<FlowCard key={flow.uid} flow={flow} deleteCallback={updateFlowList} onCopy={handleCopy} />
|
||||
))}
|
||||
{flowList.length === 0 && <MyEmpty description="No flow found" />}
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end mt-6">
|
||||
<Pagination
|
||||
showQuickJumper
|
||||
showSizeChanger
|
||||
defaultPageSize={10}
|
||||
defaultCurrent={1}
|
||||
current={page}
|
||||
total={total}
|
||||
showTotal={(total) => `Total ${total} items`}
|
||||
onChange={onPageChange}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
open={showModal}
|
||||
title="Copy AWEL Flow"
|
||||
|
Reference in New Issue
Block a user