Skip to content

Commit

Permalink
fix(desk): pass intent in MenuNodes resolver (#4892)
Browse files Browse the repository at this point in the history
  • Loading branch information
israelroldan authored and bjoerge committed Oct 9, 2023
1 parent 0068787 commit e7bf4c3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 5 additions & 6 deletions packages/sanity/src/desk/menuNodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import {negate} from 'lodash'
import {_PaneMenuGroup, _PaneMenuItem, _PaneMenuNode} from './components/pane/types'
import {PaneMenuItem, PaneMenuItemGroup} from './types'
import {DocumentFieldActionNode} from 'sanity'
import {PaneMenuItem, PaneMenuItemGroup, DocumentFieldMenuActionNode} from './types'

export function isMenuNodeButton(node: _PaneMenuNode): node is _PaneMenuItem | _PaneMenuGroup {
return (node.type === 'item' || node.type === 'group') && node.renderAsButton
Expand All @@ -13,7 +12,7 @@ export const isNotMenuNodeButton = negate(isMenuNodeButton)

export function resolveMenuNodes(params: {
actionHandler: (item: PaneMenuItem) => void
fieldActions?: DocumentFieldActionNode[]
fieldActions?: DocumentFieldMenuActionNode[]
menuItems: PaneMenuItem[]
menuItemGroups: PaneMenuItemGroup[]
}): _PaneMenuNode[] {
Expand Down Expand Up @@ -102,7 +101,7 @@ export function resolveMenuNodes(params: {
return [...ungroupedItems, ...groups, ...nodes]
}

function mapFieldActionToPaneMenuNode(a: DocumentFieldActionNode, key: string): _PaneMenuNode {
function mapFieldActionToPaneMenuNode(a: DocumentFieldMenuActionNode, key: string): _PaneMenuNode {
if (a.type === 'divider') {
return {
type: 'divider',
Expand All @@ -116,7 +115,7 @@ function mapFieldActionToPaneMenuNode(a: DocumentFieldActionNode, key: string):
key,

children: a.children.map((child, childIdx) =>
mapFieldActionToPaneMenuNode(child, `${key}-${childIdx}-${child.type}`),
mapFieldActionToPaneMenuNode(child, `${key}-${childIdx}-${child.type}`)
),
disabled: a.disabled,
expanded: a.expanded ?? true,
Expand All @@ -129,7 +128,7 @@ function mapFieldActionToPaneMenuNode(a: DocumentFieldActionNode, key: string):
return {
type: 'item',
key,

intent: a.intent,
disabled: a.disabled,
icon: a.icon,
iconRight: a.iconRight,
Expand Down
13 changes: 11 additions & 2 deletions packages/sanity/src/desk/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {Observable} from 'rxjs'
import {
DefaultDocumentNodeResolver,
MenuItem as DeskToolMenuItem,
Intent,
StructureBuilder,
StructureContext,
UserComponent,
Expand All @@ -13,6 +14,7 @@ import {
ConfigContext,
InitialValueTemplateItem,
DocumentStore,
DocumentFieldActionNode,
} from 'sanity'

/** @internal */
Expand Down Expand Up @@ -121,9 +123,9 @@ export interface DeskToolOptions {
*/
name?: string
/**
* A workspace can have different "sources". These sources were meant to allow using multiple datasets within the same workspace, for instance.
* A workspace can have different "sources". These sources were meant to allow using multiple datasets within the same workspace, for instance.
* This is not supported yet, but the API is still here.
*
*
@hidden
@alpha
*/
Expand Down Expand Up @@ -362,3 +364,10 @@ export type UnresolvedPaneNode =
| Observable<UnresolvedPaneNode>
| PromiseLike<UnresolvedPaneNode>
| PaneNode

/**
* @hidden
* @beta */
export type DocumentFieldMenuActionNode = DocumentFieldActionNode & {
intent?: Intent
}

2 comments on commit e7bf4c3

@vercel
Copy link

@vercel vercel bot commented on e7bf4c3 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

performance-studio – ./

performance-studio.sanity.build
performance-studio-git-next.sanity.build

@vercel
Copy link

@vercel vercel bot commented on e7bf4c3 Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

test-studio – ./

test-studio.sanity.build
test-studio-git-next.sanity.build

Please sign in to comment.