Files
Verso/services/web/frontend/js/features/file-tree/components/file-tree-item/file-tree-item-menu.tsx
T
claude ff7de70a61
Build and Deploy Verso / deploy (push) Successful in 21m44s
fix: per-file convert — DuplicateNameError + first-click no-op
Two bugs:
1. Converting when output already exists threw DuplicateNameError (400).
   Now overwrites existing doc via setDocument instead of failing.

2. Right-clicking an unselected file left contextMenuEntityId null,
   so the first click on Convert silently did nothing. Added
   contextMenuEntityId to FileTreeMainContext, set it on right-click
   and on the … button click; FileTreeItemMenuItems now uses it for
   the convert hooks rather than relying on selectedEntityIds.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-17 20:35:50 +00:00

46 lines
1.4 KiB
TypeScript

import { useRef } from 'react'
import { useTranslation } from 'react-i18next'
import { useFileTreeMainContext } from '../../contexts/file-tree-main'
import MaterialIcon from '@/shared/components/material-icon'
function FileTreeItemMenu({ id, name }: { id: string; name: string }) {
const { t } = useTranslation()
const { contextMenuCoords, setContextMenuCoords, setContextMenuEntityId } =
useFileTreeMainContext()
const menuButtonRef = useRef<HTMLButtonElement>(null)
const isMenuOpen = Boolean(contextMenuCoords)
function handleClick(event: React.MouseEvent) {
event.stopPropagation()
if (!contextMenuCoords && menuButtonRef.current) {
setContextMenuEntityId(id)
const target = menuButtonRef.current.getBoundingClientRect()
setContextMenuCoords({
top: target.top + target.height / 2,
left: target.right,
})
} else {
setContextMenuCoords(null)
}
}
return (
<div className="menu-button btn-group">
<button
className="entity-menu-toggle btn btn-sm"
id={`menu-button-${id}`}
onClick={handleClick}
ref={menuButtonRef}
aria-haspopup="true"
aria-expanded={isMenuOpen}
aria-label={t('open_action_menu', { name })}
>
<MaterialIcon type="more_vert" accessibilityLabel={t('menu')} />
</button>
</div>
)
}
export default FileTreeItemMenu