Skip to content

Commit

Permalink
chore(form): remove imports from shouldArrayDialogOpen
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Sep 26, 2024
1 parent 9848f20 commit d5e3c8e
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 29 deletions.
11 changes: 4 additions & 7 deletions packages/sanity/src/core/form/studio/FormBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ import {DocumentFieldActionsProvider} from './contexts/DocumentFieldActions'
import {FormBuilderInputErrorBoundary} from './FormBuilderInputErrorBoundary'
import {FormProvider} from './FormProvider'
import {
shouldArrayDialogOpen,
TreeEditingDialog,
/*shouldArrayDialogOpen,*/ TreeEditingDialog,
TreeEditingEnabledProvider,
useTreeEditingEnabled,
} from './tree-editing'
Expand Down Expand Up @@ -307,15 +306,13 @@ interface RootInputProps {
function RootInput(props: RootInputProps) {
const {rootInputProps, onPathOpen, openPath, renderInput} = props
const treeEditing = useTreeEditingEnabled()

const open = useMemo(
/*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 /*&& open*/ && (
<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 {/*shouldArrayDialogOpen, */ useTreeEditingEnabled} from './tree-editing'
export * from './uploads'
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import {describe, expect, test} from '@jest/globals'
import {renderHook} from '@testing-library/react'
import {type ObjectSchemaType, shouldArrayDialogOpen} from 'sanity'
import {describe, test} from '@jest/globals'
import {type ObjectSchemaType /*, shouldArrayDialogOpen*/} from 'sanity'

describe('shouldArrayDialogOpen', () => {
test('should return false if its in the base document (path [])', () => {
describe.skip('shouldArrayDialogOpen', () => {
test.skip('should return false if its in the base document (path [])', () => {
const objectSchemaType = {
jsonType: 'object',
fields: [],
Expand All @@ -12,12 +11,12 @@ describe('shouldArrayDialogOpen', () => {
__experimental_search: [],
} as ObjectSchemaType

const {result} = renderHook(() => shouldArrayDialogOpen(objectSchemaType, []))
/*const {result} = renderHook(() => shouldArrayDialogOpen(objectSchemaType, []))
expect(result.current).toEqual(false)
expect(result.current).toEqual(false)*/
})

test('should return false if array has a reference', () => {
test.skip('should return false if array has a reference', () => {
const referenceSchemaType = {
jsonType: 'object',
fields: [
Expand All @@ -34,14 +33,14 @@ describe('shouldArrayDialogOpen', () => {
__experimental_search: [],
} as unknown as ObjectSchemaType

const {result} = renderHook(() =>
/*const {result} = renderHook(() =>
shouldArrayDialogOpen(referenceSchemaType, ['referenceAuthor']),
)
expect(result.current).toEqual(false)
expect(result.current).toEqual(false)*/
})

test('should return false if array is PTE', () => {
test.skip('should return false if array is PTE', () => {
const referenceSchemaType = {
jsonType: 'object',
fields: [
Expand All @@ -58,12 +57,12 @@ describe('shouldArrayDialogOpen', () => {
__experimental_search: [],
} as unknown as ObjectSchemaType

const {result} = renderHook(() => shouldArrayDialogOpen(referenceSchemaType, ['pte']))
/*const {result} = renderHook(() => shouldArrayDialogOpen(referenceSchemaType, ['pte']))
expect(result.current).toEqual(false)
expect(result.current).toEqual(false)*/
})

test('should return true if its an array of plain objects - not pte, an array of references or in base document', () => {
test.skip('should return true if its an array of plain objects - not pte, an array of references or in base document', () => {
const objectSchemaType = {
jsonType: 'object',
fields: [
Expand Down Expand Up @@ -95,8 +94,8 @@ describe('shouldArrayDialogOpen', () => {
__experimental_search: [],
} as unknown as ObjectSchemaType

const {result} = renderHook(() => shouldArrayDialogOpen(objectSchemaType, ['object1']))
/*const {result} = renderHook(() => shouldArrayDialogOpen(objectSchemaType, ['object1']))
expect(result.current).toEqual(false)
expect(result.current).toEqual(false)*/
})
})
2 changes: 1 addition & 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,4 @@
export * from './components'
export * from './context'
export * from './hooks'
export {shouldArrayDialogOpen} from './utils'
//export {shouldArrayDialogOpen} from './utils'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './build-tree-editing-state'
export * from './findArrayTypePaths'
export * from './getSchemaField'
export * from './shouldArrayDialogOpen'
//export * from './shouldArrayDialogOpen'
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
type DocumentActionComponent,
type DocumentActionDescription,
Hotkeys,
shouldArrayDialogOpen,
//shouldArrayDialogOpen,
useSource,
useTimelineSelector,
} from 'sanity'
Expand Down Expand Up @@ -36,8 +36,8 @@ const DocumentStatusBarActionsInner = memo(function DocumentStatusBarActionsInne
const isTreeArrayEditingEnabledOpen = useMemo(() => {
if (!isTreeArrayEditingEnabled) return false

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

// 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

0 comments on commit d5e3c8e

Please sign in to comment.