258 lines
8.1 KiB
TypeScript
258 lines
8.1 KiB
TypeScript
|
/**
|
||
|
* This plugin contains all the logic for setting up the `Settings` singleton
|
||
|
*/
|
||
|
import { TiPuzzleOutline } from 'react-icons/ti'
|
||
|
import {
|
||
|
IoChatbubblesOutline,
|
||
|
IoDocumentOutline,
|
||
|
IoHomeOutline,
|
||
|
IoMapOutline,
|
||
|
IoFolderOutline,
|
||
|
IoOptions,
|
||
|
IoImages,
|
||
|
IoCameraOutline,
|
||
|
IoFilmOutline,
|
||
|
} from 'react-icons/io5'
|
||
|
import { definePlugin, type DocumentDefinition } from 'sanity'
|
||
|
import { type StructureResolver } from 'sanity/desk'
|
||
|
|
||
|
export const settingsPlugin = definePlugin<{ type: string }>(({ type }) => {
|
||
|
return {
|
||
|
name: 'settings',
|
||
|
document: {
|
||
|
// Hide 'Settings' from new document options
|
||
|
// https://user-images.githubusercontent.com/81981/195728798-e0c6cf7e-d442-4e58-af3a-8cd99d7fcc28.png
|
||
|
newDocumentOptions: (prev, { creationContext }) => {
|
||
|
if (creationContext.type === 'global') {
|
||
|
return prev.filter((templateItem) => templateItem.templateId !== type)
|
||
|
}
|
||
|
|
||
|
return prev
|
||
|
},
|
||
|
// Removes the "duplicate" action on the "settings" singleton
|
||
|
actions: (prev, { schemaType }) => {
|
||
|
if (schemaType === type) {
|
||
|
return prev.filter(({ action }) => action !== 'duplicate')
|
||
|
}
|
||
|
|
||
|
return prev
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
})
|
||
|
|
||
|
// The StructureResolver is how we're changing the DeskTool structure to linking to a single "Settings" document, instead of rendering "settings" in a list
|
||
|
// like how "Post" and "Author" is handled.
|
||
|
export const settingsStructure = (
|
||
|
typeDef: DocumentDefinition
|
||
|
): StructureResolver => {
|
||
|
return (S) => {
|
||
|
// The `Settings` root list item
|
||
|
const settingsListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title(typeDef.title)
|
||
|
.icon(IoOptions)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id(typeDef.name)
|
||
|
.schemaType(typeDef.name)
|
||
|
.documentId(typeDef.name)
|
||
|
)
|
||
|
|
||
|
const eventListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: The Event')
|
||
|
.icon(IoDocumentOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('eventSection')
|
||
|
.schemaType('eventSection')
|
||
|
.documentId('eventSection')
|
||
|
)
|
||
|
|
||
|
const careerListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: Career')
|
||
|
.icon(IoDocumentOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('careerSection')
|
||
|
.schemaType('careerSection')
|
||
|
.documentId('careerSection')
|
||
|
)
|
||
|
|
||
|
const WeddingListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: Wedding')
|
||
|
.icon(IoDocumentOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('WeddingSection')
|
||
|
.schemaType('WeddingSection')
|
||
|
.documentId('WeddingSection')
|
||
|
)
|
||
|
|
||
|
const storyListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: Story')
|
||
|
.icon(IoDocumentOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('sectionstory')
|
||
|
.schemaType('sectionstory')
|
||
|
.documentId('sectionstory')
|
||
|
)
|
||
|
|
||
|
const customePage = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: Custom (maintenance)')
|
||
|
.icon(TiPuzzleOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('customePage')
|
||
|
.schemaType('customePage')
|
||
|
.documentId('customePage')
|
||
|
)
|
||
|
|
||
|
const galleryListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Gallery')
|
||
|
.icon(IoCameraOutline)
|
||
|
.child(S.documentList().title('Albums').filter(`_type in ["gallery"]`))
|
||
|
|
||
|
const mapListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Map interactive')
|
||
|
.icon(IoMapOutline)
|
||
|
.child(
|
||
|
S.documentList()
|
||
|
.defaultOrdering([{ field: 'priority', direction: 'desc' }])
|
||
|
.title('Pin points')
|
||
|
.filter(`_type in ["mapinteractive"]`)
|
||
|
)
|
||
|
|
||
|
const heritageListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Page: Cultural Heritage')
|
||
|
.icon(IoDocumentOutline)
|
||
|
.child(
|
||
|
S.editor()
|
||
|
.id('culturalHeritageSection')
|
||
|
.schemaType('culturalHeritageSection')
|
||
|
.documentId('culturalHeritageSection')
|
||
|
)
|
||
|
|
||
|
const homepageSectionListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('Home settings')
|
||
|
.icon(IoHomeOutline)
|
||
|
.child(
|
||
|
S.list()
|
||
|
.title('Home sections')
|
||
|
.items([
|
||
|
S.listItem()
|
||
|
.title('Hero section')
|
||
|
.icon(IoFilmOutline)
|
||
|
.child(
|
||
|
S.documentList()
|
||
|
.title('Hero section')
|
||
|
.filter('_type == "heroHomepage"')
|
||
|
),
|
||
|
S.listItem()
|
||
|
.title('Content section')
|
||
|
.icon(IoFolderOutline)
|
||
|
.child(
|
||
|
S.documentList()
|
||
|
.title('Content section')
|
||
|
.filter(
|
||
|
`_type in ["homepageSection", "culturalSection", "functionsSection","whatsNewBanner"]`
|
||
|
)
|
||
|
),
|
||
|
])
|
||
|
)
|
||
|
const faqListItem = // A singleton not using `documentListItem`, eg no built-in preview
|
||
|
S.listItem()
|
||
|
.title('FAQ')
|
||
|
.icon(IoChatbubblesOutline)
|
||
|
.child(
|
||
|
S.list()
|
||
|
.title('FAQ')
|
||
|
.items([
|
||
|
S.listItem()
|
||
|
.title('FAQ content')
|
||
|
.icon(IoFolderOutline)
|
||
|
.child(
|
||
|
S.documentList()
|
||
|
.title('Contents')
|
||
|
.filter('_type == "pagefaq"')
|
||
|
),
|
||
|
S.listItem()
|
||
|
.title('FAQ topics')
|
||
|
.icon(IoFolderOutline)
|
||
|
.child(
|
||
|
S.documentList()
|
||
|
.title('Topics')
|
||
|
.filter(`_type in ["faqTopic"]`)
|
||
|
),
|
||
|
])
|
||
|
)
|
||
|
|
||
|
// The default root list items (except custom ones)
|
||
|
const theStructure = S.documentTypeListItems().filter((listItem) => {
|
||
|
if (
|
||
|
listItem.getId() !== typeDef.name &&
|
||
|
listItem.getId() !== 'Event' &&
|
||
|
listItem.getId() !== 'eventSection' &&
|
||
|
listItem.getId() !== 'culturalHeritageSection' &&
|
||
|
listItem.getId() !== 'contentheritage' &&
|
||
|
listItem.getId() !== 'sectionstory' &&
|
||
|
listItem.getId() !== 'customePage' &&
|
||
|
listItem.getId() !== 'linkGenerate' &&
|
||
|
listItem.getId() !== 'contentPage' &&
|
||
|
listItem.getId() !== 'careerSection' &&
|
||
|
listItem.getId() !== 'WeddingSection' &&
|
||
|
listItem.getId() !== 'weddingpackage' &&
|
||
|
listItem.getId() !== 'weddingpost' &&
|
||
|
listItem.getId() !== 'heroHomepage' &&
|
||
|
listItem.getId() !== 'homepageSection' &&
|
||
|
listItem.getId() !== 'functionsSection' &&
|
||
|
listItem.getId() !== 'culturalSection' &&
|
||
|
listItem.getId() !== 'career' &&
|
||
|
listItem.getId() !== 'mapinteractive' &&
|
||
|
listItem.getId() !== 'gallery' &&
|
||
|
listItem.getId() !== 'gallerywedding' &&
|
||
|
listItem.getId() !== 'pagefaq' &&
|
||
|
listItem.getId() !== 'faqTopic' &&
|
||
|
listItem.getId() !== 'media.tag'
|
||
|
) {
|
||
|
return listItem
|
||
|
}
|
||
|
})
|
||
|
|
||
|
return S.list()
|
||
|
.title('Content')
|
||
|
.items([
|
||
|
settingsListItem,
|
||
|
S.divider(),
|
||
|
homepageSectionListItem,
|
||
|
S.divider(),
|
||
|
eventListItem,
|
||
|
heritageListItem,
|
||
|
storyListItem,
|
||
|
careerListItem,
|
||
|
WeddingListItem,
|
||
|
S.divider(),
|
||
|
mapListItem,
|
||
|
S.divider(),
|
||
|
galleryListItem,
|
||
|
S.divider(),
|
||
|
faqListItem,
|
||
|
S.divider(),
|
||
|
customePage,
|
||
|
S.divider(),
|
||
|
...theStructure,
|
||
|
S.divider(),
|
||
|
])
|
||
|
}
|
||
|
}
|