Skip to content

Commit

Permalink
fix: removes Start in Create when type is Create excluded
Browse files Browse the repository at this point in the history
  • Loading branch information
snorrees committed Oct 20, 2024
1 parent 82ef32f commit cbd4574
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 32 deletions.
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/reference/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {type SanityClient} from '@sanity/client'

import {type SanityDocument} from '../documents'
import {type Path} from '../paths'
import {type BaseOptions} from '../schema'
import {type BaseSchemaTypeOptions} from '../schema'

/** @public */
export interface Reference {
Expand Down Expand Up @@ -57,7 +57,7 @@ export interface ReferenceFilterQueryOptions {
}

/** @public */
export interface ReferenceBaseOptions extends BaseOptions {
export interface ReferenceBaseOptions extends BaseSchemaTypeOptions {
disableNew?: boolean
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ import {
type TypeAliasDefinition,
} from '../schemaDefinition'
import {
type BaseOptions,
type BaseSchemaDefinition,
type BaseSchemaTypeOptions,
type SearchConfiguration,
type TitledListValue,
} from './common'

export type {InsertMenuOptions}

/** @public */
export interface ArrayOptions<V = unknown> extends SearchConfiguration, BaseOptions {
export interface ArrayOptions<V = unknown> extends SearchConfiguration, BaseSchemaTypeOptions {
list?: TitledListValue<V>[] | V[]
// inferring the array.of value for ArrayDefinition cause too much code-noise and was removed.
// Since we don't have the type-info needed here, we allow values
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import {type ComponentType, type ReactNode} from 'react'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type ArrayOfType} from './array'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'
import {type ObjectDefinition} from './object'

/**
* Schema options for a Block schema definition
* @public */
export interface BlockOptions extends BaseOptions {
export interface BlockOptions extends BaseSchemaTypeOptions {
/**
* Turn on or off the builtin browser spellchecking. Default is on.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/boolean.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
export interface BooleanOptions extends BaseOptions {
export interface BooleanOptions extends BaseSchemaTypeOptions {
layout?: 'switch' | 'checkbox'
}

Expand Down
6 changes: 3 additions & 3 deletions packages/@sanity/types/src/schema/definition/type/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export type FieldGroupDefinition = {
/**
* Options for configuring how Sanity Create interfaces with the type or field.
*/
export interface SanityCreateTypeOptions {
export interface SanityCreateOptions {
/** Set to true to exclude a type or field from appearing in Sanity Create */
exclude?: boolean
}
Expand All @@ -39,8 +39,8 @@ export interface SanityCreateTypeOptions {
*
* @public
* */
export interface BaseOptions {
sanityCreate?: SanityCreateTypeOptions
export interface BaseSchemaTypeOptions {
sanityCreate?: SanityCreateOptions
}

/** @public */
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/date.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {type FieldReference} from '../../../validation'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
export interface DateOptions extends BaseOptions {
export interface DateOptions extends BaseSchemaTypeOptions {
dateFormat?: string
}

Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/datetime.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {type FieldReference} from '../../../validation'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
export interface DatetimeOptions extends BaseOptions {
export interface DatetimeOptions extends BaseSchemaTypeOptions {
dateFormat?: string
timeFormat?: string
timeStep?: number
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/document.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type SanityDocument} from '../../../documents/types'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty, type SortOrdering} from '../../types'
import {type BaseOptions} from './common'
import {type BaseSchemaTypeOptions} from './common'
import {type ObjectDefinition} from './object'

/**
Expand All @@ -10,7 +10,7 @@ import {type ObjectDefinition} from './object'
* @public
*/
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface DocumentOptions extends BaseOptions {}
export interface DocumentOptions extends BaseSchemaTypeOptions {}

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/email.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
Expand All @@ -9,7 +9,7 @@ export interface EmailRule extends RuleDef<EmailRule, string> {}
/** @public */
// only exists to support declaration extensions
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface EmailOptions extends BaseOptions {}
export interface EmailOptions extends BaseSchemaTypeOptions {}

/** @public */
export interface EmailDefinition extends BaseSchemaDefinition {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/geopoint.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/**
* Geographical point representing a pair of latitude and longitude coordinates,
Expand Down Expand Up @@ -37,7 +37,7 @@ export interface GeopointRule extends RuleDef<GeopointRule, GeopointValue> {}

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface GeopointOptions extends BaseOptions {}
export interface GeopointOptions extends BaseSchemaTypeOptions {}

/** @public */
export interface GeopointDefinition extends BaseSchemaDefinition {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/number.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {type FieldReference} from '../../../validation'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition, type EnumListProps} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions, type EnumListProps} from './common'

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface NumberOptions extends EnumListProps<number>, BaseOptions {}
export interface NumberOptions extends EnumListProps<number>, BaseSchemaTypeOptions {}

/** @public */
export interface NumberRule extends RuleDef<NumberRule, number> {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type FieldDefinition} from '../schemaDefinition'
import {
type BaseOptions,
type BaseSchemaDefinition,
type BaseSchemaTypeOptions,
type FieldGroupDefinition,
type FieldsetDefinition,
} from './common'

/** @public */
export interface ObjectOptions extends BaseOptions {
export interface ObjectOptions extends BaseSchemaTypeOptions {
collapsible?: boolean
collapsed?: boolean
columns?: number
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/slug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {type SlugifierFn, type SlugSourceFn} from '../../../slug'
import {type SlugIsUniqueValidator} from '../../../validation'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
export interface SlugValue {
Expand All @@ -16,7 +16,7 @@ export interface SlugValue {
export interface SlugRule extends RuleDef<SlugRule, SlugValue> {}

/** @public */
export interface SlugOptions extends BaseOptions {
export interface SlugOptions extends BaseSchemaTypeOptions {
source?: string | Path | SlugSourceFn
maxLength?: number
slugify?: SlugifierFn
Expand Down
7 changes: 5 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {type FieldReference} from '../../../validation'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {
type BaseOptions,
type BaseSchemaDefinition,
type BaseSchemaTypeOptions,
type EnumListProps,
type SearchConfiguration,
} from './common'

/** @public */
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface StringOptions extends EnumListProps<string>, SearchConfiguration, BaseOptions {}
export interface StringOptions
extends EnumListProps<string>,
SearchConfiguration,
BaseSchemaTypeOptions {}

/** @public */
export interface StringRule extends RuleDef<StringRule, string> {
Expand Down
4 changes: 2 additions & 2 deletions packages/@sanity/types/src/schema/definition/type/url.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {type UriValidationOptions} from '../../../validation/types'
import {type RuleDef, type ValidationBuilder} from '../../ruleBuilder'
import {type InitialValueProperty} from '../../types'
import {type BaseOptions, type BaseSchemaDefinition} from './common'
import {type BaseSchemaDefinition, type BaseSchemaTypeOptions} from './common'

/** @public */
export interface UrlRule extends RuleDef<UrlRule, string> {
Expand All @@ -11,7 +11,7 @@ export interface UrlRule extends RuleDef<UrlRule, string> {
/** @public */
// only exists to support declaration extensions
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface UrlOptions extends BaseOptions {}
export interface UrlOptions extends BaseSchemaTypeOptions {}

/** @public */
export interface UrlDefinition extends BaseSchemaDefinition {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import {type BaseSchemaTypeOptions} from '@sanity/types'
import {useCallback, useState} from 'react'

import {
type DocumentActionComponent,
type DocumentActionDescription,
type DocumentActionProps,
} from '../../config'
import {useSchema} from '../../hooks'
import {useTranslation} from '../../i18n'
import {isStartInCreateAutoConfirmed, setStartInCreateAutoConfirm} from '../createStorage'
import {createLocaleNamespace} from '../i18n'
Expand Down Expand Up @@ -38,6 +40,10 @@ export function StartInCreateAction(

const {appId} = useStudioAppIdStore(appIdCache)
const {t} = useTranslation(createLocaleNamespace)
const schema = useSchema()
const schemaType = schema.get(type)
const isExcludedByOption = (schemaType?.type?.options as BaseSchemaTypeOptions | undefined)
?.sanityCreate?.exclude

const [isDialogOpen, setDialogOpen] = useState(false)
const [isLinking, setLinking] = useState(false)
Expand All @@ -53,7 +59,7 @@ export function StartInCreateAction(
const createLinkId = (draft?._id ?? published?._id ?? liveEdit) ? id : `drafts.${id}`

//appId will always be undefined when start in create is disabled via config
if (!appId || doc?._createdAt) {
if (isExcludedByOption || !appId || doc?._createdAt) {
return null
}

Expand Down

0 comments on commit cbd4574

Please sign in to comment.