Skip to content

Commit

Permalink
chore(test-studio): add debug schema for patch-on-mount
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Jan 6, 2025
1 parent 504337e commit 3918d6a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
30 changes: 30 additions & 0 deletions dev/test-studio/schema/debug/patchOnMount.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {defineType} from '@sanity/types'
import {useEffect, useRef} from 'react'
import {set} from 'sanity'

export const patchOnMountDebug = defineType({
type: 'document',
name: 'patchOnMountDebug',
fields: [
{
type: 'string',
name: 'title',
},
],
components: {
// eslint-disable-next-line func-name-matching
input: function PatchOnMountInput(props) {
const {onChange} = props
const mounted = useRef(false)

useEffect(() => {
if (!mounted.current) {
onChange(set(`${Math.random()}`, ['title']))
mounted.current = true
}
}, [onChange])

return props.renderDefault(props)
},
},
})
2 changes: 2 additions & 0 deletions dev/test-studio/schema/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import localeString from './debug/localeString'
import manyFieldsTest from './debug/manyFieldsTest'
import notitle from './debug/notitle'
import {objectsDebug} from './debug/objectsDebug'
import {patchOnMountDebug} from './debug/patchOnMount'
import poppers from './debug/poppers'
import presence, {objectWithNestedArray} from './debug/presence'
import previewImageUrlTest from './debug/previewImageUrlTest'
Expand Down Expand Up @@ -238,6 +239,7 @@ export const schemaTypes = [
recursiveObjectTest,
recursiveObject,
recursivePopover,
patchOnMountDebug,
simpleArrayOfObjects,
simpleReferences,
reservedFieldNames,
Expand Down
1 change: 1 addition & 0 deletions dev/test-studio/structure/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const DEBUG_INPUT_TYPES = [
'fieldsetsTest',
'fieldValidationInferReproDoc',
'focusTest',
'patchOnMountDebug',
'formInputDebug',
'initialValuesTest',
'inspectorsTest',
Expand Down

0 comments on commit 3918d6a

Please sign in to comment.