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 { useTranslation } from 'react-i18next'
|
||||||
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
import * as eventTracking from '../../../../infrastructure/event-tracking'
|
||||||
import { useProjectContext } from '@/shared/context/project-context'
|
import { useProjectContext } from '@/shared/context/project-context'
|
||||||
|
|
||||||
import { MenuItem } from 'react-bootstrap'
|
import { MenuItem } from 'react-bootstrap'
|
||||||
import { useFileTreeActionable } from '../../contexts/file-tree-actionable'
|
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() {
|
function FileTreeItemMenuItems() {
|
||||||
const { t } = useTranslation()
|
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 {
|
const {
|
||||||
canRename,
|
canRename,
|
||||||
canDelete,
|
canDelete,
|
||||||
|
@ -35,6 +19,7 @@ function FileTreeItemMenuItems() {
|
||||||
startCreatingDocOrFile,
|
startCreatingDocOrFile,
|
||||||
startUploadingDocOrFile,
|
startUploadingDocOrFile,
|
||||||
downloadPath,
|
downloadPath,
|
||||||
|
selectedFileName,
|
||||||
} = useFileTreeActionable()
|
} = useFileTreeActionable()
|
||||||
|
|
||||||
const { owner } = useProjectContext()
|
const { owner } = useProjectContext()
|
||||||
|
|
|
@ -58,6 +58,7 @@ const FileTreeActionableContext = createContext<
|
||||||
canRename: boolean
|
canRename: boolean
|
||||||
canCreate: boolean
|
canCreate: boolean
|
||||||
parentFolderId: string
|
parentFolderId: string
|
||||||
|
selectedFileName: string | null
|
||||||
isDuplicate: (parentFolderId: string, name: string) => boolean
|
isDuplicate: (parentFolderId: string, name: string) => boolean
|
||||||
startRenaming: any
|
startRenaming: any
|
||||||
finishRenaming: any
|
finishRenaming: any
|
||||||
|
@ -386,6 +387,16 @@ export const FileTreeActionableProvider: FC<{
|
||||||
)
|
)
|
||||||
}, [fileTreeData, selectedEntityIds, isRootFolderSelected])
|
}, [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(
|
const finishCreatingEntity = useCallback(
|
||||||
entity => {
|
entity => {
|
||||||
const error = validateCreate(fileTreeData, parentFolderId, entity)
|
const error = validateCreate(fileTreeData, parentFolderId, entity)
|
||||||
|
@ -498,6 +509,7 @@ export const FileTreeActionableProvider: FC<{
|
||||||
canCreate: selectedEntityIds.size < 2,
|
canCreate: selectedEntityIds.size < 2,
|
||||||
...state,
|
...state,
|
||||||
parentFolderId,
|
parentFolderId,
|
||||||
|
selectedFileName,
|
||||||
isDuplicate,
|
isDuplicate,
|
||||||
startRenaming,
|
startRenaming,
|
||||||
finishRenaming,
|
finishRenaming,
|
||||||
|
|
Loading…
Reference in a new issue