Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Added generatePipelineId function to blockUtils and updated Drawflow… #195

Merged
merged 5 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions frontend/src/atoms/pipelineAtom.js
Original file line number Diff line number Diff line change
@@ -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 = "";
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/components/ui/DrawflowWrapper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};

Expand Down
15 changes: 11 additions & 4 deletions frontend/src/utils/blockUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading