Gwk-Cultural-Park/schemas/category.ts
2024-09-07 08:40:25 +07:00

33 lines
743 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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}` : ``,
}),
},
})