feat: add FlowChatBox #918 (#1086)

### What problem does this PR solve?

feat: add FlowChatBox #918 

### Type of change

- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2024-06-06 19:29:36 +08:00
committed by GitHub
parent 6399a4fde2
commit dbdae8e83c
10 changed files with 547 additions and 14 deletions

View File

@ -16,6 +16,7 @@ import {
} from 'reactflow';
import { create } from 'zustand';
import { devtools } from 'zustand/middleware';
import { Operator } from './constant';
import { NodeData } from './interface';
export type RFState = {
@ -33,10 +34,11 @@ export type RFState = {
addNode: (nodes: Node) => void;
deleteEdge: () => void;
deleteEdgeById: (id: string) => void;
findNodeByName: (operatorName: Operator) => Node | undefined;
};
// this is our useStore hook that we can use in our components to get parts of the store and call actions
const useStore = create<RFState>()(
const useGraphStore = create<RFState>()(
devtools((set, get) => ({
nodes: [] as Node[],
edges: [] as Edge[],
@ -86,6 +88,9 @@ const useStore = create<RFState>()(
edges: edges.filter((edge) => edge.id !== id),
});
},
findNodeByName: (name: Operator) => {
return get().nodes.find((x) => x.data.label === name);
},
updateNodeForm: (nodeId: string, values: any) => {
set({
nodes: get().nodes.map((node) => {
@ -100,4 +105,4 @@ const useStore = create<RFState>()(
})),
);
export default useStore;
export default useGraphStore;