Gwk-Cultural-Park/schemas/category.ts

33 lines
743 B
TypeScript
Raw Permalink Normal View History

2024-09-07 01:40:25 +00:00
import { TiFolder } from 'react-icons/ti'
import { defineField, defineType } from 'sanity'
export default defineType({
name: 'category',
title: 'Category',
type: 'document',
icon: TiFolder,
fields: [
{ name: 'title', type: 'string' },
{
name: 'parent',
type: 'reference',
to: [{ type: 'category' }],
// This ensures we cannot select other "children"
options: {
filter: '!defined(parent)',
},
},
],
// Customise the preview so parents are visualised in the studio
preview: {
select: {
title: 'title',
subtitle: 'parent.title',
},
prepare: ({ title, subtitle }) => ({
title,
subtitle: subtitle ? ` ${subtitle}` : ``,
}),
},
})