Skip to content

Commit

Permalink
fix: ts error
Browse files Browse the repository at this point in the history
  • Loading branch information
everbrez committed Jan 13, 2024
1 parent a1005c7 commit 8a4b422
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 51 deletions.
36 changes: 8 additions & 28 deletions packages/flow/src/Diagrams/Panels/FlowDiagram/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ import ReactFlow, {
} from 'reactflow';
import { OPERATOR_TYPE_DATA } from '../OperatorPanel';
import { OperatorMap, getOperatorFromNode } from '../../Operators';
import { useDiagramsContext } from '../../State/DiagramsProvider';
import {
useDiagramsContext,
useDiagramsHookOption,
} from '../../State/DiagramsProvider';
import { nodeTypes } from '../../Nodes';
import { isSameSourceHandle, isSameTargetHandle } from '../../utils';
import css from './FlowDiagram.module.less';
import { useLatest } from 'ahooks';
import { BackToLayer } from '../LayerPanel/BackToLayer';

const nodeColor = (node: Node) => {
Expand Down Expand Up @@ -59,25 +61,8 @@ const getLayoutedElements = (nodes: Node[], edges: Edge[]) => {
};

export const FlowDiagram: React.FC = () => {
const {
nodes,
edges,
setNodes,
setEdges,
updateEdge,
updateNode,
setActiveLayerId,
setLayer,
layer,
activeLayerId,
} = useDiagramsContext();

const latestState = useLatest({
nodes,
edges,
layer,
activeLayerId,
});
const { nodes, edges, setNodes, setEdges } = useDiagramsContext();
const { actionsRef, currentStateRef } = useDiagramsHookOption();

const addSelectedEdges = useStore((ctx) => ctx.addSelectedEdges);

Expand Down Expand Up @@ -182,13 +167,8 @@ export const FlowDiagram: React.FC = () => {

operator?.onAfterCreate?.({
node: node as typeof operatorInstance,
currentState: latestState.current,
actions: {
updateEdge,
updateNode,
setActiveLayerId,
setLayer,
},
currentState: currentStateRef.current,
actions: actionsRef.current,
});
});
}
Expand Down
31 changes: 8 additions & 23 deletions packages/flow/src/Diagrams/Panels/LayerPanel/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
import classnames from 'classnames';
import { useDiagramsContext } from '../../State/DiagramsProvider';
import {
useDiagramsContext,
useDiagramsHookOption,
} from '../../State/DiagramsProvider';
import { Button, Input, Modal } from 'antd';
import { type Layer } from '../../State/Layer';
import { getOperatorFromOperatorType } from '../../Operators';
import css from './LayerPanel.module.less';

export function LayerPanel() {
const {
layer,
activeLayerId,
setActiveLayerId,
setLayer,
nodes,
edges,
updateEdge,
updateNode,
} = useDiagramsContext();
const { layer, activeLayerId, setActiveLayerId } = useDiagramsContext();
const { currentStateRef, actionsRef } = useDiagramsHookOption();

function renderLayers(layers: Layer[], index: number = 0) {
return (
Expand Down Expand Up @@ -74,18 +69,8 @@ export function LayerPanel() {
// add nodes
customOperator.onAfterCreate({
node: newNode,
currentState: {
layer,
activeLayerId,
nodes,
edges,
},
actions: {
setActiveLayerId,
setLayer,
updateEdge,
updateNode,
},
currentState: currentStateRef.current,
actions: actionsRef.current,
});
}
},
Expand Down

0 comments on commit 8a4b422

Please sign in to comment.