Skip to content

Commit

Permalink
chore(example): upgrade @sanity/sanitype dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Nov 12, 2024
1 parent e595887 commit 5593b18
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
5 changes: 4 additions & 1 deletion examples/web/lib/form/FormNode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
getInstanceName,
type Infer,
isDocumentSchema,
isNeverSchema,
isObjectSchema,
isObjectUnionSchema,
isOptionalSchema,
Expand Down Expand Up @@ -74,7 +75,9 @@ function resolveNode<Schema extends SanityType>(

if (isObjectUnionSchema(schema)) {
const type = value?._type
const valueType = schema.union.find(ut => getInstanceName(ut) === type)!
const valueType = schema.union.find(
ut => !isNeverSchema(ut) && getInstanceName(ut) === type,
)!
const typeForm = (
(form as ObjectUnionFormDef<SanityTypedObject>).types as any
)[type]
Expand Down
14 changes: 10 additions & 4 deletions examples/web/lib/form/inputs/UnionInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {EllipsisVerticalIcon, TransferIcon, TrashIcon} from '@sanity/icons'
import {assign, at, set, unset} from '@sanity/mutate'
import {
getInstanceName,
isNeverSchema,
isObjectSchema,
type ObjectUnionFormDef,
pickDeep,
Expand Down Expand Up @@ -39,7 +40,9 @@ export function UnionInput(props: InputProps<SanityObjectUnion>) {
const valueTypeName = value?._type

const currentSchema = valueTypeName
? schema.union.find(ut => getInstanceName(ut) === valueTypeName)
? schema.union.find(
ut => !isNeverSchema(ut) && getInstanceName(ut) === valueTypeName,
)
: undefined

const handlePatch = useCallback(
Expand All @@ -56,7 +59,7 @@ export function UnionInput(props: InputProps<SanityObjectUnion>) {
const handleTurnInto = useCallback(
(nextTypeName: string) => {
const nextSchema = schema.union.find(
ut => getInstanceName(ut) === nextTypeName,
ut => !isNeverSchema(ut) && getInstanceName(ut) === nextTypeName,
)
if (!nextSchema) {
throw new Error(`No valid union type named ${nextTypeName}.`)
Expand All @@ -74,7 +77,7 @@ export function UnionInput(props: InputProps<SanityObjectUnion>) {
const handleSelectType = useCallback(
(nextTypeName: string) => {
const nextSchema = schema.union.find(
ut => getInstanceName(ut) === nextTypeName,
ut => !isNeverSchema(ut) && getInstanceName(ut) === nextTypeName,
)
if (!nextSchema) {
throw new Error(`No valid union type named ${nextTypeName}.`)
Expand All @@ -99,7 +102,7 @@ export function UnionInput(props: InputProps<SanityObjectUnion>) {
<Select onChange={e => handleSelectType(e.currentTarget.value)}>
<option value="">Select type</option>
{schema.union.map(ut => {
const name = getInstanceName(ut)
const name = !isNeverSchema(ut) && getInstanceName(ut)
if (!name || !(name in form.types)) {
throw new Error(`No form definition found for type ${name}`)
}
Expand Down Expand Up @@ -143,6 +146,9 @@ export function UnionInput(props: InputProps<SanityObjectUnion>) {
text="Turn into…"
>
{otherTypes.map(type => {
if (isNeverSchema(type)) {
return null
}
const sharedProperties = intersection(
Object.keys(type.shape),
Object.keys(currentSchema.shape),
Expand Down
2 changes: 1 addition & 1 deletion examples/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@sanity/client": "^6.21.1",
"@sanity/icons": "^3.3.1",
"@sanity/mutate": "workspace:",
"@sanity/sanitype": "^0.4.0",
"@sanity/sanitype": "^0.6.1",
"@sanity/ui": "^2.8.8",
"dataloader": "^2.2.2",
"groq-js": "^1.12.0",
Expand Down
18 changes: 9 additions & 9 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5593b18

Please sign in to comment.