Skip to content

Commit

Permalink
feat: watch graph change (#1092)
Browse files Browse the repository at this point in the history
### What problem does this PR solve?

feat: watch graph change #918 

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
  • Loading branch information
cike8899 authored Jun 7, 2024
1 parent f8d0d65 commit 31da511
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
3 changes: 3 additions & 0 deletions web/src/pages/flow/canvas/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ function FlowCanvas({ sideWidth }: IProps) {
onKeyUp={handleKeyUp}
onSelectionChange={onSelectionChange}
nodeOrigin={[0.5, 0]}
onChange={(...params) => {
console.info('params:', ...params);
}}
defaultEdgeOptions={{
type: 'buttonEdge',
markerEnd: {
Expand Down
Empty file.
12 changes: 12 additions & 0 deletions web/src/pages/flow/constant.ts → web/src/pages/flow/constant.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import {
MergeCellsOutlined,
RocketOutlined,
SendOutlined,
} from '@ant-design/icons';

export enum Operator {
Begin = 'Begin',
Retrieval = 'Retrieval',
Generate = 'Generate',
Answer = 'Answer',
}

export const componentList = [
{ name: Operator.Retrieval, icon: <RocketOutlined />, description: '' },
{ name: Operator.Generate, icon: <MergeCellsOutlined />, description: '' },
{ name: Operator.Answer, icon: <SendOutlined />, description: '' },
];

export const initialRetrievalValues = {
similarity_threshold: 0.2,
keywords_similarity_weight: 0.3,
Expand Down
2 changes: 1 addition & 1 deletion web/src/pages/flow/flow-sider/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Avatar, Card, Flex, Layout, Space } from 'antd';
import classNames from 'classnames';
import { componentList } from '../mock';

import { componentList } from '../constant';
import { useHandleDrag } from '../hooks';
import styles from './index.less';

Expand Down
18 changes: 17 additions & 1 deletion web/src/pages/flow/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import React, {
import { Node, Position, ReactFlowInstance } from 'reactflow';
import { v4 as uuidv4 } from 'uuid';
// import { shallow } from 'zustand/shallow';
import { useDebounceEffect } from 'ahooks';
import { useParams } from 'umi';
import useGraphStore, { RFState } from './store';
import { buildDslComponentsByGraph } from './utils';
Expand Down Expand Up @@ -154,11 +155,24 @@ export const useSaveGraph = () => {
return { saveGraph };
};

export const useWatchGraphChange = () => {
const nodes = useGraphStore((state) => state.nodes);
const edges = useGraphStore((state) => state.edges);
useDebounceEffect(
() => {
console.info('useDebounceEffect');
},
[nodes, edges],
{
wait: 1000,
},
);
};

export const useHandleFormValuesChange = (id?: string) => {
const updateNodeForm = useGraphStore((state) => state.updateNodeForm);
const handleValuesChange = useCallback(
(changedValues: any, values: any) => {
console.info(changedValues, values);
if (id) {
updateNodeForm(id, values);
}
Expand Down Expand Up @@ -191,6 +205,8 @@ export const useFetchDataOnMount = () => {
setGraphInfo(data?.dsl?.graph ?? {});
}, [setGraphInfo, data?.dsl?.graph]);

useWatchGraphChange();

useFetchFlowTemplates();
useFetchLlmList();

Expand Down
6 changes: 0 additions & 6 deletions web/src/pages/flow/mock.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
import { MergeCellsOutlined, RocketOutlined } from '@ant-design/icons';
import { Position } from 'reactflow';

export const componentList = [
{ name: 'Retrieval', icon: <RocketOutlined />, description: '' },
{ name: 'Generate', icon: <MergeCellsOutlined />, description: '' },
];

export const initialNodes = [
{
sourcePosition: Position.Left,
Expand Down

0 comments on commit 31da511

Please sign in to comment.