From b245ebafffbe7384c74617ec231d2f3b087c3186 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Tue, 11 May 2021 19:10:12 +0200 Subject: [PATCH 01/10] fix adding new fsEntities and add currentID --- src/background/api/filesystem.ts | 5 +++-- src/background/constants.ts | 4 ++-- src/background/methods/filesystem.ts | 7 +++++-- src/background/redux/reducers/filesystem.ts | 2 +- src/components/pages/filesytem/FileList.tsx | 14 ++++++++------ .../pages/filesytem/upload/UploadZone.tsx | 3 +++ 6 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/background/api/filesystem.ts b/src/background/api/filesystem.ts index f141f995..f8d7e31a 100644 --- a/src/background/api/filesystem.ts +++ b/src/background/api/filesystem.ts @@ -15,14 +15,14 @@ const fhHostname = constants.url.FH_URL; export const getFolderContents = (path: string) => { console.log("[Get folder content", path) - return new Promise((resolve, reject) => { + return new Promise>((resolve, reject) => { let config = { headers: { "X-FF-PATH": path } }; Axios.get(hostname + filesystemPath + "contents", config) - .then((response: AxiosResponse) => resolve(response.data)) + .then((response: AxiosResponse) => resolve(response)) .catch((error) => reject(error)); }) } @@ -78,6 +78,7 @@ export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], par } ) .then((response: AxiosResponse<[FsEntity]>) => { + console.log(response) const currentPath = store.getState().filesystem.currentPath; const fsEntityToShow = response.data.find((fsEntity: FsEntity) => diff --git a/src/background/constants.ts b/src/background/constants.ts index 3d8e4871..2f7d3f09 100644 --- a/src/background/constants.ts +++ b/src/background/constants.ts @@ -12,9 +12,9 @@ const prod: constantsdef = { const dev: constantsdef = { url: { - API_URL: "https://demo.filefighter.de/api", + //API_URL: "https://demo.filefighter.de/api", // API_URL: "http://localhost:8080", - //API_URL: "http://localhost/api", + API_URL: "http://localhost/api", //FH_URL: "http://localhost:5000/data" FH_URL: "http://localhost/data" diff --git a/src/background/methods/filesystem.ts b/src/background/methods/filesystem.ts index 8dd2d5bb..4bc0dad3 100644 --- a/src/background/methods/filesystem.ts +++ b/src/background/methods/filesystem.ts @@ -4,12 +4,12 @@ export const getPathWithoutName = ( pathWithName: string, name: string ): string => { - return pathWithName.substr(0, pathWithName.lastIndexOf(name)); + return pathWithName.substr(0, pathWithName.lastIndexOf(name.toLowerCase())); }; export const removeTrailingBackslash = (path : string): string => { - if (path.lastIndexOf("/") === path.length){ + if (path.lastIndexOf("/") +1 === path.length){ return path.substr(0,path.length -1) } return path @@ -17,8 +17,11 @@ export const removeTrailingBackslash = (path : string): string => { export const isFsEntityInFolder = (fsEntity: FsEntity, path :string) =>{ + console.log(fsEntity,path) let fsEntityPath = getPathWithoutName(fsEntity.path,fsEntity.name); + console.log(fsEntityPath) fsEntityPath = removeTrailingBackslash(fsEntityPath); + console.log(fsEntityPath) return fsEntityPath === path.toLocaleLowerCase(); } diff --git a/src/background/redux/reducers/filesystem.ts b/src/background/redux/reducers/filesystem.ts index b945a820..9f10f66f 100644 --- a/src/background/redux/reducers/filesystem.ts +++ b/src/background/redux/reducers/filesystem.ts @@ -16,7 +16,7 @@ import {FsEntity} from "../../api/filesystemTypes"; const initialState: FilesystemState = { selectedFsEntities: [], folderContents: [], - currentFsItemId: "", + currentFsItemId: "-1", currentPath: "" }; diff --git a/src/components/pages/filesytem/FileList.tsx b/src/components/pages/filesytem/FileList.tsx index be8e21da..8d33aada 100644 --- a/src/components/pages/filesytem/FileList.tsx +++ b/src/components/pages/filesytem/FileList.tsx @@ -10,6 +10,7 @@ import {SystemState} from "../../../background/redux/actions/sytemState"; import {addToSelected, clearSelected, removeFromSelected, replaceSelected, setContents, setCurrentFsItemId, setCurrentPath} from "../../../background/redux/actions/filesystem"; import {connect, ConnectedProps} from "react-redux"; import {FFLoading} from "../../basicElements/Loading"; +import {AxiosResponse} from "axios"; const mapState = (state: SystemState) => ({ filesystem: { @@ -61,17 +62,18 @@ function FileList(props: Props): ReactElement { useEffect(() => { function updateStates(): void { getFolderContents(path) - .then((response: FsEntity[]) => { - console.log("got folder content"); + .then((response: AxiosResponse) => { + console.log("got folder content",response); + console.log(response.data) setContents([ - ...response.filter( + ...response.data.filter( (fsEntity: FsEntity) => fsEntity.type === "FOLDER" ), - ...response.filter((fsEntity: FsEntity) => fsEntity.type !== "FOLDER") + ...response.data.filter((fsEntity: FsEntity) => fsEntity.type !== "FOLDER") ]); setError(""); - setCurrentFsItemId(path); // TODO change this to the id of the current folder + setCurrentFsItemId(response.headers["X-FF-CURRENT"] ?? "-1"); }) .catch((err) => { setError(err.response?.data?.message); @@ -139,7 +141,7 @@ function FileList(props: Props): ReactElement { setFilesAndFolders(sortIncreasing ? toSort.reverse() : toSort); } - console.log("[FileList path]" + path); + console.log("[FileList path]" + path, filesAndFolders); return ( diff --git a/src/components/pages/filesytem/upload/UploadZone.tsx b/src/components/pages/filesytem/upload/UploadZone.tsx index 43f1d0ab..761019d7 100644 --- a/src/components/pages/filesytem/upload/UploadZone.tsx +++ b/src/components/pages/filesytem/upload/UploadZone.tsx @@ -93,6 +93,9 @@ export const UploadZone = (): ReactElement => { // @ts-ignore const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop }); + if (currentFsItemId == "-1" ){ + return <> + } return ( <>
From 9af538b1bacdcb5ce778b45ca6afb5cff8df1205 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Wed, 12 May 2021 14:59:44 +0200 Subject: [PATCH 02/10] fix es lint --- src/components/pages/filesytem/upload/UploadZone.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/pages/filesytem/upload/UploadZone.tsx b/src/components/pages/filesytem/upload/UploadZone.tsx index 761019d7..97e4ee8b 100644 --- a/src/components/pages/filesytem/upload/UploadZone.tsx +++ b/src/components/pages/filesytem/upload/UploadZone.tsx @@ -93,7 +93,7 @@ export const UploadZone = (): ReactElement => { // @ts-ignore const { getRootProps, getInputProps, isDragActive } = useDropzone({ onDrop }); - if (currentFsItemId == "-1" ){ + if (currentFsItemId === "-1" ){ return <> } return ( From ecb5acc20426fe4e37915685f6d8dc44292faa67 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Wed, 12 May 2021 15:38:59 +0200 Subject: [PATCH 03/10] fix upload of empty folder and currentFsItemId check --- src/components/pages/filesytem/FileList.tsx | 2 +- src/components/pages/filesytem/upload/UploadZone.tsx | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/pages/filesytem/FileList.tsx b/src/components/pages/filesytem/FileList.tsx index 8d33aada..c2275783 100644 --- a/src/components/pages/filesytem/FileList.tsx +++ b/src/components/pages/filesytem/FileList.tsx @@ -73,7 +73,7 @@ function FileList(props: Props): ReactElement { ...response.data.filter((fsEntity: FsEntity) => fsEntity.type !== "FOLDER") ]); setError(""); - setCurrentFsItemId(response.headers["X-FF-CURRENT"] ?? "-1"); + setCurrentFsItemId(response.headers["X-FF-CURRENT"]); }) .catch((err) => { setError(err.response?.data?.message); diff --git a/src/components/pages/filesytem/upload/UploadZone.tsx b/src/components/pages/filesytem/upload/UploadZone.tsx index 97e4ee8b..1eb1341d 100644 --- a/src/components/pages/filesytem/upload/UploadZone.tsx +++ b/src/components/pages/filesytem/upload/UploadZone.tsx @@ -40,6 +40,11 @@ export const UploadZone = (): ReactElement => { const onDrop = useCallback( (acceptedFiles: EditableFileWithPreflightInfo[]) => { + + if (!acceptedFiles.length){ + return + } + //check if preflight is needed let preflightNeeded = acceptedFiles.some( (file: EditablePreflightEntityOrFile) => { From 0d70d934238c8efa7a0bdd8cafebbef7683f8fdb Mon Sep 17 00:00:00 2001 From: qvalentin Date: Thu, 13 May 2021 10:23:35 +0200 Subject: [PATCH 04/10] update test --- .../__snapshots__/storybook.test.ts.snap | 29 ------------------- 1 file changed, 29 deletions(-) diff --git a/src/__tests__/__snapshots__/storybook.test.ts.snap b/src/__tests__/__snapshots__/storybook.test.ts.snap index 13864097..44e00436 100644 --- a/src/__tests__/__snapshots__/storybook.test.ts.snap +++ b/src/__tests__/__snapshots__/storybook.test.ts.snap @@ -303,35 +303,6 @@ exports[`Storyshots Filesystem default 1`] = `
-
- -

- Drag 'n' drop files or folders here, or click to select files -

-
`; From ae6143c623dae95fd785db85e563c5bffd145faf Mon Sep 17 00:00:00 2001 From: qvalentin Date: Thu, 13 May 2021 15:45:55 +0200 Subject: [PATCH 05/10] remove hardcoded fileIDS --- src/background/api/filesystem.ts | 2 -- src/components/pages/filesytem/upload/UploadZone.tsx | 3 ++- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/background/api/filesystem.ts b/src/background/api/filesystem.ts index f8d7e31a..67d716e6 100644 --- a/src/background/api/filesystem.ts +++ b/src/background/api/filesystem.ts @@ -32,7 +32,6 @@ export const uploadPreflight = ( files: File[] | EditableFileWithPreflightInfo[], parentFolderID: string ): Promise => { - parentFolderID = "0" //TODO const postData = files.map((f: File | EditableFileWithPreflightInfo) => ({ // @ts-ignore name: f.newName ?? f.name, @@ -54,7 +53,6 @@ export const uploadPreflight = ( }; export const uploadFiles = (files: File[] | EditableFileWithPreflightInfo[], parentFolderID: string) => { - parentFolderID = "0"; //TODO console.log("[API filesystem] uploading files to folderID", parentFolderID , files); const apiCall = (file: File | EditableFileWithPreflightInfo) => { return new Promise((resolve, reject) => { diff --git a/src/components/pages/filesytem/upload/UploadZone.tsx b/src/components/pages/filesytem/upload/UploadZone.tsx index 1eb1341d..626502d4 100644 --- a/src/components/pages/filesytem/upload/UploadZone.tsx +++ b/src/components/pages/filesytem/upload/UploadZone.tsx @@ -41,6 +41,7 @@ export const UploadZone = (): ReactElement => { const onDrop = useCallback( (acceptedFiles: EditableFileWithPreflightInfo[]) => { + if (!acceptedFiles.length){ return } @@ -56,7 +57,7 @@ export const UploadZone = (): ReactElement => { ); } ); - console.log(acceptedFiles, preflightNeeded); + console.log("[Upload Zone, add files]",acceptedFiles, preflightNeeded); if (preflightNeeded) { setFsItemIdToUpload(currentFsItemId); From b7629f4de987406ee31f0da87256d414c8cd1ce0 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Thu, 13 May 2021 16:41:15 +0200 Subject: [PATCH 06/10] fix current ID header parsing, design changes --- .../__snapshots__/storybook.test.ts.snap | 20 +++++-------------- src/components/pages/filesytem/FileList.tsx | 2 +- .../UploadDecisionsModalContent.stories.tsx | 12 +++++++++-- .../upload/UploadDecisionsModalContent.tsx | 4 ++-- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/src/__tests__/__snapshots__/storybook.test.ts.snap b/src/__tests__/__snapshots__/storybook.test.ts.snap index 44e00436..e089a3f5 100644 --- a/src/__tests__/__snapshots__/storybook.test.ts.snap +++ b/src/__tests__/__snapshots__/storybook.test.ts.snap @@ -54,7 +54,7 @@ Array [ onKeyDown={[Function]} >
-
Files that would be overwritten: @@ -90,7 +80,7 @@ Array [ onKeyDown={[Function]} >
-