tidy(ui): tidy connection validation functions and logic

This commit is contained in:
psychedelicious
2024-05-18 17:22:29 +10:00
parent af7b194bec
commit 6658897210
9 changed files with 396 additions and 370 deletions

View File

@ -8,7 +8,7 @@ import {
$templates,
connectionMade,
} from 'features/nodes/store/nodesSlice';
import { getFirstValidConnection } from 'features/nodes/store/util/findConnectionToValidHandle';
import { getFirstValidConnection } from 'features/nodes/store/util/connectionValidation';
import { isInvocationNode } from 'features/nodes/types/invocation';
import { useCallback, useMemo } from 'react';
import type { OnConnect, OnConnectEnd, OnConnectStart } from 'reactflow';

View File

@ -2,7 +2,7 @@ import { useStore } from '@nanostores/react';
import { createSelector } from '@reduxjs/toolkit';
import { useAppSelector } from 'app/store/storeHooks';
import { $pendingConnection, $templates, selectNodesSlice } from 'features/nodes/store/nodesSlice';
import { makeConnectionErrorSelector } from 'features/nodes/store/util/makeIsConnectionValidSelector';
import { makeConnectionErrorSelector } from 'features/nodes/store/util/connectionValidation.js';
import { useMemo } from 'react';
import { useFieldType } from './useFieldType.ts';

View File

@ -2,9 +2,12 @@
import { useStore } from '@nanostores/react';
import { useAppSelector, useAppStore } from 'app/store/storeHooks';
import { $templates } from 'features/nodes/store/nodesSlice';
import { getIsGraphAcyclic } from 'features/nodes/store/util/getIsGraphAcyclic';
import { getCollectItemType } from 'features/nodes/store/util/makeIsConnectionValidSelector';
import { areTypesEqual, validateSourceAndTargetTypes } from 'features/nodes/store/util/validateSourceAndTargetTypes';
import {
areTypesEqual,
getCollectItemType,
getHasCycles,
validateSourceAndTargetTypes,
} from 'features/nodes/store/util/connectionValidation';
import type { InvocationNodeData } from 'features/nodes/types/invocation';
import { useCallback } from 'react';
import type { Connection, Node } from 'reactflow';
@ -90,7 +93,7 @@ export const useIsValidConnection = () => {
}
// Graphs much be acyclic (no loops!)
return getIsGraphAcyclic(source, target, nodes, edges);
return !getHasCycles(source, target, nodes, edges);
},
[shouldValidateGraph, templates, store]
);