Skip to content

Commit

Permalink
[design-studio] Configure structure and document views
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuslundgard authored and rexxars committed Oct 6, 2020
1 parent 521c9d9 commit 9bbcdd3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/design-studio/documentViews/jsonPreview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {useEditState} from '@sanity/react-hooks'
import React from 'react'

export function JSONPreviewDocumentView(props: any) {
const editState: any = useEditState(props.documentId, props.schemaType.name)

return <pre>{JSON.stringify(editState.draft || editState.published, null, 2)}</pre>
}
1 change: 1 addition & 0 deletions packages/design-studio/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"@sanity/default-login": "1.150.1",
"@sanity/desk-tool": "1.150.4",
"@sanity/google-maps-input": "1.150.1",
"@sanity/react-hooks": "1.150.4",
"@sanity/vision": "1.150.1",
"prop-types": "^15.6.0",
"react": "16.9.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/design-studio/sanity.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
{
"name": "part:@sanity/base/schema",
"path": "./schemas"
},
{
"name": "part:@sanity/desk-tool/structure",
"path": "./structure"
}
]
}
16 changes: 16 additions & 0 deletions packages/design-studio/structure/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import S from '@sanity/desk-tool/structure-builder'
import {JSONPreviewDocumentView} from '../documentViews/jsonPreview'

export const getDefaultDocumentNode = ({schemaType}) => {
// Conditionally return a different configuration based on the schema type
if (schemaType === 'author') {
return S.document().views([
S.view.form(),
S.view.component(JSONPreviewDocumentView).title('JSON')
])
}

return undefined
}

export default S.defaults()
2 changes: 2 additions & 0 deletions packages/design-studio/typings/sanity.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
declare module 'part:*'
declare module 'all:part:*'

0 comments on commit 9bbcdd3

Please sign in to comment.