fix: The name of the copy operator is displayed the same as before ##3265 (#3266)
### What problem does this PR solve? fix: The name of the copy operator is displayed the same as before ##3265 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@@ -184,11 +184,12 @@ export const buildNewPositionMap = (
|
||||
const intersectionKeys = intersectionWith(
|
||||
previousKeys,
|
||||
currentKeys,
|
||||
(categoryDataKey, positionMapKey) => categoryDataKey === positionMapKey,
|
||||
(categoryDataKey: string, positionMapKey: string) =>
|
||||
categoryDataKey === positionMapKey,
|
||||
);
|
||||
// difference set
|
||||
const currentDifferenceKeys = currentKeys.filter(
|
||||
(x) => !intersectionKeys.some((y) => y === x),
|
||||
(x) => !intersectionKeys.some((y: string) => y === x),
|
||||
);
|
||||
const newPositionMap = currentDifferenceKeys.reduce<
|
||||
Record<string, IPosition>
|
||||
@@ -240,3 +241,51 @@ export const generateSwitchHandleText = (idx: number) => {
|
||||
export const getNodeDragHandle = (nodeType?: string) => {
|
||||
return nodeType === Operator.Note ? '.note-drag-handle' : undefined;
|
||||
};
|
||||
|
||||
const splitName = (name: string) => {
|
||||
const names = name.split('_');
|
||||
const type = names.at(0);
|
||||
const index = Number(names.at(-1));
|
||||
|
||||
return { type, index };
|
||||
};
|
||||
|
||||
export const generateNodeNamesWithIncreasingIndex = (
|
||||
name: string,
|
||||
nodes: Node[],
|
||||
) => {
|
||||
const templateNameList = nodes
|
||||
.filter((x) => {
|
||||
const temporaryName = x.data.name;
|
||||
|
||||
const { type, index } = splitName(temporaryName);
|
||||
|
||||
return (
|
||||
temporaryName.match(/_/g)?.length === 1 &&
|
||||
type === name &&
|
||||
!isNaN(index)
|
||||
);
|
||||
})
|
||||
.map((x) => {
|
||||
const temporaryName = x.data.name;
|
||||
const { index } = splitName(temporaryName);
|
||||
|
||||
return {
|
||||
idx: index,
|
||||
name: temporaryName,
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.idx - b.idx);
|
||||
|
||||
let index: number = 0;
|
||||
for (let i = 0; i < templateNameList.length; i++) {
|
||||
const idx = templateNameList[i]?.idx;
|
||||
const nextIdx = templateNameList[i + 1]?.idx;
|
||||
if (idx + 1 !== nextIdx) {
|
||||
index = idx + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return `${name}_${index}`;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user