fix: add support for upload flows to a folder (#2844)

* ✨ (flows.py): Add support for uploading flows to a specific folder by adding a folder_id parameter to the upload_file function and updating the flow object with the folder_id if provided
📝 (use-on-file-drop.tsx): Update import statements to include the new uploadFlowToFolder function and replace the usage of uploadFlowsFromFolders with uploadFlowToFolder
🔧 (use-drag-and-drop.tsx): Refactor the useDragAndDrop hook to remove unnecessary code related to file handling
⬆️ (index.ts): Add a new function uploadFlowToFolder to handle uploading flows to a specific folder in the MainPage services module

* ♻️ (flows.py): remove trailing whitespace to maintain code cleanliness and consistency
This commit is contained in:
Cristhian Zanforlin Lousa 2024-07-22 09:39:53 -03:00 • committed by GitHub
commit 41143b1e58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 17 deletions

View file

@ -3,7 +3,10 @@ import {
WRONG_FILE_ERROR_ALERT,
} from "../../../constants/alerts_constants";
import { updateFlowInDatabase } from "../../../controllers/API";
import { uploadFlowsFromFolders } from "../../../pages/MainPage/services";
import {
uploadFlowToFolder,
uploadFlowsFromFolders,
} from "../../../pages/MainPage/services";
import useAlertStore from "../../../stores/alertStore";
import useFlowsManagerStore from "../../../stores/flowsManagerStore";
import { useFolderStore } from "../../../stores/foldersStore";
@ -131,7 +134,8 @@ const useFileDrop = (
formData.append("file", data);
setFolderDragging(false);
setFolderIdDragging("");
uploadFlowsFromFolders(formData).then(() => {
uploadFlowToFolder(formData, folderId).then(() => {
refreshFolders();
triggerFolderChange(folderId);
});

View file

@ -1,17 +1,4 @@
import ShortUniqueId from "short-unique-id";
import {
ALLOWED_IMAGE_INPUT_EXTENSIONS,
FS_ERROR_TEXT,
SN_ERROR_TEXT,
} from "../../../../../../constants/constants";
// import useFileUpload from "./use-file-upload";
const useDragAndDrop = (
setIsDragging: (value: boolean) => void,
setFiles: (value: any) => void,
currentFlowId: string,
setErrorData: (value: any) => void,
) => {
const useDragAndDrop = (setIsDragging: (value: boolean) => void) => {
const dragOver = (e) => {
e.preventDefault();
if (e.dataTransfer.types.some((type) => type === "Files")) {

View file

@ -110,3 +110,22 @@ export async function moveFlowToFolder(
throw error;
}
}
export async function uploadFlowToFolder(
flows: FormData,
folderId: string,
): Promise<FlowType[]> {
try {
const url = `${BASE_URL_API}flows/upload/?folder_id=${encodeURIComponent(folderId)}`;
const response = await api.post(url, flows);
if (response?.status !== 201) {
throw new Error(`HTTP error! status: ${response?.status}`);
}
return response.data;
} catch (error) {
console.error(error);
throw error;
}
}