add warn message

pull/4767/head
yann300 9 months ago committed by Joseph Izang
parent b1988c6c73
commit ec29e3eb13
  1. 22
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx
  2. 20
      libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx
  3. 4
      libs/remix-ui/workspace/src/lib/components/flat-tree.tsx
  4. 1
      libs/remix-ui/workspace/src/lib/types/index.ts

@ -339,12 +339,23 @@ export const FileExplorer = (props: FileExplorerProps) => {
} }
} }
const handleFileMove = async (dest: string, copySrc: string) => { const warnMovingItems = async (src: string[], dest: string): Promise<void> => {
if (await moveFileIsAllowed(copySrc, dest) === false) return return new Promise((resolve, reject) => {
props.modal(
const src = filesSelected && filesSelected.length > 0 ? filesSelected.join(' ') : '' 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 { try {
props.modal( props.modal(
intl.formatMessage({ id: 'filePanel.moveFile' }), intl.formatMessage({ id: 'filePanel.moveFile' }),
@ -454,6 +465,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
fileState={fileState} fileState={fileState}
expandPath={props.expandPath} expandPath={props.expandPath}
handleContextMenu={handleContextMenu} handleContextMenu={handleContextMenu}
warnMovingItems={warnMovingItems}
moveFile={handleFileMove} moveFile={handleFileMove}
moveFolder={handleFolderMove} moveFolder={handleFolderMove}
moveFolderSilently={moveFolderSilently} moveFolderSilently={moveFolderSilently}

@ -8,7 +8,7 @@ import { FileSystemContext } from '../contexts'
export const FlatTreeDrop = (props: FlatTreeDropProps) => { export const FlatTreeDrop = (props: FlatTreeDropProps) => {
const { getFlatTreeItem, dragSource, moveFile, moveFolder, handleClickFolder, expandPath } = props const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props
// delay timer // delay timer
const [timer, setTimer] = useState<NodeJS.Timeout>() const [timer, setTimer] = useState<NodeJS.Timeout>()
// folder to open // folder to open
@ -67,21 +67,21 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
if (dragDestination.isDirectory) { if (dragDestination.isDirectory) {
if (dragSource.isDirectory) { if (dragSource.isDirectory) {
moveFolder(dragDestination.path, dragSource.path) await props.warnMovingItems(filePaths, dragDestination.path)
await moveFoldersSilently(props.selectedItems, dragDestination.path) await moveFoldersSilently(filePaths, dragDestination.path)
} else { } else {
moveFile(dragDestination.path, dragSource.path) await props.warnMovingItems(filePaths, dragDestination.path)
await moveFilesSilently(props.selectedItems, dragDestination.path) await moveFilesSilently(filePaths, dragDestination.path)
} }
} else { } else {
const path = extractParentFromKey(dragDestination.path) || '/' const path = extractParentFromKey(dragDestination.path) || '/'
if (dragSource.isDirectory) { if (dragSource.isDirectory) {
moveFolder(path, dragSource.path) await props.warnMovingItems(filePaths, path)
await moveFoldersSilently(props.selectedItems, path) await moveFoldersSilently(filePaths, path)
} else { } else {
moveFile(path, dragSource.path) await props.warnMovingItems(filePaths, path)
await moveFilesSilently(props.selectedItems, path) await moveFilesSilently(filePaths, path)
} }
} }
} }
@ -93,7 +93,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
* @returns Promise<void> * @returns Promise<void>
*/ */
const moveFilesSilently = async (items: DragStructure[], targetPath: string) => { const moveFilesSilently = async (items: DragStructure[], targetPath: string) => {
console.log('moveItemsSilently', { items, targetPath })
const promises = items.filter(item => item.path !== targetPath) const promises = items.filter(item => item.path !== targetPath)
.map(async (item) => { .map(async (item) => {
if (item.type === 'file') { if (item.type === 'file') {
@ -110,7 +109,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
* @returns Promise<void> * @returns Promise<void>
*/ */
const moveFoldersSilently = async (items: DragStructure[], targetPath: string) => { const moveFoldersSilently = async (items: DragStructure[], targetPath: string) => {
console.log('moveItemsSilently', { items, targetPath })
const promises = items.filter(item => item.path !== targetPath) const promises = items.filter(item => item.path !== targetPath)
.map(async (item) => { .map(async (item) => {
if (item.type === 'folder') { if (item.type === 'folder') {

@ -46,6 +46,7 @@ interface FlatTreeProps {
createNewFolder?: any createNewFolder?: any
deletePath?: (path: string | string[]) => void | Promise<void> deletePath?: (path: string | string[]) => void | Promise<void>
editPath?: (path: string, type: string, isNew?: boolean) => void editPath?: (path: string, type: string, isNew?: boolean) => void
warnMovingItems: (srcs: string[], dests: string) => Promise<void>
} }
let mouseTimer: any = { let mouseTimer: any = {
@ -54,7 +55,7 @@ let mouseTimer: any = {
} }
export const FlatTree = (props: FlatTreeProps) => { 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<string>('') const [hover, setHover] = useState<string>('')
const [mouseOverTarget, setMouseOverTarget] = useState<{ const [mouseOverTarget, setMouseOverTarget] = useState<{
path: string, path: string,
@ -264,6 +265,7 @@ export const FlatTree = (props: FlatTreeProps) => {
getFlatTreeItem={getFlatTreeItem} getFlatTreeItem={getFlatTreeItem}
moveFile={moveFile} moveFile={moveFile}
moveFolder={moveFolder} moveFolder={moveFolder}
warnMovingItems={warnMovingItems}
moveFolderSilently={moveFolderSilently} moveFolderSilently={moveFolderSilently}
moveFileSilently={moveFileSilently} moveFileSilently={moveFileSilently}
setFilesSelected={setFilesSelected} setFilesSelected={setFilesSelected}

@ -358,6 +358,7 @@ export interface FlatTreeDropProps {
expandPath: string[] expandPath: string[]
selectedItems: DragStructure[] selectedItems: DragStructure[]
setSelectedItems: Dispatch<React.SetStateAction<DragStructure[]>> setSelectedItems: Dispatch<React.SetStateAction<DragStructure[]>>
warnMovingItems: (srcs: string[], dest: string) => Promise<void>
} }
export type DragStructure = { export type DragStructure = {

Loading…
Cancel
Save