prevent unneeded modals

pull/4084/head
filip mertens 1 year ago
parent d5e64b49b0
commit 3320e8b94c
  1. 44
      apps/remix-ide/src/app/files/fileManager.ts
  2. 2
      libs/remix-ui/drag-n-drop/src/lib/drag-n-drop.tsx
  3. 13
      libs/remix-ui/workspace/src/lib/actions/index.ts
  4. 12
      libs/remix-ui/workspace/src/lib/components/file-explorer.tsx

@ -904,6 +904,50 @@ class FileManager extends Plugin {
return exists
}
async moveFileIsAllowed (src: string, dest: string) {
try {
src = this.normalize(src)
dest = this.normalize(dest)
src = this.limitPluginScope(src)
dest = this.limitPluginScope(dest)
await this._handleExists(src, `Cannot move ${src}. Path does not exist.`)
await this._handleExists(dest, `Cannot move content into ${dest}. Path does not exist.`)
await this._handleIsFile(src, `Cannot move ${src}. Path is not a file.`)
await this._handleIsDir(dest, `Cannot move content into ${dest}. Path is not directory.`)
const fileName = helper.extractNameFromKey(src)
if (await this.exists(dest + '/' + fileName)) {
return false
}
return true
} catch (e) {
console.log(e)
return false
}
}
async moveDirIsAllowed (src: string, dest: string) {
try {
src = this.normalize(src)
dest = this.normalize(dest)
src = this.limitPluginScope(src)
dest = this.limitPluginScope(dest)
await this._handleExists(src, `Cannot move ${src}. Path does not exist.`)
await this._handleExists(dest, `Cannot move content into ${dest}. Path does not exist.`)
await this._handleIsDir(src, `Cannot move ${src}. Path is not directory.`)
await this._handleIsDir(dest, `Cannot move content into ${dest}. Path is not directory.`)
const dirName = helper.extractNameFromKey(src)
if (await this.exists(dest + '/' + dirName) || src === dest) {
return false
}
return true
} catch (e) {
console.log(e)
return false
}
}
/**
* Moves a file to a new folder
* @param {string} src path of the source file

@ -62,7 +62,7 @@ export const Draggable = (props: DraggableType) => {
setTimeout(() => {
props.handleClickFolder(destination.path, destination.type)
setFolderToOpen(null)
}, 500)
}, 600)
)
}
}

@ -514,3 +514,16 @@ export const moveFolder = async (src: string, dest: string) => {
dispatch(displayPopUp('Oops! An error ocurred while performing moveDir operation.' + error))
}
}
export const moveFileIsAllowed = async (src: string, dest: string) => {
const fileManager = plugin.fileManager
const isAllowed = await fileManager.moveFileIsAllowed(src, dest)
return isAllowed
}
export const moveFolderIsAllowed = async (src: string, dest: string) => {
const fileManager = plugin.fileManager
const isAllowed = await fileManager.moveDirIsAllowed(src, dest)
return isAllowed
}

@ -11,6 +11,7 @@ import {checkSpecialChars, extractNameFromKey, extractParentFromKey, joinPath} f
import {FileRender} from './file-render'
import {Drag, Draggable} from '@remix-ui/drag-n-drop'
import {ROOT_PATH} from '../utils/constants'
import { moveFileIsAllowed, moveFolderIsAllowed } from '../actions'
export const FileExplorer = (props: FileExplorerProps) => {
const intl = useIntl()
@ -289,7 +290,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
props.dispatchHandleExpandPath(expandPath)
}
const handleFileMove = (dest: string, src: string) => {
const handleFileMove = async (dest: string, src: string) => {
if(await moveFileIsAllowed(src, dest) === false) return
try {
props.modal(
intl.formatMessage({ id: 'filePanel.moveFile' }),
@ -309,7 +311,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
}
const handleFolderMove = (dest: string, src: string) => {
const handleFolderMove = async (dest: string, src: string) => {
if(await moveFolderIsAllowed(src, dest) === false) return
try {
props.modal(
intl.formatMessage({ id: 'filePanel.moveFile' }),
@ -354,7 +357,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
</span>
</div>
</li>
<div className="pb-4 mb-4">
<div>
<TreeView id="treeViewMenu">
{files[ROOT_PATH] &&
Object.keys(files[ROOT_PATH]).map((key, index) => (
@ -378,6 +381,9 @@ export const FileExplorer = (props: FileExplorerProps) => {
))}
</TreeView>
</div>
<Draggable isDraggable={false} file={{ name: '/', path: '/', type: 'folder', isDirectory: true }} expandedPath={props.expandPath} handleClickFolder={null}>
<div className='d-block w-100 pb-4 mb-4'></div>
</Draggable>
</TreeView>
</div>
</Drag>

Loading…
Cancel
Save