diff --git a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx index 211994d118..c423ab4987 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -9,7 +9,7 @@ import '../css/file-explorer.css' import { checkSpecialChars, extractNameFromKey, extractParentFromKey, getPathIcon, joinPath } from '@remix-ui/helper' // eslint-disable-next-line @typescript-eslint/no-unused-vars import { ROOT_PATH } from '../utils/constants' -import { moveFileIsAllowed, moveFolderIsAllowed } from '../actions' +import { moveFileIsAllowed, moveFilesIsAllowed, moveFolderIsAllowed, moveFoldersIsAllowed } from '../actions' import { FlatTree } from './flat-tree' export const FileExplorer = (props: FileExplorerProps) => { @@ -299,11 +299,13 @@ export const FileExplorer = (props: FileExplorerProps) => { * @param src path of the source * @returns {void} */ - const moveFileSilently = async (dest: string, src: string) => { - if (dest.length === 0 || src.length === 0) return - if (await moveFileIsAllowed(src, dest) === false) return + const moveFileSilently = async (dest: string, sourcesrc: string[]) => { + if (dest.length === 0 || sourcesrc.length === 0) return + if (await moveFilesIsAllowed(sourcesrc, dest) === false) return + + const src = sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join('\n') try { - props.dispatchMoveFile(src, dest) + props.dispatchMoveFiles(sourcesrc, dest) } catch (error) { props.modal( intl.formatMessage({ id: 'filePanel.movingFileFailed' }), @@ -321,11 +323,13 @@ export const FileExplorer = (props: FileExplorerProps) => { * @param src path of the source * @returns {void} */ - const moveFolderSilently = async (dest: string, src: string) => { - if (dest.length === 0 || src.length === 0) return - if (await moveFolderIsAllowed(src, dest) === false) return + const moveFolderSilently = async (dest: string, sourcesrc: string[]) => { + if (dest.length === 0 || sourcesrc.length === 0) return + if (await moveFoldersIsAllowed(sourcesrc, dest) === false) return + + const src = sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join('\n') try { - props.dispatchMoveFolder(src, dest) + props.dispatchMoveFolders(sourcesrc, dest) } catch (error) { props.modal( intl.formatMessage({ id: 'filePanel.movingFolderFailed' }), @@ -336,14 +340,15 @@ export const FileExplorer = (props: FileExplorerProps) => { } } - const handleFileMove = async (dest: string, src: string) => { - if (await moveFileIsAllowed(src, dest) === false) return + const handleFileMove = async (dest: string, sourcesrc: string[]) => { + if (await moveFilesIsAllowed(sourcesrc, dest) === false) return + const src = sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join('\n') try { props.modal( intl.formatMessage({ id: 'filePanel.moveFile' }), intl.formatMessage({ id: 'filePanel.moveFileMsg1' }, { src, dest }), intl.formatMessage({ id: 'filePanel.yes' }), - () => props.dispatchMoveFile(src, dest), + () => props.dispatchMoveFiles(sourcesrc, dest), intl.formatMessage({ id: 'filePanel.cancel' }), () => { } ) @@ -357,14 +362,15 @@ export const FileExplorer = (props: FileExplorerProps) => { } } - const handleFolderMove = async (dest: string, src: string) => { - if (await moveFolderIsAllowed(src, dest) === false) return + const handleFolderMove = async (dest: string, sourcesrc: string[]) => { + if (await moveFoldersIsAllowed(sourcesrc, dest) === false) return + const src = sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join('\n') try { props.modal( intl.formatMessage({ id: 'filePanel.moveFile' }), intl.formatMessage({ id: 'filePanel.moveFileMsg1' }, { src, dest }), intl.formatMessage({ id: 'filePanel.yes' }), - () => props.dispatchMoveFolder(src, dest), + () => props.dispatchMoveFolders(sourcesrc, dest), intl.formatMessage({ id: 'filePanel.cancel' }), () => { } ) diff --git a/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx b/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx index 0fc8f38637..e4d3d558d2 100644 --- a/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx +++ b/libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx @@ -69,20 +69,20 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { } if (dragDestination.isDirectory) { if (dragSource.isDirectory) { - moveFolder(dragDestination.path, dragSource.path) + moveFolder(dragDestination.path, [dragSource.path]) await moveFoldersSilently(items, dragDestination.path) } else { - moveFile(dragDestination.path, dragSource.path) + moveFile(dragDestination.path, [dragSource.path]) await moveFilesSilently(items, dragDestination.path) } } else { const path = extractParentFromKey(dragDestination.path) || '/' if (dragSource.isDirectory) { - moveFolder(path, dragSource.path) + moveFolder(path, [dragSource.path]) await moveFoldersSilently(items, dragDestination.path) } else { - moveFile(path, dragSource.path) + moveFile(path, [dragSource.path]) await moveFilesSilently(items, dragDestination.path) } } @@ -130,7 +130,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { const promises = items.filter(item => item.path !== targetPath) .map(async (item) => { if (item.type === 'file') { - await props.moveFileSilently(targetPath, item.path) + await props.moveFileSilently(targetPath, [item.path]) } }) await Promise.all(promises) @@ -147,7 +147,7 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { const promises = items.filter(item => item.path !== targetPath) .map(async (item) => { if (item.type === 'folder') { - await props.moveFolderSilently(targetPath, item.path) + await props.moveFolderSilently(targetPath, [item.path]) } }) await Promise.all(promises) diff --git a/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx b/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx index da9eb1aca5..af7048c932 100644 --- a/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx +++ b/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx @@ -36,10 +36,10 @@ interface FlatTreeProps { handleContextMenu: (pageX: number, pageY: number, path: string, content: string, type: string) => void handleTreeClick: (e: SyntheticEvent) => void handleClickFolder: (path: string, type: string) => void - moveFile: (dest: string, src: string) => void - moveFolder: (dest: string, src: string) => void - moveFolderSilently: (dest: string, src: string) => Promise - moveFileSilently: (dest: string, src: string) => Promise + moveFile: (dest: string, src: string[]) => void + moveFolder: (dest: string, src: string[]) => void + moveFolderSilently: (dest: string, src: string[]) => Promise + moveFileSilently: (dest: string, src: string[]) => Promise fileState: fileDecoration[] createNewFile?: any createNewFolder?: any diff --git a/libs/remix-ui/workspace/src/lib/contexts/index.ts b/libs/remix-ui/workspace/src/lib/contexts/index.ts index 7e297ffb0d..5b58bfba61 100644 --- a/libs/remix-ui/workspace/src/lib/contexts/index.ts +++ b/libs/remix-ui/workspace/src/lib/contexts/index.ts @@ -39,6 +39,8 @@ export const FileSystemContext = createContext<{ dispatchCloneRepository: (url: string) => Promise, dispatchMoveFile: (src: string, dest: string) => Promise, dispatchMoveFolder: (src: string, dest: string) => Promise, + dispatchMoveFiles: (src: string[], dest: string) => Promise, + dispatchMoveFolders: (src: string[], dest: string) => Promise, dispatchShowAllBranches: () => Promise, dispatchSwitchToBranch: (branch: string) => Promise, dispatchCreateNewBranch: (branch: string) => Promise, diff --git a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx index 3da9063576..29a52a8654 100644 --- a/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx +++ b/libs/remix-ui/workspace/src/lib/remix-ui-workspace.tsx @@ -1251,7 +1251,9 @@ export function Workspace() { dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} dispatchMoveFile={global.dispatchMoveFile} + dispatchMoveFiles={global.dispatchMoveFiles} dispatchMoveFolder={global.dispatchMoveFolder} + dispatchMoveFolders={global.dispatchMoveFolders} handleCopyClick={handleCopyClick} handlePasteClick={handlePasteClick} addMenuItems={addMenuItems} @@ -1317,7 +1319,9 @@ export function Workspace() { dispatchAddInputField={global.dispatchAddInputField} dispatchHandleExpandPath={global.dispatchHandleExpandPath} dispatchMoveFile={global.dispatchMoveFile} + dispatchMoveFiles={global.dispatchMoveFiles} dispatchMoveFolder={global.dispatchMoveFolder} + dispatchMoveFolders={global.dispatchMoveFolders} handleCopyClick={handleCopyClick} handlePasteClick={handlePasteClick} addMenuItems={addMenuItems} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index f70b7611e3..95f3380b99 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -135,6 +135,8 @@ export interface FileExplorerProps { dispatchAddInputField:(path: string, type: 'file' | 'folder') => Promise, dispatchHandleExpandPath: (paths: string[]) => Promise, dispatchMoveFile: (src: string, dest: string) => Promise, + dispatchMoveFiles: (src: string[], dest: string) => Promise, + dispatchMoveFolders: (src: string[], dest: string) => Promise, dispatchMoveFolder: (src: string, dest: string) => Promise, handlePasteClick: (dest: string, destType: string) => void handleCopyClick: (path: string, type: WorkspaceElement) => void @@ -344,10 +346,10 @@ export type Actions = {[A in keyof ActionPayloadTypes]: Action}[keyof ActionP export type WorkspaceElement = 'folder' | 'file' | 'workspace' export interface FlatTreeDropProps { - moveFile: (dest: string, src: string) => void - moveFolder: (dest: string, src: string) => void - moveFolderSilently: (dest: string, src: string) => Promise - moveFileSilently: (dest: string, src: string) => Promise + moveFile: (dest: string, src: string[]) => void + moveFolder: (dest: string, src: string[]) => void + moveFolderSilently: (dest: string, src: string[]) => Promise + moveFileSilently: (dest: string, src: string[]) => Promise getFlatTreeItem: (path: string) => FileType handleClickFolder: (path: string, type: string) => void dragSource: FileType