Skip to content

Commit

Permalink
fix: better intent handling (#99)
Browse files Browse the repository at this point in the history
* chore: update code examples in readme
* fix: improve intent handling
  • Loading branch information
SimeonGriggs committed Sep 15, 2024
1 parent 343a4db commit 2c73e39
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ A Sanity Studio with [Desk Structure](https://www.sanity.io/docs/structure-build

```ts
import {defineConfig} from 'sanity'
import {deskTool, StructureBuilder} from 'sanity/structure'
import {structureTool, StructureBuilder} from 'sanity/structure'

export default defineConfig({
//...
plugins: [
deskTool({
structureTool({
structure: (S, context) => {
/* Structure code */
},
Expand Down Expand Up @@ -54,13 +54,13 @@ The config parameter requires `type`, `S` and `context`. It also accepts `title`

```ts
import {defineConfig} from 'sanity'
import {deskTool, StructureBuilder} from 'sanity/structure'
import {structureTool, StructureBuilder} from 'sanity/structure'
import {orderableDocumentListDeskItem} from '@sanity/orderable-document-list'

export default defineConfig({
//...
plugins: [
deskTool({
structureTool({
structure: (S, context) => {
return S.list()
.title('Content')
Expand Down Expand Up @@ -115,13 +115,13 @@ You can configure the placement of new documents by setting `newItemPosition` to
```js
// sanity.config.js
import {defineConfig} from "sanity";
import {deskTool, StructureBuilder} from "sanity/structure";
import {structureTool, StructureBuilder} from "sanity/structure";
import {orderRankField, orderRankOrdering} from '@sanity/orderable-document-list'

export default defineConfig({
//...
plugins: [
deskTool({structure: (S, context) => {/* snip */}})
structureTool({structure: (S, context) => {/* snip */}})
],
schema: {
types: (previousTypes) => {
Expand Down
42 changes: 24 additions & 18 deletions src/desk-structure/orderableDocumentListDeskItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,32 @@ export function orderableDocumentListDeskItem(config: OrderableListConfig): List
.title(listTitle)
.id(listId)
.icon(listIcon)
.schemaType(type)
.child(
Object.assign(S.documentTypeList(type).serialize(), {
// Prevents the component from re-rendering when switching documents
__preserveInstance: true,
// Prevents the component from NOT re-rendering when switching listItems
key: listId,
Object.assign(
S.documentTypeList(type)
.canHandleIntent(() => !!createIntent)
.serialize(),
{
// Prevents the component from re-rendering when switching documents
__preserveInstance: true,
// Prevents the component from NOT re-rendering when switching listItems
key: listId,

type: 'component',
component: OrderableDocumentList,
options: {type, filter, params, client},
menuItems: [
...menuItems,
S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder`).serialize(),
S.menuItem()
.title(`Toggle Increments`)
.icon(SortIcon)
.action(`showIncrements`)
.serialize(),
],
})
type: 'component',
component: OrderableDocumentList,
options: {type, filter, params, client},
menuItems: [
...menuItems,
S.menuItem().title(`Reset Order`).icon(GenerateIcon).action(`resetOrder`).serialize(),
S.menuItem()
.title(`Toggle Increments`)
.icon(SortIcon)
.action(`showIncrements`)
.serialize(),
],
}
)
)
.serialize()
}

0 comments on commit 2c73e39

Please sign in to comment.