🐛 Fix bug unable to recreate document or folder
This commit is contained in:
@@ -263,3 +263,16 @@ export const getFilesTree = (
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const getFileIdsInTree = (tree: FileTreeObject['tree']): string[] => {
|
||||
const fileIds: string[] = [];
|
||||
for (const directory of Object.keys(tree)) {
|
||||
if (tree[directory].root) {
|
||||
fileIds.push(tree[directory].root as string);
|
||||
} else {
|
||||
getFileIdsInTree(tree[directory] as FileTreeObject['tree']);
|
||||
}
|
||||
}
|
||||
|
||||
return fileIds;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { FileTreeObject } from '@components/uploads/file-tree-utils';
|
||||
import { FileTreeObject, getFileIdsInTree } from '@components/uploads/file-tree-utils';
|
||||
import FileUploadService from '@features/files/services/file-upload-service';
|
||||
import { ToasterService } from '@features/global/services/toaster-service';
|
||||
import { DriveApiClient } from '../api-client/api-client';
|
||||
@@ -16,6 +16,7 @@ export const useDriveUpload = () => {
|
||||
|
||||
const uploadVersion = async (file: File, context: { companyId: string; id: string }) => {
|
||||
return new Promise(r => {
|
||||
FileUploadService.resetStates([file.name]);
|
||||
FileUploadService.upload([{ root: file.name, file }], {
|
||||
context: {
|
||||
companyId: context.companyId,
|
||||
@@ -49,6 +50,7 @@ export const useDriveUpload = () => {
|
||||
context: { companyId: string; parentId: string },
|
||||
) => {
|
||||
logger.debug('Start creating directories and file upload ...');
|
||||
FileUploadService.resetStates(getFileIdsInTree(tree.tree));
|
||||
await FileUploadService.createDirectories(tree, context);
|
||||
await refresh(context.parentId, true);
|
||||
};
|
||||
@@ -68,6 +70,7 @@ export const useDriveUpload = () => {
|
||||
`Unexpected response status code: ${request.status} from ${JSON.stringify(url)}`,
|
||||
);
|
||||
const file = new File([request.response], name);
|
||||
FileUploadService.resetStates([file.name]);
|
||||
FileUploadService.upload([{ root: file.name, file }], {
|
||||
context: {
|
||||
companyId: context.companyId,
|
||||
|
||||
@@ -27,8 +27,9 @@ export const useUploadZones = (zoneId: string) => {
|
||||
list: File[],
|
||||
options?: { uploader?: (file: File, context: any) => Promise<FileType>; context?: any },
|
||||
) => {
|
||||
FileUploadService.resetStates(list.map((file) => file.name));
|
||||
const newFiles = await FileUploadService.upload(
|
||||
list.map((file, index) => {
|
||||
list.map((file) => {
|
||||
return {
|
||||
root: file.name,
|
||||
file,
|
||||
|
||||
@@ -12,8 +12,6 @@ import FileUploadAPIClient from '../api/file-upload-api-client';
|
||||
import { isPendingFileStatusPending } from '../utils/pending-files';
|
||||
import { FileTreeObject } from 'components/uploads/file-tree-utils';
|
||||
import { DriveApiClient } from 'features/drive/api-client/api-client';
|
||||
import { ToasterService } from 'app/features/global/services/toaster-service';
|
||||
import Languages from 'app/features/global/services/languages-service';
|
||||
import { DriveItem, DriveItemVersion } from 'app/features/drive/types';
|
||||
|
||||
export enum Events {
|
||||
@@ -63,6 +61,9 @@ class FileUploadService {
|
||||
* @private
|
||||
*/
|
||||
async _waitWhilePaused(id?: string) {
|
||||
logger.debug('===== _waitWhilePaused ======');
|
||||
logger.debug('rootStates: ', this.rootStates);
|
||||
logger.debug('status: ', this.uploadStatus)
|
||||
while (this.uploadStatus === UploadStateEnum.Paused || (id && this.rootStates.paused[id])) {
|
||||
if (this.uploadStatus === UploadStateEnum.Cancelled || (id && this.rootStates.cancelled[id]))
|
||||
return;
|
||||
@@ -305,10 +306,14 @@ class FileUploadService {
|
||||
callback?: (file: { root: string; file: FileType | null }, context: any) => void;
|
||||
},
|
||||
): Promise<PendingFileType[]> {
|
||||
logger.debug('===== upload =====');
|
||||
logger.debug('uploadStatus: ', this.uploadStatus);
|
||||
|
||||
// reset the upload status when creating a new document
|
||||
if (fileList.length === 1 && fileList[0].root === fileList[0].file.name) {
|
||||
this.pauseOrResume();
|
||||
if (this.uploadStatus === UploadStateEnum.Paused) {
|
||||
this.uploadStatus = UploadStateEnum.Progress;
|
||||
}
|
||||
}
|
||||
|
||||
// if we're uploading one file directly, do the size calc first
|
||||
@@ -746,6 +751,28 @@ class FileUploadService {
|
||||
this.groupIds = {};
|
||||
this.notify();
|
||||
}
|
||||
|
||||
public resetStates(ids: string[]) {
|
||||
this.logger.debug('===== START resetStates =====');
|
||||
this.logger.debug('groupedPendingFiles: ', this.groupedPendingFiles);
|
||||
this.logger.debug('groupIds: ', this.groupIds);
|
||||
this.logger.debug('rootStates: ', this.rootStates);
|
||||
|
||||
this.uploadStatus = UploadStateEnum.Progress;
|
||||
for (const id of ids) {
|
||||
delete this.groupedPendingFiles[id];
|
||||
delete this.groupIds[id];
|
||||
delete this.rootStates.paused[id];
|
||||
delete this.rootStates.completed[id];
|
||||
delete this.rootStates.failed[id];
|
||||
delete this.rootStates.cancelled[id];
|
||||
}
|
||||
|
||||
this.logger.debug('===== END resetStates =====');
|
||||
this.logger.debug('groupedPendingFiles: ', this.groupedPendingFiles);
|
||||
this.logger.debug('groupIds: ', this.groupIds);
|
||||
this.logger.debug('rootStates: ', this.rootStates);
|
||||
}
|
||||
}
|
||||
|
||||
export default new FileUploadService();
|
||||
|
||||
@@ -21,6 +21,7 @@ export const CreateLink = () => {
|
||||
type: 'text/uri-list',
|
||||
});
|
||||
|
||||
FileUploadService.resetStates([file.name]);
|
||||
await FileUploadService.upload([{ root: file.name, file }], {
|
||||
context: {
|
||||
parentId: state.parent_id,
|
||||
|
||||
Reference in New Issue
Block a user