Join us live Sept. 27 – How Sanity and Vercel powered Morning Brew's transformation –>

Display a document count in the title of a pane in Structure Builder

By RD Pennell

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) =>
        .title('Movie Database Example')
          S.documentTypeListItem('movie').title(`Movies (${count})`),
            (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.


Other schemas by author