1
0
Fork 0
mirror of https://github.com/overleaf/overleaf.git synced 2025-04-17 12:39:15 +00:00

Merge pull request from overleaf/ae-file-tree-menu-multiple-selection

Only show the file tree item menu when a single item is selected

GitOrigin-RevId: fe98ffb4627beba376b20432a1d489eeeadc520b
This commit is contained in:
Alf Eaton 2021-06-03 14:45:05 +01:00 committed by Copybot
parent 30efdae9c5
commit 35770f50ca
2 changed files with 65 additions and 1 deletions
services/web
frontend/js/features/file-tree/components/file-tree-item
test/frontend/features/file-tree/components

View file

@ -8,11 +8,15 @@ import { useDraggable } from '../../contexts/file-tree-draggable'
import FileTreeItemName from './file-tree-item-name'
import FileTreeItemMenu from './file-tree-item-menu'
import { useFileTreeSelectable } from '../../contexts/file-tree-selectable'
function FileTreeItemInner({ id, name, isSelected, icons }) {
const { hasWritePermissions, setContextMenuCoords } = useFileTreeMainContext()
const hasMenu = hasWritePermissions && isSelected
const { selectedEntityIds } = useFileTreeSelectable()
const hasMenu =
hasWritePermissions && isSelected && selectedEntityIds.size === 1
const { isDragging, dragRef, isDraggable, setIsDraggable } = useDraggable(id)

View file

@ -227,4 +227,64 @@ describe('<FileTreeRoot/>', function () {
screen.getByRole('treeitem', { name: 'main.tex', selected: false })
screen.getByRole('treeitem', { name: 'other.tex', selected: true })
})
it('only shows a menu button when a single item is selected', function () {
const rootFolder = [
{
_id: 'root-folder-id',
docs: [
{ _id: '456def', name: 'main.tex' },
{ _id: '789ghi', name: 'other.tex' },
],
folders: [],
fileRefs: [],
},
]
renderWithEditorContext(
<FileTreeRoot
rootFolder={rootFolder}
projectId="123abc"
rootDocId="456def"
hasWritePermissions
userHasFeature={() => true}
refProviders={{}}
reindexReferences={() => null}
setRefProviderEnabled={() => null}
setStartedFreeTrial={() => null}
onSelect={onSelect}
onInit={onInit}
isConnected
/>
)
const main = screen.getByRole('treeitem', {
name: 'main.tex',
selected: true,
})
const other = screen.getByRole('treeitem', {
name: 'other.tex',
selected: false,
})
// single item selected: menu button is visible
expect(screen.queryAllByRole('button', { name: 'Menu' })).to.have.length(1)
// select the other item
fireEvent.click(other)
screen.getByRole('treeitem', { name: 'main.tex', selected: false })
screen.getByRole('treeitem', { name: 'other.tex', selected: true })
// single item selected: menu button is visible
expect(screen.queryAllByRole('button', { name: 'Menu' })).to.have.length(1)
// multi-select the main item
fireEvent.click(main, { ctrlKey: true })
screen.getByRole('treeitem', { name: 'main.tex', selected: true })
screen.getByRole('treeitem', { name: 'other.tex', selected: true })
// multiple items selected: no menu button is visible
expect(screen.queryAllByRole('button', { name: 'Menu' })).to.have.length(0)
})
})