mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #18174 from overleaf/jdt-file-name-context
[Web] add selectedFileName to context in editor (fileTreeActionable) GitOrigin-RevId: 53bc1a9692cbd6626a44ae8f0cd8ac68d6ce69ae
This commit is contained in:
parent
72b53fe8db
commit
a40c593a21
2 changed files with 14 additions and 17 deletions
|
@ -1,30 +1,14 @@
|
|||
import { useCallback, useMemo } from 'react'
|
||||
import { useCallback } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
||||
import { useProjectContext } from '@/shared/context/project-context'
|
||||
|
||||
import { MenuItem } from 'react-bootstrap'
|
||||
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
||||
import { useFileTreeData } from '@/shared/context/file-tree-data-context'
|
||||
import { useFileTreeSelectable } from '../../contexts/file-tree-selectable'
|
||||
import { findInTree } from '../../util/find-in-tree'
|
||||
|
||||
function FileTreeItemMenuItems() {
|
||||
const { t } = useTranslation()
|
||||
|
||||
const { fileTreeData } = useFileTreeData()
|
||||
const { selectedEntityIds } = useFileTreeSelectable()
|
||||
|
||||
// return the name of the selected file or doc if there is only one selected
|
||||
const selectedFileName = useMemo(() => {
|
||||
if (selectedEntityIds.size === 1) {
|
||||
const [selectedEntityId] = selectedEntityIds
|
||||
const selectedEntity = findInTree(fileTreeData, selectedEntityId)
|
||||
return selectedEntity?.entity?.name
|
||||
}
|
||||
return null
|
||||
}, [fileTreeData, selectedEntityIds])
|
||||
|
||||
const {
|
||||
canRename,
|
||||
canDelete,
|
||||
|
@ -35,6 +19,7 @@ function FileTreeItemMenuItems() {
|
|||
startCreatingDocOrFile,
|
||||
startUploadingDocOrFile,
|
||||
downloadPath,
|
||||
selectedFileName,
|
||||
} = useFileTreeActionable()
|
||||
|
||||
const { owner } = useProjectContext()
|
||||
|
|
|
@ -58,6 +58,7 @@ const FileTreeActionableContext = createContext<
|
|||
canRename: boolean
|
||||
canCreate: boolean
|
||||
parentFolderId: string
|
||||
selectedFileName: string | null
|
||||
isDuplicate: (parentFolderId: string, name: string) => boolean
|
||||
startRenaming: any
|
||||
finishRenaming: any
|
||||
|
@ -386,6 +387,16 @@ export const FileTreeActionableProvider: FC<{
|
|||
)
|
||||
}, [fileTreeData, selectedEntityIds, isRootFolderSelected])
|
||||
|
||||
// return the name of the selected file or doc if there is only one selected
|
||||
const selectedFileName = useMemo(() => {
|
||||
if (selectedEntityIds.size === 1) {
|
||||
const [selectedEntityId] = selectedEntityIds
|
||||
const selectedEntity = findInTree(fileTreeData, selectedEntityId)
|
||||
return selectedEntity?.entity?.name
|
||||
}
|
||||
return null
|
||||
}, [fileTreeData, selectedEntityIds])
|
||||
|
||||
const finishCreatingEntity = useCallback(
|
||||
entity => {
|
||||
const error = validateCreate(fileTreeData, parentFolderId, entity)
|
||||
|
@ -498,6 +509,7 @@ export const FileTreeActionableProvider: FC<{
|
|||
canCreate: selectedEntityIds.size < 2,
|
||||
...state,
|
||||
parentFolderId,
|
||||
selectedFileName,
|
||||
isDuplicate,
|
||||
startRenaming,
|
||||
finishRenaming,
|
||||
|
|
Loading…
Reference in a new issue