@@ -14,8 +14,82 @@ export default defineConfig({
1414 basePath : '/studio' ,
1515 title : 'Grunnmuren - Sanity Studio' ,
1616 auth : obosAuthStore ( { dataset } ) ,
17- plugins : [ structureTool ( ) , visionTool ( ) , codeInput ( ) , table ( ) ] ,
17+ plugins : [
18+ structureTool ( {
19+ structure : async ( S , context ) => {
20+ const CATEGORIES = await context
21+ . getClient ( { apiVersion : '2025-03-21' } )
22+ . fetch ( `(*[_type == "category"])` ) ;
23+
24+ return S . list ( )
25+ . title ( 'Content' )
26+ . items ( [
27+ S . listItem ( )
28+ . id ( 'menuAndCategories' )
29+ . title ( 'Menu and categories' )
30+ . child (
31+ S . list ( )
32+ . title ( 'Menu and categories' )
33+ . items ( [
34+ // Our singleton type has a list item with a custom child
35+ S . listItem ( )
36+ . title ( 'Menu' )
37+ . id ( 'menu' )
38+ . child (
39+ // Instead of rendering a list of documents, we render a single
40+ // document, specifying the `documentId` manually to ensure
41+ // that we're editing the single instance of the document
42+ S . document ( )
43+ . title ( 'Menu' )
44+ . schemaType ( 'menu' )
45+ . documentId ( 'menu' ) ,
46+ ) ,
47+ S . divider ( ) ,
48+ ...CATEGORIES . map ( ( category ) => {
49+ return S . listItem ( )
50+ . title ( category . title )
51+ . id ( category . _id )
52+ . child (
53+ // Instead of rendering a list of documents, we render a single
54+ // document, specifying the `documentId` manually to ensure
55+ // that we're editing the single instance of the document
56+ S . document ( )
57+ . title ( category . title )
58+ . schemaType ( category . _type )
59+ . documentId ( category . _id ) ,
60+ ) ;
61+ } ) ,
62+ ] ) ,
63+ ) ,
64+ S . divider ( ) ,
65+ S . documentTypeListItem ( 'component' ) . title ( 'Components' ) ,
66+ S . documentTypeListItem ( 'info' ) . title ( 'Info' ) ,
67+ ] ) ;
68+ } ,
69+ } ) ,
70+ visionTool ( ) ,
71+ codeInput ( ) ,
72+ table ( ) ,
73+ ] ,
1874 schema : {
1975 types : schemaTypes ,
2076 } ,
77+ document : {
78+ newDocumentOptions : ( templateItems , { creationContext } ) => {
79+ // Define the singleton document types
80+ const singletonTypes = new Set ( [ 'menu' ] ) ;
81+ // Check if the context is that of the top level "Create" button in the header
82+ if ( creationContext . type === 'global' ) {
83+ const nonSingletonTemplateItems = [ ] as typeof templateItems ;
84+ for ( const item of templateItems ) {
85+ if ( ! singletonTypes . has ( item . templateId ) ) {
86+ nonSingletonTemplateItems . push ( item ) ;
87+ }
88+ }
89+ return nonSingletonTemplateItems ;
90+ }
91+
92+ return templateItems ;
93+ } ,
94+ } ,
2195} ) ;
0 commit comments