Skip to content

Commit

Permalink
refactor(sanity): rename StudioFormBuilderProvider and related (#3675)
Browse files Browse the repository at this point in the history
* refactor(form): change StudioFormBuilderProvider to FormProvider

* refactor(form): change StudioFormBuilder to FormBuilder

* test(form): fix test
  • Loading branch information
RitaDias authored and mariuslundgard committed Oct 3, 2022
1 parent b55cea0 commit 6cca17e
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
fromMutationPatches,
PatchEvent,
PatchMsg,
StudioFormBuilder,
FormBuilder,
} from '../../../../../form'
import {PresenceOverlay} from '../../../../../presence'
import {
Expand Down Expand Up @@ -180,7 +180,7 @@ export function FormView(props: FormViewProps) {
<Text>This form is hidden</Text>
</Box>
) : (
<StudioFormBuilder
<FormBuilder
__internal_patchChannel={patchChannel}
collapsedFieldSets={collapsedFieldSets}
collapsedPaths={collapsedPaths}
Expand Down
2 changes: 1 addition & 1 deletion packages/sanity/src/form/__workshop__/FormBuilderStory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Card, Container} from '@sanity/ui'
import React, {useCallback, useMemo, useState} from 'react'
import {useUnique} from '../../util'
import {useDocumentOperation, useEditState, useSchema, useValidationStatus} from '../../hooks'
import {StudioFormBuilder} from '../studio/StudioFormBuilder'
import {FormBuilder} from '../studio/FormBuilder'
import {createPatchChannel} from '../patch/PatchChannel'

export default function FormBuilderStory() {
Expand Down
4 changes: 2 additions & 2 deletions packages/sanity/src/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// sanity
export * from './studio/contexts'
export * from './studio/StudioFormBuilder'
export * from './studio/StudioFormBuilderProvider'
export * from './studio/FormBuilder'
export * from './studio/FormProvider'
export * from './studio/focusManagers/HashFocusManager'
export * from './studio/focusManagers/SimpleFocusManager'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function TestForm() {
return <>TODO</>

// return (
// <StudioFormBuilderProvider
// <FormProvider
// __internal_patchChannel={patchChannel}
// onChange={handleChange}
// value={value}
Expand Down Expand Up @@ -130,6 +130,6 @@ function TestForm() {
// validation={validation}
// value={value}
// />
// </StudioFormBuilderProvider>
// </FormProvider>
// )
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {Card, Container, Flex} from '@sanity/ui'
import {useAction} from '@sanity/ui-workshop'
import React, {useMemo, useState} from 'react'
import {useSchema} from '../../../../hooks'
import {StudioFormBuilderProvider} from '../../../studio/StudioFormBuilderProvider'
import {FormProvider} from '../../../studio/FormProvider'
import {ReviewChangesContextProvider} from '../../../studio/contexts/reviewChanges/ReviewChangesProvider'
import {createPatchChannel} from '../../../patch/PatchChannel'

Expand All @@ -26,7 +26,7 @@ export default function ReferenceInputStory() {
<Container width={0}>
<ReviewChangesContextProvider changesOpen={false}>
TODO
{/* <StudioFormBuilderProvider
{/* <FormProvider
__internal_patchChannel={patchChannel}
onChange={onChange}
value={value}
Expand All @@ -43,7 +43,7 @@ export default function ReferenceInputStory() {
validation={[]}
value={undefined}
/>
</StudioFormBuilderProvider> */}
</FormProvider> */}
</ReviewChangesContextProvider>
</Container>
</Flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {createPatchChannel} from '../patch'
import {useFormState} from '../store/useFormState'
import {EMPTY_ARRAY} from '../utils/empty'
import {useWorkspace} from '../../studio'
import {StudioFormBuilder, StudioFormBuilderProps} from './StudioFormBuilder'
import {FormBuilder, FormBuilderProps} from './FormBuilder'

const schemaTypes = [
defineType({
Expand All @@ -27,7 +27,7 @@ const schemaTypes = [
}),
]

describe('StudioFormBuilder', () => {
describe('FormBuilder', () => {
it('should render a studio form', async () => {
const client = createMockSanityClient() as unknown as SanityClient
const TestProvider = await createTestProvider({
Expand Down Expand Up @@ -79,7 +79,7 @@ describe('StudioFormBuilder', () => {
validation: [],
})

const formBuilderProps: StudioFormBuilderProps = useMemo(
const formBuilderProps: FormBuilderProps = useMemo(
() => ({
__internal_patchChannel: patchChannel,
changesOpen: false,
Expand Down Expand Up @@ -109,7 +109,7 @@ describe('StudioFormBuilder', () => {
[formState, patchChannel, schemaType]
)

return <StudioFormBuilder {...formBuilderProps} />
return <FormBuilder {...formBuilderProps} />
}

const result = render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import {ObjectInputProps} from '../types'
import {EMPTY_ARRAY} from '../utils/empty'
import {useFormBuilder} from '../useFormBuilder'
import {StateTree} from '../store'
import {StudioFormBuilderProvider} from './StudioFormBuilderProvider'
import {FormProvider} from './FormProvider'
import {useFormCallbacks} from './contexts/FormCallbacks'

/**
* @alpha
*/
export interface StudioFormBuilderProps
export interface FormBuilderProps
extends Omit<ObjectFormNode, 'level' | 'path' | 'presence' | 'validation'> {
/**
* @internal Considered internal – do not use.
Expand Down Expand Up @@ -47,7 +47,7 @@ export interface StudioFormBuilderProps
/**
* @alpha
*/
export function StudioFormBuilder(props: StudioFormBuilderProps) {
export function FormBuilder(props: FormBuilderProps) {
const {
__internal_patchChannel: patchChannel,
autoFocus,
Expand All @@ -74,7 +74,7 @@ export function StudioFormBuilder(props: StudioFormBuilderProps) {
} = props

return (
<StudioFormBuilderProvider
<FormProvider
__internal_patchChannel={patchChannel}
autoFocus={autoFocus}
changesOpen={changesOpen}
Expand All @@ -99,7 +99,7 @@ export function StudioFormBuilder(props: StudioFormBuilderProps) {
value={value}
>
<RootInput />
</StudioFormBuilderProvider>
</FormProvider>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {FormFieldPresence} from '../../presence'
/**
* @alpha This API might change.
*/
export interface StudioFormBuilderProviderProps {
export interface FormProviderProps {
/**
* @internal Considered internal, do not use.
*/
Expand Down Expand Up @@ -47,7 +47,7 @@ export interface StudioFormBuilderProviderProps {
*
* @alpha This API might change.
*/
export function StudioFormBuilderProvider(props: StudioFormBuilderProviderProps) {
export function FormProvider(props: FormProviderProps) {
const {
__internal_patchChannel: patchChannel,
autoFocus,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`FormBuilder should render a studio form 1`] = `"<div data-ui=\\"Stack\\" data-testid=\\"field-title\\" data-level=\\"0\\"><div data-as=\\"div\\" data-ui=\\"Flex\\"><div data-as=\\"div\\" data-ui=\\"Box\\"><div data-ui=\\"Stack\\"><div data-as=\\"div\\" data-ui=\\"Flex\\"><label data-ui=\\"Text\\"><span>Title</span></label></div></div></div></div><div><div><div data-testid=\\"change-bar-wrapper\\"><div data-testid=\\"change-bar__field-wrapper\\"><span data-as=\\"span\\" data-ui=\\"TextInput\\" data-scheme=\\"light\\" data-tone=\\"default\\"><span><input data-as=\\"input\\" data-scheme=\\"light\\" data-tone=\\"default\\" id=\\"title\\" type=\\"text\\" value=\\"\\"><span data-scheme=\\"light\\" data-tone=\\"default\\"></span></span></span></div></div></div></div></div>"`;

This file was deleted.

6 changes: 3 additions & 3 deletions packages/sanity/test/form/renderInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
NodeValidation,
PatchArg,
PatchEvent,
StudioFormBuilderProvider,
FormProvider,
useFormState,
} from '../../src/form'
import {FormState} from '../../src/form/store/useFormState'
Expand Down Expand Up @@ -130,7 +130,7 @@ export async function renderInput(props: {
const {level, path, readOnly, schemaType} = fieldMember.field

return (
<StudioFormBuilderProvider
<FormProvider
__internal_patchChannel={patchChannel}
changesOpen={false}
collapsedFieldSets={undefined}
Expand Down Expand Up @@ -179,7 +179,7 @@ export async function renderInput(props: {
},
{client, formState}
)}
</StudioFormBuilderProvider>
</FormProvider>
)
}

Expand Down

0 comments on commit 6cca17e

Please sign in to comment.