balibabu
commited on
Commit
·
8da11cb
1
Parent(s):
df5aa03
feat: watch graph change (#1092)
Browse files### What problem does this PR solve?
feat: watch graph change #918
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
web/src/pages/flow/canvas/index.tsx
CHANGED
@@ -78,6 +78,9 @@ function FlowCanvas({ sideWidth }: IProps) {
|
|
78 |
onKeyUp={handleKeyUp}
|
79 |
onSelectionChange={onSelectionChange}
|
80 |
nodeOrigin={[0.5, 0]}
|
|
|
|
|
|
|
81 |
defaultEdgeOptions={{
|
82 |
type: 'buttonEdge',
|
83 |
markerEnd: {
|
|
|
78 |
onKeyUp={handleKeyUp}
|
79 |
onSelectionChange={onSelectionChange}
|
80 |
nodeOrigin={[0.5, 0]}
|
81 |
+
onChange={(...params) => {
|
82 |
+
console.info('params:', ...params);
|
83 |
+
}}
|
84 |
defaultEdgeOptions={{
|
85 |
type: 'buttonEdge',
|
86 |
markerEnd: {
|
web/src/pages/flow/chat/drawer.tsx
ADDED
File without changes
|
web/src/pages/flow/{constant.ts → constant.tsx}
RENAMED
@@ -1,3 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
export enum Operator {
|
2 |
Begin = 'Begin',
|
3 |
Retrieval = 'Retrieval',
|
@@ -5,6 +11,12 @@ export enum Operator {
|
|
5 |
Answer = 'Answer',
|
6 |
}
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
export const initialRetrievalValues = {
|
9 |
similarity_threshold: 0.2,
|
10 |
keywords_similarity_weight: 0.3,
|
|
|
1 |
+
import {
|
2 |
+
MergeCellsOutlined,
|
3 |
+
RocketOutlined,
|
4 |
+
SendOutlined,
|
5 |
+
} from '@ant-design/icons';
|
6 |
+
|
7 |
export enum Operator {
|
8 |
Begin = 'Begin',
|
9 |
Retrieval = 'Retrieval',
|
|
|
11 |
Answer = 'Answer',
|
12 |
}
|
13 |
|
14 |
+
export const componentList = [
|
15 |
+
{ name: Operator.Retrieval, icon: <RocketOutlined />, description: '' },
|
16 |
+
{ name: Operator.Generate, icon: <MergeCellsOutlined />, description: '' },
|
17 |
+
{ name: Operator.Answer, icon: <SendOutlined />, description: '' },
|
18 |
+
];
|
19 |
+
|
20 |
export const initialRetrievalValues = {
|
21 |
similarity_threshold: 0.2,
|
22 |
keywords_similarity_weight: 0.3,
|
web/src/pages/flow/flow-sider/index.tsx
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import { Avatar, Card, Flex, Layout, Space } from 'antd';
|
2 |
import classNames from 'classnames';
|
3 |
-
import { componentList } from '../mock';
|
4 |
|
|
|
5 |
import { useHandleDrag } from '../hooks';
|
6 |
import styles from './index.less';
|
7 |
|
|
|
1 |
import { Avatar, Card, Flex, Layout, Space } from 'antd';
|
2 |
import classNames from 'classnames';
|
|
|
3 |
|
4 |
+
import { componentList } from '../constant';
|
5 |
import { useHandleDrag } from '../hooks';
|
6 |
import styles from './index.less';
|
7 |
|
web/src/pages/flow/hooks.ts
CHANGED
@@ -17,6 +17,7 @@ import React, {
|
|
17 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
18 |
import { v4 as uuidv4 } from 'uuid';
|
19 |
// import { shallow } from 'zustand/shallow';
|
|
|
20 |
import { useParams } from 'umi';
|
21 |
import useGraphStore, { RFState } from './store';
|
22 |
import { buildDslComponentsByGraph } from './utils';
|
@@ -154,11 +155,24 @@ export const useSaveGraph = () => {
|
|
154 |
return { saveGraph };
|
155 |
};
|
156 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
157 |
export const useHandleFormValuesChange = (id?: string) => {
|
158 |
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
|
159 |
const handleValuesChange = useCallback(
|
160 |
(changedValues: any, values: any) => {
|
161 |
-
console.info(changedValues, values);
|
162 |
if (id) {
|
163 |
updateNodeForm(id, values);
|
164 |
}
|
@@ -191,6 +205,8 @@ export const useFetchDataOnMount = () => {
|
|
191 |
setGraphInfo(data?.dsl?.graph ?? {});
|
192 |
}, [setGraphInfo, data?.dsl?.graph]);
|
193 |
|
|
|
|
|
194 |
useFetchFlowTemplates();
|
195 |
useFetchLlmList();
|
196 |
|
|
|
17 |
import { Node, Position, ReactFlowInstance } from 'reactflow';
|
18 |
import { v4 as uuidv4 } from 'uuid';
|
19 |
// import { shallow } from 'zustand/shallow';
|
20 |
+
import { useDebounceEffect } from 'ahooks';
|
21 |
import { useParams } from 'umi';
|
22 |
import useGraphStore, { RFState } from './store';
|
23 |
import { buildDslComponentsByGraph } from './utils';
|
|
|
155 |
return { saveGraph };
|
156 |
};
|
157 |
|
158 |
+
export const useWatchGraphChange = () => {
|
159 |
+
const nodes = useGraphStore((state) => state.nodes);
|
160 |
+
const edges = useGraphStore((state) => state.edges);
|
161 |
+
useDebounceEffect(
|
162 |
+
() => {
|
163 |
+
console.info('useDebounceEffect');
|
164 |
+
},
|
165 |
+
[nodes, edges],
|
166 |
+
{
|
167 |
+
wait: 1000,
|
168 |
+
},
|
169 |
+
);
|
170 |
+
};
|
171 |
+
|
172 |
export const useHandleFormValuesChange = (id?: string) => {
|
173 |
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
|
174 |
const handleValuesChange = useCallback(
|
175 |
(changedValues: any, values: any) => {
|
|
|
176 |
if (id) {
|
177 |
updateNodeForm(id, values);
|
178 |
}
|
|
|
205 |
setGraphInfo(data?.dsl?.graph ?? {});
|
206 |
}, [setGraphInfo, data?.dsl?.graph]);
|
207 |
|
208 |
+
useWatchGraphChange();
|
209 |
+
|
210 |
useFetchFlowTemplates();
|
211 |
useFetchLlmList();
|
212 |
|
web/src/pages/flow/mock.tsx
CHANGED
@@ -1,11 +1,5 @@
|
|
1 |
-
import { MergeCellsOutlined, RocketOutlined } from '@ant-design/icons';
|
2 |
import { Position } from 'reactflow';
|
3 |
|
4 |
-
export const componentList = [
|
5 |
-
{ name: 'Retrieval', icon: <RocketOutlined />, description: '' },
|
6 |
-
{ name: 'Generate', icon: <MergeCellsOutlined />, description: '' },
|
7 |
-
];
|
8 |
-
|
9 |
export const initialNodes = [
|
10 |
{
|
11 |
sourcePosition: Position.Left,
|
|
|
|
|
1 |
import { Position } from 'reactflow';
|
2 |
|
|
|
|
|
|
|
|
|
|
|
3 |
export const initialNodes = [
|
4 |
{
|
5 |
sourcePosition: Position.Left,
|