-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(form): use most specific title for schema type in modal header
- Loading branch information
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import type {SchemaType} from '@sanity/types' | ||
|
||
/** | ||
* Get the most specific defined title of a schema type | ||
* If not set directly on the given type, it will traverse up the tree until it | ||
* finds one, falling back to the _name_ of the type. | ||
* | ||
* @param type - The schema type to get the title of | ||
* @returns A title, alternatively the schema type _name_ | ||
* @internal | ||
*/ | ||
export function getSchemaTypeTitle(type: SchemaType): string { | ||
if (typeof type.title === 'string') { | ||
return type.title | ||
} | ||
|
||
if (type.type) { | ||
return getSchemaTypeTitle(type.type) | ||
} | ||
|
||
return type.name || type.jsonType | ||
} |