🐛 fix(tabsContext.tsx): add missing import statement for addVersionToDuplicates function
✨ feat(tabsContext.tsx): add version number to duplicate flow names to ensure uniqueness 🐛 fix(reactflowUtils.ts): add missing newline at end of file
This commit is contained in:
parent
492371b185
commit
f4793940b0
2 changed files with 18 additions and 1 deletions
|
|
@ -20,7 +20,7 @@ import {
|
|||
import { APIClassType, APITemplateType } from "../types/api";
|
||||
import { FlowType, NodeType } from "../types/flow";
|
||||
import { TabsContextType, TabsState } from "../types/tabs";
|
||||
import { updateIds, updateTemplate } from "../utils/reactflowUtils";
|
||||
import { addVersionToDuplicates, updateIds, updateTemplate } from "../utils/reactflowUtils";
|
||||
import { getRandomDescription, getRandomName } from "../utils/utils";
|
||||
import { alertContext } from "./alertContext";
|
||||
import { typesContext } from "./typesContext";
|
||||
|
|
@ -448,6 +448,10 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
|||
processFlowEdges(newFlow);
|
||||
processFlowNodes(newFlow);
|
||||
|
||||
const flowName = addVersionToDuplicates(newFlow, flows);
|
||||
|
||||
newFlow.name = flowName;
|
||||
|
||||
try {
|
||||
const { id } = await saveFlowToDatabase(newFlow);
|
||||
// Change the id to the new id.
|
||||
|
|
|
|||
|
|
@ -219,3 +219,16 @@ export function validateNodes(reactFlowInstance: ReactFlowInstance) {
|
|||
.getNodes()
|
||||
.flatMap((n: NodeType) => validateNode(n, reactFlowInstance));
|
||||
}
|
||||
|
||||
export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) {
|
||||
const existingNames = flows.map((item) => item.name);
|
||||
let newName = flow.name;
|
||||
let count = 1;
|
||||
|
||||
while (existingNames.includes(newName)) {
|
||||
newName = `${flow.name} (${count})`;
|
||||
count++;
|
||||
}
|
||||
|
||||
return newName;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue