Racheal Pennell
Community Engineer at Sanity.io
Racheal is located at Richmond, CA
Add a count of documents to your Structure Builder panes
import S from '@sanity/desk-tool/structure-builder';
import documentStore from 'part:@sanity/base/datastore/document';
import { map } from 'rxjs/operators';
export default () => documentStore.listenQuery(`count(*[_type == 'movie'])`).pipe(
map((count) =>
S.list()
.title('Movie Database Example')
.items([
S.documentTypeListItem('movie').title(`Movies (${count})`),
...S.documentTypeListItems().filter(
(listItem) => !['movie'].includes(listItem.getId())
),
])
)
);
Within the Community Slack, we're often asked how to show the count of a given document type within a custom Desk structure. The documentStore
and rxjs
allow us to display a count inside of our title that updates in real time.
Community Engineer at Sanity.io
Sanity preview component cannot access the parent/document if its inside an array or object. Using Custom Preview component, we can solve the issue.
Go to Sanity Custom Preview Component to get Parent DocumentIf you'd like to be able to reference your project users within your content, you'll need to create a document for them.
Go to Create A Document for All Current Project UsersUse a publishedOnce field to control other fields.
Go to Make a Field Read-Only After Publishing Once