pull/5370/head
yann300 7 months ago committed by Joseph Izang
parent 803ffb612e
commit 215d356972
  1. 4
      apps/remix-ide-e2e/src/tests/file_explorer_multiselect.test.ts
  2. 39
      libs/remix-ui/workspace/src/lib/components/flat-tree-drop.tsx
  3. 1
      libs/remix-ui/workspace/src/lib/components/flat-tree.tsx

@ -23,7 +23,7 @@ module.exports = {
.assert.visible('.bg-secondary[data-id="treeViewLitreeViewItemcontracts/2_Owner.sol"]') .assert.visible('.bg-secondary[data-id="treeViewLitreeViewItemcontracts/2_Owner.sol"]')
.assert.visible('.bg-secondary[data-id="treeViewLitreeViewItemtests"]') .assert.visible('.bg-secondary[data-id="treeViewLitreeViewItemtests"]')
}, },
'Should select multiple items in file explorer to tests folder #group1': function (browser: NightwatchBrowser) { 'Should drag and drop multiple files in file explorer to tests folder #group1': function (browser: NightwatchBrowser) {
const selectedElements = [] const selectedElements = []
browser browser
.click({ selector: '//*[@data-id="treeViewLitreeViewItemcontracts/1_Storage.sol"]', locateStrategy: 'xpath' }) .click({ selector: '//*[@data-id="treeViewLitreeViewItemcontracts/1_Storage.sol"]', locateStrategy: 'xpath' })
@ -45,7 +45,7 @@ module.exports = {
.waitForElementNotPresent('li[data-id="treeViewLitreeViewItemcontracts/2_Owner.sol"]') .waitForElementNotPresent('li[data-id="treeViewLitreeViewItemcontracts/2_Owner.sol"]')
}) })
}, },
'should select multiple files and folders in file explorer to contracts folder #group1': function (browser: NightwatchBrowser) { 'should drag and drop multiple files and folders in file explorer to contracts folder #group1': function (browser: NightwatchBrowser) {
const selectedElements = [] const selectedElements = []
browser browser
.click({ selector: '//*[@data-id="treeViewLitreeViewItemtests"]', locateStrategy: 'xpath' }) .click({ selector: '//*[@data-id="treeViewLitreeViewItemtests"]', locateStrategy: 'xpath' })

@ -4,8 +4,6 @@ import { buildMultiSelectedItemProfiles, getEventTarget } from '../utils/getEven
import { extractParentFromKey } from '@remix-ui/helper' import { extractParentFromKey } from '@remix-ui/helper'
import { FileSystemContext } from '../contexts' import { FileSystemContext } from '../contexts'
export const FlatTreeDrop = (props: FlatTreeDropProps) => { export const FlatTreeDrop = (props: FlatTreeDropProps) => {
const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props const { getFlatTreeItem, dragSource, handleClickFolder, expandPath } = props
@ -13,9 +11,6 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
const [timer, setTimer] = useState<NodeJS.Timeout>() const [timer, setTimer] = useState<NodeJS.Timeout>()
// folder to open // folder to open
const [folderToOpen, setFolderToOpen] = useState<string>() const [folderToOpen, setFolderToOpen] = useState<string>()
const globalFEContext = useContext(FileSystemContext)
const [selectedItems, setSelectedItems] = useState<DragStructure[]>([])
const onDragOver = async (e: SyntheticEvent) => { const onDragOver = async (e: SyntheticEvent) => {
e.preventDefault() e.preventDefault()
@ -66,23 +61,12 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
props.setFilesSelected(filePaths) props.setFilesSelected(filePaths)
if (dragDestination.isDirectory) { if (dragDestination.isDirectory) {
if (dragSource.isDirectory) {
await props.warnMovingItems(filePaths, dragDestination.path) await props.warnMovingItems(filePaths, dragDestination.path)
await moveFoldersSilently(props.selectedItems, dragDestination.path) await moveItemsSilently(props.selectedItems, dragDestination.path)
} else {
await props.warnMovingItems(filePaths, dragDestination.path)
await moveFilesSilently(props.selectedItems, dragDestination.path)
}
} else { } else {
const path = extractParentFromKey(dragDestination.path) || '/' const path = extractParentFromKey(dragDestination.path) || '/'
if (dragSource.isDirectory) {
await props.warnMovingItems(filePaths, path)
await moveFoldersSilently(props.selectedItems, path)
} else {
await props.warnMovingItems(filePaths, path) await props.warnMovingItems(filePaths, path)
await moveFilesSilently(props.selectedItems, path) await moveItemsSilently(props.selectedItems, path)
}
} }
} }
@ -92,33 +76,18 @@ export const FlatTreeDrop = (props: FlatTreeDropProps) => {
* @param dragSource source FileExplorer item being dragged. * @param dragSource source FileExplorer item being dragged.
* @returns Promise<void> * @returns Promise<void>
*/ */
const moveFilesSilently = async (items: DragStructure[], targetPath: string) => { const moveItemsSilently = async (items: DragStructure[], targetPath: string) => {
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') {
await props.moveFileSilently(targetPath, item.path) await props.moveFileSilently(targetPath, item.path)
} } else if (item.type === 'folder') {
})
await Promise.all(promises)
}
/**
* Moves items silently without showing a confirmation dialog.
* @param items MultiSelected items built into a DragStructure profile
* @param dragSource source FileExplorer item being dragged.
* @returns Promise<void>
*/
const moveFoldersSilently = async (items: DragStructure[], targetPath: string) => {
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) await Promise.all(promises)
} }
return (<div return (<div
onDrop={onDrop} onDragOver={onDragOver} onDrop={onDrop} onDragOver={onDragOver}
className="d-flex h-100" className="d-flex h-100"

@ -72,7 +72,6 @@ export const FlatTree = (props: FlatTreeProps) => {
const virtuoso = useRef<VirtuosoHandle>(null) const virtuoso = useRef<VirtuosoHandle>(null)
const [selectedItems, setSelectedItems] = useState<DragStructure[]>([]) const [selectedItems, setSelectedItems] = useState<DragStructure[]>([])
const labelClass = (file: FileType) => const labelClass = (file: FileType) =>
props.focusEdit.element === file.path props.focusEdit.element === file.path
? 'bg-light' ? 'bg-light'

Loading…
Cancel
Save