Issue with filtering out a document by ID in Sanity Studio using desk structure.
8 replies
Last updated: Apr 20, 2021
A
I’m trying to figure out how to filter out a document by an ID in sanity studio using desk structure
Here I’m trying to keep the version of revisionTemplate with a set documentId seperated from all the instances of the document
S.listItem()
.title("Audit template")
.icon(FaBible)
.child(
S.document()
.schemaType("revisionTemplate")
.documentId("sourceDocument")
),
S.listItem()
.title("Audits")
.child(
S.document()
.filter((item) => item.getId() !== "sourceDocument")
.schemaType("revisionTemplate")
),Apr 20, 2021, 2:31 PM
G
Could you try:
.filter(item => !['sourceDocument'].includes(item.getId()))
Apr 20, 2021, 2:32 PM
A
I should have included the error
It seems like I can’t call filter where I am trying to call it
TypeError: _structureBuilder.default.document(...) .filter is not a function
Apr 20, 2021, 2:34 PM
G
And
...S.documentTypeListItems()instead of
S.document().
Apr 20, 2021, 2:35 PM
G
You may also need the top-level to be
S.list()containing
.items([...]). In
.items([])are
S.listItem()(Audit template) and
…S.documentTypeListItems(). If you scroll up a few threads you’ll see Giacomo’s example—I think that structure would work.
Apr 20, 2021, 2:38 PM
A
Hmm adding it to documentTypeListItems seems to produce the same error
Will check out the example
🙂
Will check out the example
🙂
Apr 20, 2021, 2:50 PM
A
I think I already have that, I tried the filter to S.documentTypeListItems but I still see the document under my audits tab
https://pastebin.com/TW0bPQ20
S.listItem()
.title("Audit template")
.icon(FaBible)
.child(
S.document()
.schemaType("revisionTemplate")
.documentId("sourceDocument")
),
S.listItem()
.title("Audits")
.child(S.documentTypeList("revisionTemplate").title("Audits")),
...S.documentTypeListItems().filter(
hiddenDocTypes,
(item) => !["sourceDocument"].includes(item.getId())
),https://pastebin.com/TW0bPQ20
Apr 20, 2021, 2:54 PM
A
Hmm I added the document to my hiddenDocTypes but I setill se the document when I query for the documentTypeList
https://pastebin.com/Z9QV91D9
S.listItem()
.title("Audits")
.child(S.documentTypeList("revisionTemplate").title("Audits")),
S.listItem()
.title("Audit template")
.icon(FaBible)
.child(
S.document()
.schemaType("revisionTemplate")
.documentId("sourceDocument")
),https://pastebin.com/Z9QV91D9
Apr 20, 2021, 3:00 PM
A
Turns out sanity has something nifty called filterThis worked:
S.listItem()
.title("Audits")
.child(
S.documentTypeList("revisionTemplate")
.title("Audits")
.filter('_type == "revisionTemplate" && _id!="sourceDocument"')
),Apr 20, 2021, 3:03 PM
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.