Web: Files: Added empty folder tree creation on DropZone upload only
This commit is contained in:
parent
515c401914
commit
10091ac5d1
@ -276,27 +276,6 @@ export function createFolder(parentFolderId, title) {
|
||||
return request(options);
|
||||
}
|
||||
|
||||
//TODO: Change to API method
|
||||
export async function createFolderPath(parentFolderId, folderPath) {
|
||||
const pathParts = folderPath.split("/").filter((p) => p !== "");
|
||||
|
||||
const folders = [];
|
||||
|
||||
let i = 0;
|
||||
let parentId = parentFolderId;
|
||||
while (i < pathParts.length) {
|
||||
let title = pathParts[i];
|
||||
|
||||
const folder = await createFolder(parentId, title);
|
||||
|
||||
folders.push(folder);
|
||||
parentId = folder.id;
|
||||
i++;
|
||||
}
|
||||
|
||||
return folders;
|
||||
}
|
||||
|
||||
export function renameFolder(folderId, title) {
|
||||
const data = { title };
|
||||
const options = {
|
||||
|
@ -34,10 +34,26 @@ export default function withFileActions(WrappedFileItem) {
|
||||
};
|
||||
|
||||
onDropZoneUpload = (files, uploadToFolder) => {
|
||||
const { t, dragging, setDragging, startUpload } = this.props;
|
||||
const {
|
||||
t,
|
||||
dragging,
|
||||
setDragging,
|
||||
startUpload,
|
||||
uploadEmptyFolders,
|
||||
} = this.props;
|
||||
|
||||
dragging && setDragging(false);
|
||||
startUpload(files, uploadToFolder, t);
|
||||
|
||||
const emptyFolders = files.filter((f) => f.isEmptyDirectory);
|
||||
|
||||
if (emptyFolders.length > 0) {
|
||||
uploadEmptyFolders(emptyFolders, uploadToFolder).then(() => {
|
||||
const onlyFiles = files.filter((f) => !f.isEmptyDirectory);
|
||||
if (onlyFiles.length > 0) startUpload(onlyFiles, uploadToFolder, t);
|
||||
});
|
||||
} else {
|
||||
startUpload(files, uploadToFolder, t);
|
||||
}
|
||||
};
|
||||
|
||||
onDrop = (items) => {
|
||||
@ -272,7 +288,7 @@ export default function withFileActions(WrappedFileItem) {
|
||||
setEnabledHotkeys,
|
||||
} = filesStore;
|
||||
|
||||
const { startUpload } = uploadDataStore;
|
||||
const { startUpload, uploadEmptyFolders } = uploadDataStore;
|
||||
const { type, extension, id } = fileActionStore;
|
||||
|
||||
const selectedItem = selection.find(
|
||||
@ -315,6 +331,7 @@ export default function withFileActions(WrappedFileItem) {
|
||||
dragging,
|
||||
setDragging,
|
||||
startUpload,
|
||||
uploadEmptyFolders,
|
||||
draggable,
|
||||
setTooltipPosition,
|
||||
setStartDrag,
|
||||
|
@ -15,7 +15,7 @@ import {
|
||||
getFileConversationProgress,
|
||||
copyToFolder,
|
||||
moveToFolder,
|
||||
createFolderPath,
|
||||
createFolder,
|
||||
fileCopyAs,
|
||||
} from "@appserver/common/api/files";
|
||||
import toastr from "studio/toastr";
|
||||
@ -480,13 +480,57 @@ class UploadDataStore {
|
||||
this.tempConversionFiles = [];
|
||||
};
|
||||
|
||||
createEmptyFolders = (emptyFolders, toFolderId) => {
|
||||
for (let i = 0; i < emptyFolders.length; i++) {
|
||||
let folder = emptyFolders[i];
|
||||
if (!folder.path || folder.path.length === 0) continue;
|
||||
convertToTree = (folders) => {
|
||||
let result = [];
|
||||
let level = { result };
|
||||
try {
|
||||
folders.forEach((folder) => {
|
||||
folder.path
|
||||
.split("/")
|
||||
.filter((name) => name !== "")
|
||||
.reduce((r, name, i, a) => {
|
||||
if (!r[name]) {
|
||||
r[name] = { result: [] };
|
||||
r.result.push({ name, children: r[name].result });
|
||||
}
|
||||
|
||||
createFolderPath(toFolderId, folder.path);
|
||||
return r[name];
|
||||
}, level);
|
||||
});
|
||||
} catch (e) {
|
||||
console.error("convertToTree", e);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
createFolderTree = async (treeList, parentFolderId) => {
|
||||
if (!treeList || !treeList.length) return;
|
||||
|
||||
for (let i = 0; i < treeList.length; i++) {
|
||||
const treeNode = treeList[i];
|
||||
|
||||
console.log(
|
||||
`createFolderTree parent id = ${parentFolderId} name '${treeNode.name}': `,
|
||||
treeNode.children
|
||||
);
|
||||
|
||||
const folder = await createFolder(parentFolderId, treeNode.name);
|
||||
const parentId = folder.id;
|
||||
|
||||
if (treeNode.children.length == 0) continue;
|
||||
|
||||
await this.createFolderTree(treeNode.children, parentId);
|
||||
}
|
||||
};
|
||||
|
||||
createEmptyFolders = async (emptyFolders, toFolderId) => {
|
||||
const tree = this.convertToTree(emptyFolders);
|
||||
await this.createFolderTree(tree, toFolderId);
|
||||
};
|
||||
|
||||
uploadEmptyFolders = async (emptyFolders, folderId) => {
|
||||
const toFolderId = folderId ? folderId : this.selectedFolderStore.id;
|
||||
await this.createEmptyFolders(emptyFolders, toFolderId);
|
||||
};
|
||||
|
||||
startUpload = (uploadFiles, folderId, t) => {
|
||||
@ -494,12 +538,6 @@ class UploadDataStore {
|
||||
|
||||
const toFolderId = folderId ? folderId : this.selectedFolderStore.id;
|
||||
|
||||
const emptyFolders = uploadFiles.filter((f) => f.isEmptyDirectory);
|
||||
|
||||
if (emptyFolders.length > 0) {
|
||||
this.createEmptyFolders(emptyFolders, toFolderId);
|
||||
}
|
||||
|
||||
if (this.uploaded) {
|
||||
this.files = this.files.filter((f) => f.action !== "upload");
|
||||
this.filesSize = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user