Nested category system causing view override in Sanity.io
// deskStructure.js
export default (S) =>
S.list()
.id("root")
.title("Content")
.items([
S.listItem({
id: "subcategories-by-maincategory",
title: "Subcategories by Main category",
schemaType: "sub_category",
child: () =>
S.documentTypeList("main_category").child((mainCategoryId) =>
S.documentTypeList("sub_category")
.title("Subcategories")
.filter(
`_type == $type && parent_category._ref == $mainCategoryId`
)
.params({ type: "sub_category", mainCategoryId })
.initialValueTemplates([
S.initialValueTemplateItem("subcategories-by-maincategory", {
mainCategoryId,
}),
])
.child((subCategoryId) =>
S.documentTypeList("project")
.title("Projects")
.filter(
`_type == $type && main_category._ref == $mainCategoryId && sub_category._ref == $subCategoryId`
)
.params({ type: "project", mainCategoryId, subCategoryId })
.initialValueTemplates([
S.initialValueTemplateItem("projects-by-categories", {
mainCategoryId,
subCategoryId,
}),
])
)
),
}),
...S.documentTypeListItems().filter(
(listItem) =>
![
// "project",
// "siteSettings",
// "menuBackgroundImage",
// "sub_category",
// "main_category",
"media.tag",
].includes(listItem.getId())
),
]);// sanity.config.js excerpt
templates: [
{
id: "subcategories-by-maincategory",
title: "Sub Categories by Main Category",
description: "Sub Categories under specific Main category",
schemaType: "sub_category",
parameters: [{ name: "mainCategoryId", type: "string" }],
value: (params) => ({
parent_category: { _type: "reference", _ref: params.mainCategoryId },
}),
},
{
id: "projects-by-categories",
title: "Projects",
description: "Projects under main category and sub category",
schemaType: "project",
parameters: [
{ name: "mainCategoryId", type: "string" },
{ name: "subCategoryId", type: "string" },
],
value: (params) => ({
main_category: { _type: "reference", _ref: params.mainCategoryId },
sub_category: { _type: "reference", _ref: params.subCategoryId },
}),
},
],Was this answer helpful?
Sanity – Build the way you think, not the way your CMS thinks
Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.