import React from 'react'
import styles from './styles/DeskTool.css'
import SchemaPaneResolver from './SchemaPaneResolver'
import client from 'part:@sanity/base/client'
import {withRouterHOC} from 'part:@sanity/base/router'
import PropTypes from 'prop-types'

export default withRouterHOC(class DeskTool extends React.Component {
  static propTypes = {
    router: PropTypes.shape({
      state: PropTypes.object
    }).isRequired
  }
  componentDidMount() {
    const {router} = this.props
    const {selectedType, selectedDocumentId} = router.state
    if (selectedDocumentId && selectedType) {
      client.fetch('*[_id == $id][0]._type', {id: selectedDocumentId})
        .then(type => {
          if (type !== selectedType) {
            router.navigate({...router.state, selectedType: type}, {replace: true})
          }
        })
    }
  }

  render() {
    const {router} = this.props

    return (
      <div className={styles.deskTool}>
        <SchemaPaneResolver router={router} />
      </div>
    )
  }
})

@@ -609,17 +609,17 @@
 t.fetch(
-'
+%60
 *%5B_id ==
@@ -623,29 +623,52 @@
  == 
-$id%5D%5B0%5D._type', %7Bid: 
+%22$%7BselectedDocumentId%7D%22 %7C%7C _id == %22drafts.$%7B
 sele
@@ -682,16 +682,28 @@
 umentId%7D
+%22%5D%5B0%5D._type%60
 )%0A      
@@ -739,16 +739,24 @@
 f (type 
+&& type 
 !== sele

Handle drafts/missing documents when checking for type mismatch