chore(store): add current connection result closes #2916
This commit is contained in:
@@ -21,7 +21,8 @@
|
|||||||
"react": "^18.2.0",
|
"react": "^18.2.0",
|
||||||
"react-dom": "^18.2.0",
|
"react-dom": "^18.2.0",
|
||||||
"react-router-dom": "^6.3.0",
|
"react-router-dom": "^6.3.0",
|
||||||
"reactflow": "workspace:*"
|
"reactflow": "workspace:*",
|
||||||
|
"zustand": "^4.3.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cypress/skip-test": "^2.6.1",
|
"@cypress/skip-test": "^2.6.1",
|
||||||
|
|||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import { ReactFlowState, useStore } from 'reactflow';
|
||||||
|
import { shallow } from 'zustand/shallow';
|
||||||
|
|
||||||
|
import styles from './validation.module.css';
|
||||||
|
|
||||||
|
const selector = (state: ReactFlowState) => ({
|
||||||
|
connectionPosition: state.connectionPosition,
|
||||||
|
connectionStatus: state.connectionStatus,
|
||||||
|
connectionNodeId: state.connectionNodeId,
|
||||||
|
connectionTargetNodeId: state.connectionTargetNodeId,
|
||||||
|
});
|
||||||
|
|
||||||
|
function ConnectionStatus() {
|
||||||
|
const { connectionPosition, connectionStatus, connectionNodeId, connectionTargetNodeId } = useStore(
|
||||||
|
selector,
|
||||||
|
shallow
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!connectionPosition) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={styles.connectionstatus}>
|
||||||
|
{connectionNodeId ? (
|
||||||
|
<>
|
||||||
|
<div>
|
||||||
|
<strong>connection info</strong>
|
||||||
|
</div>
|
||||||
|
<div>position: {JSON.stringify(connectionPosition)}</div>
|
||||||
|
<div>status: {JSON.stringify(connectionStatus)}</div>
|
||||||
|
<div>source node id: {JSON.stringify(connectionNodeId)}</div>
|
||||||
|
<div>target node id: {JSON.stringify(connectionTargetNodeId)}</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
'no connection data'
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ConnectionStatus;
|
||||||
@@ -16,6 +16,8 @@ import ReactFlow, {
|
|||||||
Edge,
|
Edge,
|
||||||
} from 'reactflow';
|
} from 'reactflow';
|
||||||
|
|
||||||
|
import ConnectionStatus from './ConnectionStatus';
|
||||||
|
|
||||||
import styles from './validation.module.css';
|
import styles from './validation.module.css';
|
||||||
|
|
||||||
const initialNodes: Node[] = [
|
const initialNodes: Node[] = [
|
||||||
@@ -96,7 +98,9 @@ const ValidationFlow = () => {
|
|||||||
onEdgeUpdate={onEdgeUpdate}
|
onEdgeUpdate={onEdgeUpdate}
|
||||||
isValidConnection={isValidConnection}
|
isValidConnection={isValidConnection}
|
||||||
fitView
|
fitView
|
||||||
/>
|
>
|
||||||
|
<ConnectionStatus />
|
||||||
|
</ReactFlow>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -39,3 +39,10 @@
|
|||||||
.validationflow :global .invalid .react-flow__connection-path {
|
.validationflow :global .invalid .react-flow__connection-path {
|
||||||
stroke: #ff6060;
|
stroke: #ff6060;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.connectionstatus {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 20px;
|
||||||
|
left: 50%;
|
||||||
|
transform: translateX(-50%);
|
||||||
|
}
|
||||||
|
|||||||
@@ -93,6 +93,8 @@ export function handlePointerDown({
|
|||||||
connectionHandleId: handleId,
|
connectionHandleId: handleId,
|
||||||
connectionHandleType: handleType,
|
connectionHandleType: handleType,
|
||||||
connectionStatus: null,
|
connectionStatus: null,
|
||||||
|
connectionTargetNodeId: null,
|
||||||
|
connectionTargetHandeId: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
onConnectStart?.(event, { nodeId, handleId, handleType });
|
onConnectStart?.(event, { nodeId, handleId, handleType });
|
||||||
@@ -139,6 +141,8 @@ export function handlePointerDown({
|
|||||||
)
|
)
|
||||||
: connectionPosition,
|
: connectionPosition,
|
||||||
connectionStatus: getConnectionStatus(!!prevClosestHandle, isValid),
|
connectionStatus: getConnectionStatus(!!prevClosestHandle, isValid),
|
||||||
|
connectionTargetNodeId: connection.target,
|
||||||
|
connectionTargetHandleId: connection.targetHandle,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!prevClosestHandle && !isValid && !handleDomNode) {
|
if (!prevClosestHandle && !isValid && !handleDomNode) {
|
||||||
|
|||||||
@@ -275,6 +275,8 @@ const createRFStore = () =>
|
|||||||
connectionHandleId: initialState.connectionHandleId,
|
connectionHandleId: initialState.connectionHandleId,
|
||||||
connectionHandleType: initialState.connectionHandleType,
|
connectionHandleType: initialState.connectionHandleType,
|
||||||
connectionStatus: initialState.connectionStatus,
|
connectionStatus: initialState.connectionStatus,
|
||||||
|
connectionTargetNodeId: initialState.connectionTargetNodeId,
|
||||||
|
connectionTargetHandleId: initialState.connectionTargetHandleId,
|
||||||
}),
|
}),
|
||||||
reset: () => set({ ...initialState }),
|
reset: () => set({ ...initialState }),
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ const initialState: ReactFlowStore = {
|
|||||||
connectionNodeId: null,
|
connectionNodeId: null,
|
||||||
connectionHandleId: null,
|
connectionHandleId: null,
|
||||||
connectionHandleType: 'source',
|
connectionHandleType: 'source',
|
||||||
|
connectionTargetNodeId: null,
|
||||||
|
connectionTargetHandleId: null,
|
||||||
connectionPosition: { x: 0, y: 0 },
|
connectionPosition: { x: 0, y: 0 },
|
||||||
connectionStatus: null,
|
connectionStatus: null,
|
||||||
connectionMode: ConnectionMode.Strict,
|
connectionMode: ConnectionMode.Strict,
|
||||||
|
|||||||
@@ -169,6 +169,8 @@ export type ReactFlowStore = {
|
|||||||
|
|
||||||
connectionNodeId: string | null;
|
connectionNodeId: string | null;
|
||||||
connectionHandleId: string | null;
|
connectionHandleId: string | null;
|
||||||
|
connectionTargetNodeId: string | null;
|
||||||
|
connectionTargetHandleId: string | null;
|
||||||
connectionHandleType: HandleType | null;
|
connectionHandleType: HandleType | null;
|
||||||
connectionPosition: XYPosition;
|
connectionPosition: XYPosition;
|
||||||
connectionStatus: ConnectionStatus | null;
|
connectionStatus: ConnectionStatus | null;
|
||||||
|
|||||||
Generated
+2
@@ -74,6 +74,7 @@ importers:
|
|||||||
start-server-and-test: ^1.14.0
|
start-server-and-test: ^1.14.0
|
||||||
typescript: ^4.9.4
|
typescript: ^4.9.4
|
||||||
vite: ^4.0.4
|
vite: ^4.0.4
|
||||||
|
zustand: ^4.3.1
|
||||||
dependencies:
|
dependencies:
|
||||||
'@reactflow/node-resizer': link:../../packages/node-resizer
|
'@reactflow/node-resizer': link:../../packages/node-resizer
|
||||||
classcat: registry.npmjs.org/classcat/5.0.4
|
classcat: registry.npmjs.org/classcat/5.0.4
|
||||||
@@ -83,6 +84,7 @@ importers:
|
|||||||
react-dom: registry.npmjs.org/react-dom/18.2.0_react@18.2.0
|
react-dom: registry.npmjs.org/react-dom/18.2.0_react@18.2.0
|
||||||
react-router-dom: registry.npmjs.org/react-router-dom/6.3.0_biqbaboplfbrettd7655fr4n2y
|
react-router-dom: registry.npmjs.org/react-router-dom/6.3.0_biqbaboplfbrettd7655fr4n2y
|
||||||
reactflow: link:../../packages/reactflow
|
reactflow: link:../../packages/reactflow
|
||||||
|
zustand: registry.npmjs.org/zustand/4.3.1_react@18.2.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@cypress/skip-test': registry.npmjs.org/@cypress/skip-test/2.6.1
|
'@cypress/skip-test': registry.npmjs.org/@cypress/skip-test/2.6.1
|
||||||
'@types/dagre': registry.npmjs.org/@types/dagre/0.7.48
|
'@types/dagre': registry.npmjs.org/@types/dagre/0.7.48
|
||||||
|
|||||||
Reference in New Issue
Block a user