### What problem does this PR solve? feat: Build the positions of the Switch handle #1739 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { DSLComponents } from '@/interfaces/database/flow';
|
||||
import { removeUselessFieldsFromValues } from '@/utils/form';
|
||||
import { humanId } from 'human-id';
|
||||
import { curry, sample } from 'lodash';
|
||||
import { curry, intersectionWith, isEqual, sample } from 'lodash';
|
||||
import pipe from 'lodash/fp/pipe';
|
||||
import isObject from 'lodash/isObject';
|
||||
import { Edge, Node, Position } from 'reactflow';
|
||||
@@ -172,10 +172,24 @@ export const isEdgeEqual = (previous: Edge, current: Edge) =>
|
||||
previous.sourceHandle === current.sourceHandle;
|
||||
|
||||
export const buildNewPositionMap = (
|
||||
categoryDataKeys: string[],
|
||||
indexesInUse: number[],
|
||||
currentKeys: string[],
|
||||
previousPositionMap: Record<string, IPosition>,
|
||||
) => {
|
||||
return categoryDataKeys.reduce<Record<string, IPosition>>((pre, cur) => {
|
||||
// index in use
|
||||
const indexesInUse = Object.values(previousPositionMap).map((x) => x.idx);
|
||||
const previousKeys = Object.keys(previousPositionMap);
|
||||
const intersectionKeys = intersectionWith(
|
||||
previousKeys,
|
||||
currentKeys,
|
||||
(categoryDataKey, positionMapKey) => categoryDataKey === positionMapKey,
|
||||
);
|
||||
// difference set
|
||||
const currentDifferenceKeys = currentKeys.filter(
|
||||
(x) => !intersectionKeys.some((y) => y === x),
|
||||
);
|
||||
const newPositionMap = currentDifferenceKeys.reduce<
|
||||
Record<string, IPosition>
|
||||
>((pre, cur) => {
|
||||
// take a coordinate
|
||||
const effectiveIdxes = CategorizeAnchorPointPositions.map(
|
||||
(x, idx) => idx,
|
||||
@@ -188,4 +202,10 @@ export const buildNewPositionMap = (
|
||||
|
||||
return pre;
|
||||
}, {});
|
||||
|
||||
return { intersectionKeys, newPositionMap };
|
||||
};
|
||||
|
||||
export const isKeysEqual = (currentKeys: string[], previousKeys: string[]) => {
|
||||
return isEqual(currentKeys.sort(), previousKeys.sort());
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user