diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/CSFFileBrowser.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/CSFFileBrowser.tsx index 6394a8b577..df24ab5115 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/CSFFileBrowser.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/CSFFileBrowser.tsx @@ -106,7 +106,7 @@ const CSFFileBrowser: React.FC = () => { const itemToRename = pathContents.find(i => i.cid === cid) if (!bucket || !itemToRename) return - filesApiClient.moveBucketObjects(bucket.id, { + return filesApiClient.moveBucketObjects(bucket.id, { paths: [getPathWithFile(currentPath, itemToRename.name)], new_path: getPathWithFile(currentPath, newName) }) .then(() => refreshContents()) @@ -116,7 +116,6 @@ const CSFFileBrowser: React.FC = () => { const moveItems = useCallback(async (cids: string[], newPath: string) => { if (!bucket) return - const pathsToMove = getAbsolutePathsFromCids(cids, currentPath, pathContents) filesApiClient.moveBucketObjects(bucket.id, { @@ -210,7 +209,7 @@ const CSFFileBrowser: React.FC = () => { deleteItems: moveItemsToBin, downloadFile: handleDownload, moveItems, - renameItem: renameItem, + renameItem, viewFolder, handleUploadOnDrop, loadingCurrentPath, diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx index 6a8f00515a..8138defb6f 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFileBrowser.tsx @@ -155,7 +155,7 @@ const SharedFileBrowser = () => { const itemToRename = pathContents.find(i => i.cid === cid) if (!bucket || !itemToRename) return - filesApiClient.moveBucketObjects(bucket.id, { + return filesApiClient.moveBucketObjects(bucket.id, { paths: [getPathWithFile(currentPath, itemToRename.name)], new_path: getPathWithFile(currentPath, newName) }).then(() => refreshContents()) .catch(console.error) diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFoldersOverview.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFoldersOverview.tsx index 7a12b8ee5e..bc22e609d7 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFoldersOverview.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/SharedFoldersOverview.tsx @@ -178,7 +178,7 @@ const SharedFolderOverview = () => { }, [column, direction]) const handleRename = useCallback((bucket: BucketKeyPermission, newName: string) => { - filesApiClient.updateBucket(bucket.id, { + return filesApiClient.updateBucket(bucket.id, { ...bucket, name: newName }).then(() => refreshBuckets(false)) diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemGridItem.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemGridItem.tsx index 69191e86ac..adac7f1ab1 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemGridItem.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemGridItem.tsx @@ -1,10 +1,11 @@ -import React, { useCallback, useEffect, useMemo, useRef } from "react" +import React, { useCallback, useEffect, useMemo, useRef, useState } from "react" import { makeStyles, createStyles, useThemeSwitcher, useOnClickOutside, LongPressEvents } from "@chainsafe/common-theme" import { t } from "@lingui/macro" import clsx from "clsx" import { FormikTextInput, IMenuItem, + Loading, MoreIcon, Typography } from "@chainsafe/common-components" @@ -118,6 +119,10 @@ const useStyles = makeStyles(({ breakpoints, constants, palette }: CSFTheme) => }, focusVisible: { backgroundColor: "transparent !important" + }, + loadingIcon: { + marginLeft: constants.generalUnit, + verticalAlign: "middle" } }) }) @@ -133,7 +138,7 @@ interface IFileSystemTableItemProps { icon: React.ReactNode preview: ConnectDragPreview setEditing: (editing: string | undefined) => void - handleRename?: (path: string, newPath: string) => Promise + handleRename?: (path: string, newPath: string) => Promise | undefined currentPath: string | undefined menuItems: IMenuItem[] resetSelectedFiles: () => void @@ -161,11 +166,9 @@ const FileSystemGridItem = React.forwardRef( const { name, cid } = file const { desktop } = useThemeSwitcher() const formRef = useRef(null) + const [isEditingLoading, setIsEditingLoading] = useState(false) - const { - fileName, - extension - } = useMemo(() => { + const { fileName, extension } = useMemo(() => { if (isFolder) { return { fileName : name, @@ -196,8 +199,11 @@ const FileSystemGridItem = React.forwardRef( onSubmit: (values: { name: string }) => { const newName = extension !== "" ? `${values.name.trim()}.${extension}` : values.name.trim() - if (newName !== name) { - newName && handleRename && handleRename(file.cid, newName) + if (newName !== name && !!newName && handleRename) { + setIsEditingLoading(true) + + handleRename(cid, newName) + ?.then(() => setIsEditingLoading(false)) } else { stopEditing() } @@ -232,7 +238,7 @@ const FileSystemGridItem = React.forwardRef( formik.resetForm() }, [formik, setEditing]) - useOnClickOutside(formRef, stopEditing) + useOnClickOutside(formRef, formik.submitForm) return (
{ !isFolder && extension !== "" && ( @@ -291,7 +297,13 @@ const FileSystemGridItem = React.forwardRef( ) - :
{name}
+ :
+ {name}{isEditingLoading && } +
}
diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemItem.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemItem.tsx index 9ba00d687d..1612e8ed54 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemItem.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemItem.tsx @@ -109,7 +109,7 @@ interface IFileSystemItemProps { handleAddToSelectedItems(selectedItems: FileSystemItemType): void editing: string | undefined setEditing(editing: string | undefined): void - handleRename?: (cid: string, newName: string) => Promise + handleRename?: (cid: string, newName: string) => Promise | undefined handleMove?: (cid: string, newPath: string) => Promise deleteFile?: () => void recoverFile?: () => void @@ -524,7 +524,7 @@ const FileSystemItem = ({ className={classes.renameInput} name="name" placeholder={isFolder ? t`Please enter a folder name` : t`Please enter a file name`} - autoFocus={editing === cid} + autoFocus /> { !isFolder && extension !== "" && ( diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemTableItem.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemTableItem.tsx index 8349139346..50df6ac46c 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemTableItem.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/FileSystemTableItem.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useMemo, useRef } from "react" +import React, { useCallback, useMemo, useRef, useState } from "react" import { makeStyles, createStyles, useThemeSwitcher, useOnClickOutside, LongPressEvents } from "@chainsafe/common-theme" import { t } from "@lingui/macro" import clsx from "clsx" @@ -7,6 +7,7 @@ import { formatBytes, FormikTextInput, IMenuItem, + Loading, MoreIcon, TableCell, TableRow, @@ -104,6 +105,10 @@ const useStyles = makeStyles(({ breakpoints, constants, palette }: CSFTheme) => }, focusVisible: { backgroundColor: "transparent !important" + }, + loadingIcon: { + marginLeft: constants.generalUnit, + verticalAlign: "middle" } }) }) @@ -114,13 +119,13 @@ interface IFileSystemTableItemProps { isOverUpload: boolean selectedCids: string[] file: FileSystemItem - editing: string | undefined + editing?: string handleAddToSelectedItems: (selected: FileSystemItem) => void onFolderOrFileClicks: (e?: React.MouseEvent) => void icon: React.ReactNode preview: ConnectDragPreview setEditing: (editing: string | undefined) => void - handleRename?: (path: string, newPath: string) => Promise + handleRename?: (path: string, newPath: string) => Promise | undefined currentPath: string | undefined menuItems: IMenuItem[] longPressEvents?: LongPressEvents @@ -147,11 +152,9 @@ const FileSystemTableItem = React.forwardRef( const { name, cid, created_at, size } = file const { desktop } = useThemeSwitcher() const formRef = useRef(null) + const [isEditingLoading, setIsEditingLoading] = useState(false) - const { - fileName, - extension - } = useMemo(() => { + const { fileName, extension } = useMemo(() => { if (isFolder) { return { fileName : name, @@ -178,10 +181,14 @@ const FileSystemTableItem = React.forwardRef( initialValues: { name: fileName }, validationSchema: nameValidator, onSubmit: (values: { name: string }) => { + const newName = extension !== "" ? `${values.name.trim()}.${extension}` : values.name.trim() - if (newName !== name) { - newName && handleRename && handleRename(file.cid, newName) + if (newName !== name && !!newName && handleRename) { + setIsEditingLoading(true) + + handleRename(file.cid, newName) + ?.then(() => setIsEditingLoading(false)) } else { stopEditing() } @@ -194,7 +201,7 @@ const FileSystemTableItem = React.forwardRef( formik.resetForm() }, [formik, setEditing]) - useOnClickOutside(formRef, stopEditing) + useOnClickOutside(formRef, formik.submitForm) return ( !editing && onFolderOrFileClicks(e)} {...longPressEvents} > - {editing === cid && desktop + { editing === cid && desktop ? (
{ !isFolder && extension !== "" && ( @@ -264,14 +271,19 @@ const FileSystemTableItem = React.forwardRef(
) - : {name}} + : <> + {name} + {isEditingLoading && } + } {desktop && ( <> - { - !isFolder && !!created_at && dayjs.unix(created_at).format("DD MMM YYYY h:mm a") - } + {!isFolder && !!created_at && dayjs.unix(created_at).format("DD MMM YYYY h:mm a")} {!isFolder && formatBytes(size, 2)} @@ -296,3 +308,4 @@ const FileSystemTableItem = React.forwardRef( FileSystemTableItem.displayName = "FileSystemTableItem" export default FileSystemTableItem + diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/SharedFolderRow.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/SharedFolderRow.tsx index 66ba0e2dab..52fd715ca4 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/SharedFolderRow.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FileSystemItem/SharedFolderRow.tsx @@ -9,6 +9,7 @@ import { formatBytes, FormikTextInput, IMenuItem, + Loading, MoreIcon, TableCell, TableRow, @@ -139,13 +140,17 @@ const useStyles = makeStyles(({ breakpoints, constants, palette }: CSFTheme) => }, okButton: { marginLeft: constants.generalUnit + }, + loadingIcon: { + marginLeft: constants.generalUnit, + verticalAlign: "middle" } }) }) interface Props { bucket: BucketKeyPermission - handleRename: (bucket: BucketKeyPermission, newName: string) => void + handleRename: (bucket: BucketKeyPermission, newName: string) => Promise openSharedFolder: (bucketId: string) => void onEditSharedFolder: () => void handleDeleteSharedFolder: () => void @@ -160,6 +165,7 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS const formRef = useRef(null) const isOwner = useMemo(() => bucket.permission === "owner", [bucket.permission]) const [ownerName, setOwnerName] = useState("") + const [isEditingLoading, setIsEditingLoading] = useState(false) useEffect(() => { if (isOwner) { @@ -246,15 +252,20 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS } const formik = useFormik({ - initialValues:{ - name - }, + initialValues:{ name }, enableReinitialize: true, validationSchema: nameValidator, onSubmit:(values, { resetForm }) => { const newName = values.name?.trim() - newName && handleRename && handleRename(bucket, newName) + if (newName !== name && !!newName && handleRename) { + setIsEditingLoading(true) + + handleRename(bucket, newName) + .then(() => setIsEditingLoading(false)) + } else { + stopEditing() + } setIsRenaming(false) resetForm() } @@ -265,7 +276,7 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS formik.resetForm() }, [formik, setIsRenaming]) - useOnClickOutside(formRef, stopEditing) + useOnClickOutside(formRef, formik.submitForm) return ( <> @@ -290,7 +301,14 @@ const SharedFolderRow = ({ bucket, handleRename, openSharedFolder, handleDeleteS onClick={(e) => onFolderClick(e)} > {!isRenaming || !desktop - ? {name} + ? <> + {name} + {isEditingLoading && } + : (
- {name} + <> + {name} + {isEditingLoading && } + ) } diff --git a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx index c62c400a65..f7366a18c4 100644 --- a/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx +++ b/packages/files-ui/src/Components/Modules/FileBrowsers/views/FilesList.tsx @@ -1198,9 +1198,9 @@ const FilesList = ({ isShared = false }: Props) => { handleAddToSelectedItems={handleAddToSelectedItems} editing={editing} setEditing={setEditing} - handleRename={async (cid: string, newName: string) => { - handleRename && (await handleRename(cid, newName)) + handleRename={(cid: string, newName: string) => { setEditing(undefined) + return handleRename && handleRename(cid, newName) }} deleteFile={() => { setSelectedItems([file]) @@ -1257,9 +1257,9 @@ const FilesList = ({ isShared = false }: Props) => { handleAddToSelectedItems={handleAddToSelectedItems} editing={editing} setEditing={setEditing} - handleRename={async (path: string, newPath: string) => { - handleRename && (await handleRename(path, newPath)) + handleRename={(path: string, newPath: string) => { setEditing(undefined) + return handleRename && handleRename(path, newPath) }} deleteFile={() => { setSelectedItems([file]) diff --git a/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemGridItem.tsx b/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemGridItem.tsx index 71beb08368..0a9284ed11 100644 --- a/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemGridItem.tsx +++ b/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemGridItem.tsx @@ -1,10 +1,11 @@ -import React, { useCallback, useEffect } from "react" +import React, { useCallback, useEffect, useState } from "react" import { makeStyles, createStyles, useThemeSwitcher } from "@chainsafe/common-theme" import { t } from "@lingui/macro" import clsx from "clsx" import { FormikTextInput, IMenuItem, + Loading, MenuDropdown, MoreIcon } from "@chainsafe/common-components" @@ -115,6 +116,10 @@ const useStyles = makeStyles(({ breakpoints, constants, palette }: CSSTheme) => [breakpoints.down("md")]: { padding: 0 } + }, + loadingIcon: { + marginLeft: constants.generalUnit, + verticalAlign: "middle" } }) }) @@ -125,12 +130,12 @@ interface IFileSystemTableItemProps { isOverUpload: boolean selected: ISelectedFile[] file: FileSystemItem - editing: ISelectedFile | undefined + editing?: string onFolderOrFileClicks: (e?: React.MouseEvent) => void icon: React.ReactNode preview: ConnectDragPreview setEditing: (editing: ISelectedFile | undefined) => void - handleRename?: (toRename: ISelectedFile, newPath: string) => Promise + handleRename?: (cid: string, newName: string) => Promise | undefined currentPath: string | undefined menuItems: IMenuItem[] resetSelectedFiles: () => void @@ -155,6 +160,7 @@ const FileSystemGridItem = React.forwardRef( const classes = useStyles() const { name, cid } = file const { desktop } = useThemeSwitcher() + const [isEditingLoading, setIsEditingLoading] = useState(false) const formik = useFormik({ initialValues: { @@ -164,10 +170,14 @@ const FileSystemGridItem = React.forwardRef( onSubmit: (values) => { const newName = values.fileName?.trim() - newName && handleRename && handleRename({ - cid: file.cid, - name: file.name - }, newName) + if (newName !== name && !!newName && handleRename) { + setIsEditingLoading(true) + + handleRename(file.cid, newName) + ?.then(() => setIsEditingLoading(false)) + } else { + stopEditing() + } }, enableReinitialize: true }) @@ -224,11 +234,11 @@ const FileSystemGridItem = React.forwardRef( > {icon}
- {(editing?.cid === cid && editing.name === name) && desktop ? ( + {editing === cid && desktop ? ( - ) : ( -
{name}
- )} - -
- + ) :
+ {name}{isEditingLoading && } +
+ }
+ + ) } diff --git a/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemItem.tsx b/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemItem.tsx index eeb956b69e..f959d0feb4 100644 --- a/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemItem.tsx +++ b/packages/storage-ui/src/Components/Modules/FileSystemItem/FileSystemItem.tsx @@ -107,9 +107,9 @@ interface IFileSystemItemProps { selected: ISelectedFile[] handleSelectCid(selectedFile: ISelectedFile): void handleAddToSelectedCids(selectedFile: ISelectedFile): void - editing: ISelectedFile | undefined + editing?: string setEditing(editing: ISelectedFile | undefined): void - handleRename?: (toRename: ISelectedFile, newName: string) => Promise + handleRename?: (cid: string, newName: string) => Promise | undefined handleMove?: (toMove: ISelectedFile, newPath: string) => Promise deleteFile?: () => void recoverFile?: (toRecover: ISelectedFile) => void @@ -158,9 +158,7 @@ const FileSystemItem = ({ const classes = useStyles() const formik = useFormik({ - initialValues: { - name - }, + initialValues: { name }, validationSchema: nameValidator, onSubmit: (values: {name: string}) => { const newName = values.name.trim() @@ -180,10 +178,7 @@ const FileSystemItem = ({ ), - onClick: () => setEditing({ - cid, - name - }) + onClick: () => setEditing({ cid, name }) }, delete: { contents: ( @@ -434,7 +429,7 @@ const FileSystemItem = ({ : } { - (editing?.cid === cid && editing.name === name) && !desktop && ( + editing === cid && !desktop && ( <> setEditing(undefined)} > @@ -462,7 +456,7 @@ const FileSystemItem = ({ className={classes.renameInput} name="name" placeholder={isFolder ? t`Please enter a folder name` : t`Please enter a file name`} - autoFocus={editing.cid === cid} + autoFocus />