Unlock seamless workflows and faster delivery with our latest releases - Join the deep dive

How to implement a new structure in Sanity.io without crashing the existing site

3 replies
Last updated: Jun 7, 2021
Hi! So I have a project where there already exists a studio, with Structure Builder API. Now I want to implement a new structure. I have already created a new dataset "staging" and connected it to a branch, and I can se that it works (followed this https://www.erichowey.dev/writing/how-to-setup-a-staging-website-with-SANITY/ ). But this doesn't fix my problem, that I want to be able to change the studio structure in staging, but keep it in master until the new structure is done. I don't want the existing site to crash. Any suggestions?
Jun 4, 2021, 1:22 PM
Hey Racheal! The goal is to have three branches, one master, one called production and one called staging. Production and staging is branched from master. In staging I want to be able to change the structure of the current studio and also add some things. This is then merged in to production, where we do some testing and where the client can test it out. And when given an OK, production is merged in to master (which is their current studio) and this will be their new updated studio. Since the client is using the studio it's importent that no changes are made before eveything is in order. Sorry, it's a bit confusing. So, if I use spaces production and staging can share studio and have diffrent datasets, right? But since they share studio, if I make changes to the studio in the stagingbranch these changes will also be seen if I switch dataset in the studio?
Jun 7, 2021, 11:46 AM
Gotcha! Something like this should work:
// deskStructure.js
import S from '@sanity/desk-tool/structure-builder'
import client from 'part:@sanity/base/client'

const { dataset } = client.clientConfig

export default () => {
  if (dataset == 'staging') {
    return S.list()
      .title('My new structure')
      .items([
        S.listItem()
          .title('New title')
          .child(
            S.documentTypeList('myNewType')
              .title('New title')
              .filter('_type == $type')
              .params({type: 'myNewType'})
          ),
      ])
  if (dataset == 'production') {
    return S.list()
    .title('My current structure')
    .items([
      S.listItem()
        .title('Current title')
        .child(
          S.documentTypeList('myType')
            .title('Current title')
            .filter('_type == $type')
            .params({type: 'myType'})
        ),
    ])
  }
}
The above uses the active dataset, which will update when they change environment or 
switch spaces , to show/hide the different desk structures.
Jun 7, 2021, 4:26 PM
It works! Thank you so much!!
Jun 7, 2021, 5:10 PM

Sanity– build remarkable experiences at scale

Sanity is a modern headless CMS that treats content as data to power your digital business. Free to get started, and pay-as-you-go on all plans.

Was this answer helpful?