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

Fix move single file and test #1608

Merged
merged 5 commits into from
Oct 4, 2021
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
1 change: 1 addition & 0 deletions packages/files-ui/cypress/support/page-objects/homePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const homePage = {
selectAllCheckbox: () => cy.get("[data-testId=checkbox-select-all]"),
uploadStatusToast: () => cy.get("[data-testId=toast-upload-status]", { timeout: 10000 }),
deleteSuccessToast: () => cy.get("[data-testId=toast-deletion-success]", { timeout: 10000 }),
moveSuccessToast: () => cy.get("[data-testId=toast-move-success]", { timeout: 10000 }),
fileRenameInput: () => cy.get("[data-cy=rename-form] input"),
fileRenameSubmitButton: () => cy.get("[data-cy=rename-submit-button]"),
fileRenameErrorLabel: () => cy.get("[data-cy=rename-form] span.minimal.error"),
Expand Down
1 change: 1 addition & 0 deletions packages/files-ui/cypress/tests/file-management-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ describe("File management", () => {
homePage.moveSelectedButton().click()
moveItemModal.folderList().contains("Home").click()
moveItemModal.moveButton().safeClick()
homePage.moveSuccessToast().should("not.exist")

// ensure the home root now has the folder and file
navigationMenu.homeNavButton().click()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { t } from "@lingui/macro"
import { CONTENT_TYPES } from "../../../Utils/Constants"
import { IFilesTableBrowserProps } from "../../Modules/FileBrowsers/types"
import { useHistory, useLocation, useToasts } from "@chainsafe/common-components"
import { extractFileBrowserPathFromURL, getAbsolutePathsFromCids, getUrlSafePathWithFile } from "../../../Utils/pathUtils"
import {
extractFileBrowserPathFromURL,
getAbsolutePathsFromCids,
getUrlSafePathWithFile,
pathEndingWithSlash
} from "../../../Utils/pathUtils"
import { ROUTE_LINKS } from "../../FilesRoutes"
import { FileBrowserContext } from "../../../Contexts/FileBrowserContext"
import { useFilesApi } from "../../../Contexts/FilesApiContext"
Expand Down Expand Up @@ -82,7 +87,7 @@ const BinFileBrowser: React.FC<IFileBrowserModuleProps> = ({ controls = false }:
bucket.id,
{
paths: pathsToRecover,
new_path: newPath,
new_path: pathEndingWithSlash(newPath),
destination: buckets.find(b => b.type === "csf")?.id
}
).then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import {
getPathWithFile,
extractFileBrowserPathFromURL,
getUrlSafePathWithFile,
getAbsolutePathsFromCids
getAbsolutePathsFromCids,
pathEndingWithSlash
} from "../../../Utils/pathUtils"
import { IBulkOperations, IFileBrowserModuleProps, IFilesTableBrowserProps } from "./types"
import FilesList from "./views/FilesList"
Expand Down Expand Up @@ -114,15 +115,17 @@ const CSFFileBrowser: React.FC<IFileBrowserModuleProps> = () => {
const moveItems = useCallback(async (cids: string[], newPath: string) => {
if (!bucket) return


const pathsToMove = getAbsolutePathsFromCids(cids, currentPath, pathContents)

filesApiClient.moveBucketObjects(bucket.id, {
paths: pathsToMove,
new_path: newPath
new_path: pathEndingWithSlash(newPath)
}).then(() => {
addToast({
title: t`Data moved successfully`,
type: "success"
type: "success",
testId: "move-success"
})
}).catch((error) => {
console.error("Error moving:", error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import {
getPathWithFile,
extractSharedFileBrowserPathFromURL,
getUrlSafePathWithFile,
getAbsolutePathsFromCids
getAbsolutePathsFromCids,
pathEndingWithSlash
} from "../../../Utils/pathUtils"
import { IBulkOperations, IFilesTableBrowserProps } from "./types"
import { CONTENT_TYPES } from "../../../Utils/Constants"
Expand All @@ -21,7 +22,7 @@ import DragAndDrop from "../../../Contexts/DnDContext"
import FilesList from "./views/FilesList"

const SharedFileBrowser = () => {
const { downloadFile, uploadFiles, buckets, getStorageSummary } = useFiles()
const { downloadFile, uploadFiles, buckets, getStorageSummary, refreshBuckets } = useFiles()
const { filesApiClient } = useFilesApi()
const { addToast } = useToasts()
const [loadingCurrentPath, setLoadingCurrentPath] = useState(false)
Expand Down Expand Up @@ -113,8 +114,11 @@ const SharedFileBrowser = () => {
title: t`There was an error deleting your data`,
type: "error"
})
}).finally(refreshContents)
}, [addToast, bucket, currentPath, filesApiClient, pathContents, refreshContents])
}).finally(() => {
refreshContents()
refreshBuckets()
})
}, [addToast, bucket, currentPath, filesApiClient, pathContents, refreshBuckets, refreshContents])

// Rename
const renameItem = useCallback(async (cid: string, newName: string) => {
Expand All @@ -134,7 +138,7 @@ const SharedFileBrowser = () => {

filesApiClient.moveBucketObjects(bucket.id, {
paths: pathsToMove,
new_path: newPath
new_path: pathEndingWithSlash(newPath)
}).then(() => {
addToast({
title: t`Data moved successfully`,
Expand Down
7 changes: 7 additions & 0 deletions packages/files-ui/src/Utils/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,11 @@ export const getAbsolutePathsFromCids = (cids: string[], currentPath: string, pa
}
return getPathWithFile(currentPath, item.name)
}).filter((item): item is string => !!item)
}

export const pathEndingWithSlash = (path: string) => {
const lastChar = path.substr(-1)
return lastChar === "/"
? path
: `${path}/`
}
Loading