diff --git a/frontend/src/atoms/pipelineAtom.js b/frontend/src/atoms/pipelineAtom.js index e567b2be..19274bc7 100644 --- a/frontend/src/atoms/pipelineAtom.js +++ b/frontend/src/atoms/pipelineAtom.js @@ -1,8 +1,8 @@ import { atom } from "jotai"; import { withImmer } from "jotai-immer"; -import { customAlphabet } from "nanoid"; import rfdc from "rfdc"; import { sha1 } from "js-sha1"; +import { generateId } from "@/utils/blockUtils"; export const pipelineKey = (id, data) => { let hash = ""; @@ -13,9 +13,7 @@ export const pipelineKey = (id, data) => { }; export const pipelineFactory = (cachePath, pipeline = null) => { - const nanoid = customAlphabet("1234567890abcedfghijklmnopqrstuvwxyz", 12); - const newNanoid = nanoid(); - const id = `pipeline-${newNanoid}`; + const id = generateId("pipeline"); const buffer = `${cachePath}${id}`; let defaultPipeline = { id: id, diff --git a/frontend/src/components/ui/DrawflowWrapper.jsx b/frontend/src/components/ui/DrawflowWrapper.jsx index 41d8cd01..0cba60ef 100644 --- a/frontend/src/components/ui/DrawflowWrapper.jsx +++ b/frontend/src/components/ui/DrawflowWrapper.jsx @@ -168,7 +168,7 @@ export default function DrawflowWrapper() { }, [renderNodes]); const addBlockToPipeline = (block) => { - const id = generateId(block); + const id = generateId(block.information.id); block = replaceIds(block, id); setPipeline((draft) => { draft.data[id] = block; @@ -202,6 +202,8 @@ export default function DrawflowWrapper() { const dropPipeline = (pipelineData) => { const pipelineJson = JSON.parse(pipelineData); const { specs, path } = pipelineJson; + const newId = generateId(pipeline.id); + specs.id = newId; loadPipeline(specs, path); }; diff --git a/frontend/src/utils/blockUtils.js b/frontend/src/utils/blockUtils.js index eb654ac7..46472de9 100644 --- a/frontend/src/utils/blockUtils.js +++ b/frontend/src/utils/blockUtils.js @@ -26,11 +26,18 @@ export const genJSON = (block, id) => { }; }; -export function generateId(block) { - const nanoid = customAlphabet("1234567890abcedfghijklmnopqrstuvwxyz", 12); +export function generateId(prefix) { + const nanoid = customAlphabet("abcdefghijklmnopqrstuvwxyz0123456789", 12); + const newNanoid = nanoid(); - const id = `${block.information.id}-${newNanoid}`; - return id; + + if (prefix) { + const [basePrefix] = prefix.split("-"); + const finalPrefix = basePrefix === "pipeline" ? basePrefix : prefix; + return `${finalPrefix}-${newNanoid}`; + } + + return `pipeline-${newNanoid}`; } export function replaceIds(block, id) {