From ec29e3eb138fe7c298b82db7dcbb38d63f76ee90 Mon Sep 17 00:00:00 2001 From: yann300 Date: Mon, 29 Apr 2024 19:20:29 +0200 Subject: [PATCH] add warn message --- .../src/lib/components/file-explorer.tsx | 22 ++++++++++++++----- .../src/lib/components/flat-tree-drop.tsx | 20 ++++++++--------- .../src/lib/components/flat-tree.tsx | 4 +++- .../remix-ui/workspace/src/lib/types/index.ts | 1 + 4 files changed, 30 insertions(+), 17 deletions(-) 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 7768366f4b..8169053528 100644 --- a/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx +++ b/libs/remix-ui/workspace/src/lib/components/file-explorer.tsx @@ -339,12 +339,23 @@ export const FileExplorer = (props: FileExplorerProps) => { } } - const handleFileMove = async (dest: string, copySrc: string) => { - if (await moveFileIsAllowed(copySrc, dest) === false) return - - const src = filesSelected && filesSelected.length > 0 ? filesSelected.join(' ') : '' + const warnMovingItems = async (src: string[], dest: string): Promise => { + return new Promise((resolve, reject) => { + props.modal( + intl.formatMessage({ id: 'filePanel.moveFile' }), + intl.formatMessage({ id: 'filePanel.moveFileMsg1' }, { src: src.join(', '), dest }), + intl.formatMessage({ id: 'filePanel.yes' }), + () => resolve(null), + intl.formatMessage({ id: 'filePanel.cancel' }), + () => reject() + ) + }) + } - console.log('handleFileMove sourcesrc', {src, copySrc, dest }) + const handleFileMove = async (dest: string, sourcesrc: string[]) => { + if (await moveFilesIsAllowed(sourcesrc, dest) === false) return + const files = filesSelected && filesSelected.length > 0 && filesSelected.join(' ') + const src = files.length > 0 ? files : sourcesrc.length === 1 ? sourcesrc[0] : sourcesrc.join(' ') try { props.modal( intl.formatMessage({ id: 'filePanel.moveFile' }), @@ -454,6 +465,7 @@ export const FileExplorer = (props: FileExplorerProps) => { fileState={fileState} expandPath={props.expandPath} handleContextMenu={handleContextMenu} + warnMovingItems={warnMovingItems} moveFile={handleFileMove} moveFolder={handleFolderMove} moveFolderSilently={moveFolderSilently} 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 fb2c08ff21..8d48aaccd9 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 @@ -8,7 +8,7 @@ import { FileSystemContext } from '../contexts' export const FlatTreeDrop = (props: FlatTreeDropProps) => { - const { getFlatTreeItem, dragSource, moveFile, moveFolder, handleClickFolder, expandPath } = props + const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props // delay timer const [timer, setTimer] = useState() // folder to open @@ -67,21 +67,21 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { if (dragDestination.isDirectory) { if (dragSource.isDirectory) { - moveFolder(dragDestination.path, dragSource.path) - await moveFoldersSilently(props.selectedItems, dragDestination.path) + await props.warnMovingItems(filePaths, dragDestination.path) + await moveFoldersSilently(filePaths, dragDestination.path) } else { - moveFile(dragDestination.path, dragSource.path) - await moveFilesSilently(props.selectedItems, dragDestination.path) + await props.warnMovingItems(filePaths, dragDestination.path) + await moveFilesSilently(filePaths, dragDestination.path) } } else { const path = extractParentFromKey(dragDestination.path) || '/' if (dragSource.isDirectory) { - moveFolder(path, dragSource.path) - await moveFoldersSilently(props.selectedItems, path) + await props.warnMovingItems(filePaths, path) + await moveFoldersSilently(filePaths, path) } else { - moveFile(path, dragSource.path) - await moveFilesSilently(props.selectedItems, path) + await props.warnMovingItems(filePaths, path) + await moveFilesSilently(filePaths, path) } } } @@ -93,7 +93,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { * @returns Promise */ const moveFilesSilently = async (items: DragStructure[], targetPath: string) => { - console.log('moveItemsSilently', { items, targetPath }) const promises = items.filter(item => item.path !== targetPath) .map(async (item) => { if (item.type === 'file') { @@ -110,7 +109,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => { * @returns Promise */ const moveFoldersSilently = async (items: DragStructure[], targetPath: string) => { - console.log('moveItemsSilently', { items, targetPath }) const promises = items.filter(item => item.path !== targetPath) .map(async (item) => { if (item.type === 'folder') { 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 42ced37826..4f8e8f7aa0 100644 --- a/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx +++ b/libs/remix-ui/workspace/src/lib/components/flat-tree.tsx @@ -46,6 +46,7 @@ interface FlatTreeProps { createNewFolder?: any deletePath?: (path: string | string[]) => void | Promise editPath?: (path: string, type: string, isNew?: boolean) => void + warnMovingItems: (srcs: string[], dests: string) => Promise } let mouseTimer: any = { @@ -54,7 +55,7 @@ let mouseTimer: any = { } export const FlatTree = (props: FlatTreeProps) => { - const { files, flatTree, expandPath, focusEdit, editModeOff, handleTreeClick, moveFile, moveFolder, fileState, focusElement, handleClickFolder, deletePath, moveFileSilently, moveFolderSilently, setFilesSelected } = props + const { files, flatTree, expandPath, focusEdit, editModeOff, handleTreeClick, moveFile, moveFolder, warnMovingItems, fileState, focusElement, handleClickFolder, deletePath, moveFileSilently, moveFolderSilently, setFilesSelected } = props const [hover, setHover] = useState('') const [mouseOverTarget, setMouseOverTarget] = useState<{ path: string, @@ -264,6 +265,7 @@ export const FlatTree = (props: FlatTreeProps) => { getFlatTreeItem={getFlatTreeItem} moveFile={moveFile} moveFolder={moveFolder} + warnMovingItems={warnMovingItems} moveFolderSilently={moveFolderSilently} moveFileSilently={moveFileSilently} setFilesSelected={setFilesSelected} diff --git a/libs/remix-ui/workspace/src/lib/types/index.ts b/libs/remix-ui/workspace/src/lib/types/index.ts index 56bf8b839e..9ba1843b4c 100644 --- a/libs/remix-ui/workspace/src/lib/types/index.ts +++ b/libs/remix-ui/workspace/src/lib/types/index.ts @@ -358,6 +358,7 @@ export interface FlatTreeDropProps { expandPath: string[] selectedItems: DragStructure[] setSelectedItems: Dispatch> + warnMovingItems: (srcs: string[], dest: string) => Promise } export type DragStructure = {