Skip to content

Commit

Permalink
chore(form): remove imports from shouldArrayDialogOpen (#7550)
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias authored Sep 30, 2024
1 parent 7fcf22a commit bdfd8df
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 181 deletions.
15 changes: 2 additions & 13 deletions packages/sanity/src/core/form/studio/FormBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ import {
import {DocumentFieldActionsProvider} from './contexts/DocumentFieldActions'
import {FormBuilderInputErrorBoundary} from './FormBuilderInputErrorBoundary'
import {FormProvider} from './FormProvider'
import {
shouldArrayDialogOpen,
TreeEditingDialog,
TreeEditingEnabledProvider,
useTreeEditingEnabled,
} from './tree-editing'
import {TreeEditingDialog, TreeEditingEnabledProvider, useTreeEditingEnabled} from './tree-editing'

/**
* @alpha
Expand Down Expand Up @@ -307,15 +302,9 @@ interface RootInputProps {
function RootInput(props: RootInputProps) {
const {rootInputProps, onPathOpen, openPath, renderInput} = props
const treeEditing = useTreeEditingEnabled()

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

const isRoot = rootInputProps.id === 'root'

const arrayEditingModal = treeEditing.enabled && isRoot && open && (
const arrayEditingModal = treeEditing.enabled && isRoot && (
<TreeEditingDialog
// eslint-disable-next-line react/jsx-handler-names
onPathFocus={rootInputProps.onPathFocus}
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/core/form/studio/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ export * from './defaults'
export * from './FormBuilder'
export * from './FormProvider'
export * from './inputs'
export {shouldArrayDialogOpen, useTreeEditingEnabled} from './tree-editing'
export {useTreeEditingEnabled} from './tree-editing'
export * from './uploads'

This file was deleted.

1 change: 0 additions & 1 deletion packages/sanity/src/core/form/studio/tree-editing/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './components'
export * from './context'
export * from './hooks'
export {shouldArrayDialogOpen} from './utils'
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './build-tree-editing-state'
export * from './findArrayTypePaths'
export * from './getSchemaField'
export * from './shouldArrayDialogOpen'

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
type DocumentActionComponent,
type DocumentActionDescription,
Hotkeys,
shouldArrayDialogOpen,
useSource,
useTimelineSelector,
} from 'sanity'

Expand All @@ -27,17 +25,9 @@ const DocumentStatusBarActionsInner = memo(function DocumentStatusBarActionsInne
props: DocumentStatusBarActionsInnerProps,
) {
const {disabled, showMenu, states} = props
const {__internal_tasks, schemaType, openPath} = useDocumentPane()
const {__internal_tasks} = useDocumentPane()
const [firstActionState, ...menuActionStates] = states
const [buttonElement, setButtonElement] = useState<HTMLButtonElement | null>(null)
const isTreeArrayEditingEnabled = useSource().beta?.treeArrayEditing?.enabled

// Disable the main document action if the array dialog is open
const isTreeArrayEditingEnabledOpen = useMemo(() => {
if (!isTreeArrayEditingEnabled) return false

return shouldArrayDialogOpen(schemaType, openPath)
}, [isTreeArrayEditingEnabled, openPath, schemaType])

// TODO: This could be refactored to use the tooltip from the button if the firstAction.title was updated to a string.
const tooltipContent = useMemo(() => {
Expand Down Expand Up @@ -69,9 +59,7 @@ const DocumentStatusBarActionsInner = memo(function DocumentStatusBarActionsInne
<Stack>
<Button
data-testid={`action-${firstActionState.label}`}
disabled={
disabled || Boolean(firstActionState.disabled) || isTreeArrayEditingEnabledOpen
}
disabled={disabled || Boolean(firstActionState.disabled)}
icon={firstActionState.icon}
// eslint-disable-next-line react/jsx-handler-names
onClick={firstActionState.onHandle}
Expand Down

0 comments on commit bdfd8df

Please sign in to comment.