Skip to content

Commit

Permalink
(sanity): add fix to ImageInput and TreeEditingDialog to use openPath
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Jun 24, 2024
1 parent af40db2 commit 3e33987
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {Stack, useToast} from '@sanity/ui'
import {get} from 'lodash'
import {type FocusEvent, memo, type ReactNode, useCallback, useMemo, useRef, useState} from 'react'
import {type Subscription} from 'rxjs'
import {shouldArrayDialogOpen} from 'sanity'
import {useDocumentPane} from 'sanity/structure'

import {useTranslation} from '../../../../i18n'
import {FormInput} from '../../../components'
Expand Down Expand Up @@ -65,6 +67,8 @@ function BaseImageInputComponent(props: BaseImageInputProps): JSX.Element {
const [menuButtonElement, setMenuButtonElement] = useState<HTMLButtonElement | null>(null)
const [isMenuOpen, setMenuOpen] = useState(false)

const {schemaType: documentSchemaType} = useDocumentPane()

const uploadSubscription = useRef<null | Subscription>(null)

/**
Expand Down Expand Up @@ -260,12 +264,15 @@ function BaseImageInputComponent(props: BaseImageInputProps): JSX.Element {
// Background: https://github.com/facebook/react/issues/6410#issuecomment-671915381
if (
event.currentTarget === event.target &&
event.currentTarget === elementProps.ref?.current
event.currentTarget === elementProps.ref?.current &&
// when opening the array editing dialog, we don't want to focus to be on the element itself
// (the array) vs the item itself
!shouldArrayDialogOpen(documentSchemaType, path)
) {
elementProps.onFocus(event)
}
},
[elementProps],
[elementProps, path, documentSchemaType],
)
const handleFilesOver = useCallback((nextHoveringFiles: FileInfo[]) => {
setHoveringFiles(nextHoveringFiles.filter((file) => file.kind !== 'string'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,7 @@ export function TreeEditingDialog(props: TreeEditingDialogProps): JSX.Element |
openPathRef.current = undefined
}, [debouncedBuildTreeEditingState, onPathOpen])

// if the path is outside of the current window, we want to use the openPath
const pathToUse = openPath.some((path) => treeState.relativePath.includes(path))
? treeState.relativePath
: openPath

const open = useMemo(() => shouldArrayDialogOpen(schemaType, pathToUse), [schemaType, pathToUse])
const open = useMemo(() => shouldArrayDialogOpen(schemaType, openPath), [schemaType, openPath])

const onHandlePathSelect = useCallback(
(path: Path) => {
Expand Down

0 comments on commit 3e33987

Please sign in to comment.